ESP8266 - 64x32 RGB Led Matrix - Leser87 - 25-03-2023
Siema
Mam problem z kompilacją szkicu dla wyświetlacza RGB. Znalazłem w sieci poradnik krok, po kroku, jak uruchamić taki wyswietlacz jako stację pogody, ale poległem na kompilacji szkicu. Nie ukrywam, że jest to moja pierwsza styczność z arduino, ale udało mi się wgrać kilka przykładowych grafik, więc podstawy juz opanowałem. Utknąłem na błędzie, na którego nie moge znależć rozwiązania w sieci. Jak się domyślam, problem jest z plikiem <kongtext4pt7b.h>. Ten plik musiałem dodać ręcznie do biblioteki Adafruit GFX, bo nie było go po instalacji biblioteki.
Kod: ```cpp
#include <Adafruit_GFX.h>
#include <Adafruit_GrayOLED.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
// REQUIRES the following Arduino libraries:
// - RGB matrix Panel Library: https://github.com/2dom/PxMatrix
// - Adafruit_GFX Library: https://github.com/adafruit/Adafruit-GFX-Library
// - esp8266 library (nodemcu) found at https://github.com/esp8266/Arduino
// - package_esp8266com_index.json found at http://arduino.esp8266.com/stable/package_esp8266com_index.json
// Find All "Great Projects" Videos : https://www.youtube.com/channel/UCCC8DuqicBtP3A_aC53HYDQ/videos
// Approx. 2402 bytes
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <time.h>
#include <Adafruit_GFX.h>
#include <FreeMonoBold12pt7b.h>
#include <kongtext4pt7b.h>
#include <PxMatrix.h>
#include <Ticker.h>
#include "ThingSpeak.h"
Ticker display_ticker;
#define P_LAT 16
#define P_A 5
#define P_B 4
#define P_C 15
#define P_D 12
#define P_OE 2
// Pins for LED MATRIX
#define matrix_width 64
#define matrix_height 32
int timezone = 1;
int dst = 0;
int temp;
int humi;
static uint32_t lastTime = 0; // millis() memory
static bool flasher = false; // seconds passing flasher
uint8_t frameDelay = 10; // default frame delay value
int h, m, s, d;
uint8_t dow;
int day;
uint8_t month;
String year;
String date;
String text;
String Message0 = "To all people, I love you and wish you safety and recovery for patients";
String Message1 = "Great Projects wish you a very nice day. Hope you have a great time ahead.";
String Messagetemp = "";
String Messagehumi = "";
static bool Mode = true;
uint8_t r = 0, g = 0, b = 0;
unsigned int NewRTCh = 24;
unsigned int NewRTCm = 60;
unsigned int NewRTCs = 10;
char szTime[4]; // 00
char szMesg[10] = "";
char szBuf[10];
const char* wifi_ssid = "Zyxel Leser"; // replace MySSID with your WiFi network name
const char* wifi_password = "Leser2020"; // replace MyPassword with your WiFi password
WiFiClient client;
// Counting channel details
unsigned long counterChannelNumber = MyChannelNumber; //replace MyChannelNumber with your Channel ID
const char* myCounterReadAPIKey = "APIKey"; //replace APIKey with your Read API Key
unsigned int TemperatureFieldNumber = 1;
unsigned int HumidityFieldNumber = 2;
// This defines the 'on' time of the display is us. The larger this number,
// the brighter the display. If too large the ESP will crash
uint8_t display_draw_time = 10; //10-50 is usually fine
PxMATRIX display(64, 32, P_LAT, P_OE, P_A, P_B, P_C, P_D);
//PxMATRIX display(matrix_width,matrix_height,P_LAT, P_OE,P_A,P_B,P_C);
//PxMATRIX display(64,64,P_LAT, P_OE,P_A,P_B,P_C,P_D,P_E);
// Some standard colors
uint16_t myRED = display.color565(255, 0, 0);
uint16_t myGREEN = display.color565(0, 255, 0);
uint16_t myBLUE = display.color565(0, 0, 255);
uint16_t myWHITE = display.color565(255, 255, 255);
uint16_t myYELLOW = display.color565(255, 255, 0);
uint16_t myCYAN = display.color565(0, 255, 255);
uint16_t myMAGENTA = display.color565(255, 0, 255);
uint16_t myBLACK = display.color565(255, 255, 255);
uint16_t myCOLORS[8] = {myRED, myGREEN, myBLUE, myWHITE, myYELLOW, myCYAN, myMAGENTA, myBLACK};
// ISR for display refresh
void display_updater()
{
display.display(display_draw_time);
}
void display_update_enable(bool is_enable)
{
if (is_enable)
display_ticker.attach(0.002, display_updater);
else
display_ticker.detach();
}
void(* resetFunc) (void) = 0;//declare reset function at address 0
char *mon2str(uint8_t mon, char *psz, uint8_t len)
{
static const char str[][4] PROGMEM =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
*psz = '\0';
mon--;
if (mon < 12)
{
strncpy_P(psz, str[mon], len);
psz[len] = '\0';
}
return (psz);
}
char *dow2str(uint8_t code, char *psz, uint8_t len)
{
static const char str[][10] PROGMEM =
{
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
*psz = '\0';
code--;
if (code < 7)
{
strncpy_P(psz, str[code], len);
psz[len] = '\0';
}
return (psz);
}
void getTemperature()
{
float temp = ThingSpeak.readFloatField(counterChannelNumber, TemperatureFieldNumber, myCounterReadAPIKey);
Messagetemp = "Temperature: " + String(temp) + " $";
}
void getHumidity()
{
int humi = ThingSpeak.readLongField(counterChannelNumber, HumidityFieldNumber, myCounterReadAPIKey);
Messagehumi = "Humidity: " + String(humi) + " %RH";
}
void getDate()
// Code for reading date
{
text = mon2str(month, szBuf, sizeof(szBuf) - 1);
display.setCursor(0, 23);
display.fillRect(0, 23, 64, 8, display.color565(0, 0, 0));
display.setFont(&kongtext4pt7b);
display.setTextColor(myRED);
if (day < 10) {
display.print("0");
}
display.print(day);
display.setTextColor(myGREEN);
display.print(text);
display.setTextColor(myRED);
display.print(year);
display.setFont();
}
void getDowe()
// Code for reading date
{
text = dow2str(dow, szBuf, sizeof(szBuf) - 1);
uint16_t text_length = text.length();
int xpos = (matrix_width - text_length * 7) / 2;
display.setCursor(xpos, 23);
display.fillRect(0, 23, 64, 8, display.color565(0, 0, 0));
display.setFont(&kongtext4pt7b);
uint8_t y = 0;
for (y = 0; y < 10; y++) {
display.setTextColor(Whel(y));
display.print(text[y]);
}
display.setFont();
}
void getRTCh(char *psz)
// Code for reading clock time
{
sprintf(psz, "%02d", h);
display.setCursor(0, 16);
display.setFont(&FreeMonoBold12pt7b);
display.setTextColor(myMAGENTA);
display.fillRect(0, 8, 24, 15, display.color565(0, 0, 0));
display.print(szTime);
display.setFont();
NewRTCh = h;
}
void getRTCm(char *psz)
// Code for reading clock time
{
sprintf(psz, "%02d", m);
display.setCursor(26, 16);
display.setFont(&FreeMonoBold12pt7b);
display.setTextColor(myMAGENTA);
display.fillRect(26, 8, 25, 15, display.color565(0, 0, 0));
display.print(szTime);
display.setFont();
NewRTCm = m;
}
void getTim(char *psz, bool f = true)
// Code for reading clock time
{
if (NewRTCs != s / 10)
{
display.setCursor(20, 8);
display.setTextSize(2);
display.setTextColor(myCOLORS[g]);
display.fillRect(24, 12, 2, 6, display.color565(0, 0, 0));
display.print(f ? ':' : ' ');
display.setCursor(54, 10);
display.setTextSize(1);
display.fillRect(54, 10, 10, 6, display.color565(0, 0, 0));
display.setFont(&kongtext4pt7b);
display.setTextColor(myCOLORS[b]);
display.print(f ? ' ' : '*');
display.setFont();
display.setCursor(51, 16);
display.setTextSize(1);
display.setTextColor(myCOLORS[r]);
sprintf(psz, "%02d", s);
display.fillRect(51, 17, 13, 6, display.color565(0, 0, 0));
display.setFont(&kongtext4pt7b);
display.print(szTime);
display.setFont();
NewRTCs = s / 10;
}
else
{
display.setCursor(20, 8);
display.setTextSize(2);
display.setTextColor(myCOLORS[g]);
display.fillRect(24, 12, 2, 6, display.color565(0, 0, 0));
display.print(f ? ':' : ' ');
display.setCursor(54, 10);
display.setTextSize(1);
display.fillRect(54, 10, 10, 6, display.color565(0, 0, 0));
display.setFont(&kongtext4pt7b);
display.setTextColor(myCOLORS[b]);
display.print(f ? ' ' : '*');
display.setFont();
display.setCursor(51, 16);
display.setTextColor(myCOLORS[r]);
sprintf(psz, "%02d", s);
display.fillRect(58, 17, 6, 6, display.color565(0, 0, 0));
display.setFont(&kongtext4pt7b);
display.print(szTime);
display.setFont();
}
}
void scroll_text(uint8_t ypos, unsigned long scroll_delay, String text)
{
uint16_t text_length = text.length();
// Asuming 5 pixel average character width
for (int xpos = matrix_width; xpos > -(matrix_width + text_length * 7); xpos--)
{
display.setCursor(xpos, ypos);
display.fillRect(0, ypos, 64, 8, display.color565(0, 0, 0));
display.setFont(&kongtext4pt7b);
display.print(text);
display.setFont();
delay(scroll_delay);
yield();
if (millis() - lastTime >= 1000)
{
lastTime = millis();
updateTime();
getTim(szTime, flasher);
flasher = !flasher;
if (NewRTCh != h)
{
getTime();
getRTCh(szTime);
}
if (NewRTCm != m)
{
getRTCm(szTime);
Mode = true;
}
}
}
r++;
if (r == 8) {
r = 0;
g++;
if (g == 8) {
g = 0;
b++;
if (b == 8) {
b = 0;
}
}
}
}
void setup() {
Serial.begin(115200); // Initialize serial
display.begin(16);
display.setFastUpdate(true);
display.setRotation(0); // we don't wrap text so it scrolls nicely
display.clearDisplay();
display.setTextColor(myCYAN);
display.setCursor(2, 0);
display.println("Connecting");
WiFi.mode(WIFI_STA);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
display.print(".");
}
display.setTextWrap(false);
display.clearDisplay();
display.println("");
display.print("WiFi OK");
display_update_enable(true);
getTime();
delay(3000);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
getDowe();
scroll_text(0, frameDelay, Message0);
getDate();
scroll_text(0, frameDelay, Message1);
getDate();
getTemperature();
scroll_text(0, frameDelay, Messagetemp);
getDowe();
getHumidity();
scroll_text(0, frameDelay, Messagehumi);
}
void getTime()
{
configTime(timezone * 3600, dst, "pool.ntp.org", "time.nist.gov");
while (!time(nullptr)) {
display.print(".");
}
}
void updateTime()
{
time_t now = time(nullptr);
struct tm* p_tm = localtime(&now);
dow = p_tm->tm_wday + 1;
day = p_tm->tm_mday;
month = p_tm->tm_mon + 1;
year = p_tm->tm_year + 1900;
h = p_tm->tm_hour;
m = p_tm->tm_min;
s = p_tm->tm_sec;
}
// Input a value 0 to 24 to get a color value.
// The colours are a transition r - g - b - back to r.
uint16_t Wheel(byte WheelPos) {
if (WheelPos < 2) {
return display.color565(255, 0, 0);
} else if (WheelPos < 5) {
WheelPos -= 2;
return display.color565(0, 0, 255);
} else {
WheelPos -= 5;
return display.color565(255, 0, 0);
}
}
// Input a value 0 to 24 to get a color value.
// The colours are a transition r - g - b - back to r.
uint16_t Whel(byte WheelPos) {
if (WheelPos < 1) {
return display.color565(255, 0, 0);
} else if (WheelPos < 2) {
WheelPos -= 1;
return display.color565(0, 255, 0);
} else if (WheelPos < 3) {
WheelPos -= 2;
return display.color565(255, 255, 0);
} else if (WheelPos < 4) {
WheelPos -= 3;
return display.color565(255, 0, 255);
} else if (WheelPos < 5) {
WheelPos -= 4;
return display.color565(0, 0, 255);
} else if (WheelPos < 6) {
WheelPos -= 5;
return display.color565(0, 255, 255);
} else if (WheelPos < 7) {
WheelPos -= 6;
return display.color565(255, 0, 255);
} else if (WheelPos < 8) {
WheelPos -= 7;
return display.color565(255, 255, 0);
} else if (WheelPos < 9) {
WheelPos -= 8;
return display.color565(255, 0, 0);
} else {
WheelPos -= 9;
return display.color565(255, 255, 255);
}
}
```
Kod: ```cpp
In file included from C:\Users\Leser\Desktop\Matrix-P4_ESP8266_Weather-Station_Clock\Matrix-P4_ESP8266_Weather-Station_Clock.ino:23:
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:618:75: error: extended character ↵ is not valid in an identifier
618 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:623:56: error: extended character ↵ is not valid in an identifier
623 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:665:75: error: extended character ↵ is not valid in an identifier
665 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:670:56: error: extended character ↵ is not valid in an identifier
670 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:703:75: error: extended character ↵ is not valid in an identifier
703 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:708:56: error: extended character ↵ is not valid in an identifier
708 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:741:75: error: extended character ↵ is not valid in an identifier
741 | <span aria-hidden="true" class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:746:56: error: extended character ↵ is not valid in an identifier
746 | <span class="d-inline-block ml-1 v-align-middle">↵</span>
| ^
In file included from C:\Users\Leser\Desktop\Matrix-P4_ESP8266_Weather-Station_Clock\Matrix-P4_ESP8266_Weather-Station_Clock.ino:23:
c:\Users\Leser\Documents\Arduino\libraries\Adafruit_GFX_Library/kongtext4pt7b.h:2216:9: error: extended character ’ is not valid in an identifier
2216 | You can’t perform that action at this time.
| ^
exit status 1
Compilation error: exit status 1
```
RE: ESP8266 - 64x32 RGB Led Matrix - kaczakat - 26-03-2023
Core ESP i biblioteki się zmieniają, to co kiedyś się kompilowało OK, potem może już nie zagrać. Trzeba doczytać tam gdzie to zdobyłeś jakie wersje bibliotek były użyte, albo przynajmniej dojść po datach publikacji i czytając daty updatów wymodzić prawidłowy zestaw. Bo starsze wersje core i bibliotek zwykle można pobrać w managerach Arduino IDE.
RE: ESP8266 - 64x32 RGB Led Matrix - Leser87 - 26-03-2023
(26-03-2023, 02:05)kaczakat napisał(a): Core ESP i biblioteki się zmieniają, to co kiedyś się kompilowało OK, potem może już nie zagrać. Trzeba doczytać tam gdzie to zdobyłeś jakie wersje bibliotek były użyte, albo przynajmniej dojść po datach publikacji i czytając daty updatów wymodzić prawidłowy zestaw. Bo starsze wersje core i bibliotek zwykle można pobrać w managerach Arduino IDE.
czyli aktualizacja biblioteki, moze nie miec czegoś, co bylo w starszych jej wersjach?
|