Yes indeed, that's the very code I'm using at the moment. The problem is the people over at the Arduino Forum insist that the code is "not allowed" and bad C/C++ coding because the icon arrays are uint8_t and the DrawIcon function uses uint16_t. Here is a link to the discussions this issue appears towards the end of the discussion from post 20/38. Also it is very difficult for me to understand eactly how the DrawIcon function works, even though it most certainly does work. I have tried changing the uint16_t references in the function to uint8_t and the arrays to uint16_t but all I get with both changes is a black square instead of an icon.
Posts made by Steve1
-
RE: Drawing an icon on the M5Paper from an array
-
Drawing an icon on the M5Paper from an array
On the M5Paper how can I draw an icon using a function with drawPixel() from an array of the form;
static const uint8_t SUNRISE64x64[8192] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff........}; -
RE: MPaper: How to read touch (or fingerUp) just one time.
Thanks for your patience ;-)
-
RE: MPaper: How to read touch (or fingerUp) just one time.
Well, yes it does. But why does the readFinger() have to be reaad three times?
for(int i=0;i<2; i++){
tp_finger_t FingerItem = M5.TP.readFinger(i); -
MPaper: How to read touch (or fingerUp) just one time.
I am programming my M5Paper with the Arduino IDE 2.2.1. I have tried everything I can think of to get just a single pair of x,y cordinates from a single touch on the M5Paper. I have tried comparing new coordinates with old and so on, but I haven't been able get just a single pair of coordinates and then wait for the net touch. Could someone show me how to achieve this?
-
M5Paper icon displaying as 2 small icons.
I am using an M5Paper and I have created a static const int8_t array using this website.
I then use the command
"DrawIcon(100, 780, (uint16_t *)Arrow_circle_down, 64, 64, true);"
together with the same drawIcon command for my other icons which are in an icon.h file I downloaded from the internet. All of the other icons display correctly but the icon I created displays as two small icons at the top and part of an unconnected icon at the bottom of the 64x64 square.
My working icon arrays look like this:
static const uint8_t SUNRISE64x64[8192] = {
0xff, 0xff, 0xff,........};My created icon array array looks like this;
// array size is 4096
static const int8_t Arrow_circle_down[] = {
0xff, 0xff, 0xff,........};I tried putting the array size 4096 in the square brackets but that made no difference.
The function drawIcon is:
void DrawIcon(int x, int y, const uint16_t icon, int dx /= 64/, int dy /= 64/, bool highContrast /= false/) {
for (int yi = 0; yi < dy; yi++) {
for (int xi = 0; xi < dx; xi++) {
uint16_t pixel = icon[yi * dx + xi];
if (highContrast) {
if (15 - (pixel / 4096) > 0) canvas.drawPixel(x + xi, y + yi, M5EPD_Canvas::G15);
} else {
canvas.drawPixel(x + xi, y + yi, 15 - (pixel / 4096));
}
}
}
}*Why is the created icon not displaying correctly?
-
M5Paper online PNG icons problem(s)
I have writen a sketch which gets JSON data from Open Weather Maps and displays it on my M5Paper device. I have included an icon for the weather which is obtained from https://openweathermap.org/img/wn/10d@2x.png with 10d replaced by the icon id for present weather conditions.
My first issue is that it takes literally minutes for the icon to actually appear, a long time after the other info has been displayed. Is this usual?
My second issue, possibly related to the first, is that when the M5Paper isn't connected to an external usb power source the icon simply never appears at all. All other data appears and is refreshed after a shutdown interval, but the icon never appears at all. What could be the cause?
-
RE: Cannot canvas.drawString() onto canvas. (M5PaperTouchArea)
I am just starting out with the M5Paper and a lot of things are taking some getting use to. I thought about deleting this thread when I found out how easy the solution was but then I thought that maybe this will help someone else. So here is the solution:
You have to declare a font for use in the canvasOP. So adding his line after creating canvasOP fixes the problem:
canvasOP.setFreeFont(&FreeSerif24pt7b); -
Cannot canvas.drawString() onto canvas. (M5PaperTouchArea)
I have made a small modification to RAWSEQ'sexcellent M5PaperTouchArea project.
I am trying to use the spare white area as an output canvas. I can place the CanvasOP (output canvas) correctly and I can check it is really there by filling it in different shades and moving it around. but I cannot write into it. Any canvasOP.drawString() commands seem to be ignored. I have tried changing the text color, size and position but I cannot seem to get text to show up on the pushed canvasOP.
#include <M5EPD.h> #include "M5PaperTouchArea.h" #include "MPlusFontsSubset.h" // M5EPD Canvas M5EPD_Canvas canvas(&M5.EPD); M5EPD_Canvas canvasOP(&M5.EPD); // Module (Grid & TouchArea) M5PaperTouchAreas _m5pta; // Module (Grid Only) GridUtil _gu; void setup() { // Display Setup M5.begin(); M5.EPD.SetRotation(90); M5.TP.SetRotation(90); M5.EPD.Clear(true); canvas.loadFont(MPlusFontsSubset, sizeof(MPlusFontsSubset)); canvas.createCanvas(540, 960); canvas.createRender(48, 256); canvas.fillRect(0, 0, 540, 960, 10); _m5pta.current_canvas = &canvas; _m5pta.getGutil()->setVertical(true); _gu.setVertical(true); // Event Setting _m5pta.e_touch.func = bTouch; _m5pta.e_release.func = bRelease; // Change Default Setting _m5pta.default_font_size = 48; _m5pta.default_radius = 15; _m5pta.default_font_linepos = 6; _m5pta.default_bc = { 13, 0, 0 }; // Touch Area Test _m5pta.add_grid(1, 1, 1, 1, "B1", "b1"); _m5pta.add_grid(2, 1, 1, 1, "B2", "b2"); _m5pta.add_grid(3, 1, 1, 1, "B3", "b3"); _m5pta.add_grid(4, 1, 1, 1, "B4", "b4"); _m5pta.add_grid(5, 1, 1, 1, "B5", "b5"); _m5pta.add_grid(1, 2, 3, 1, "B6", "b6"); _m5pta.add_grid(4, 2, 2, 1, "B7", "b7"); _m5pta.add_grid(1, 3, 2, 1, "B8", "b8"); _m5pta.add_grid(3, 3, 3, 1, "B9", "b9"); _m5pta.add_grid(1, 4, 5, 1, "B10 Steve", "Steve"); _m5pta.add_grid(1, 5, 2, 1, "B11", "b11"); //_m5pta.add_grid(3, 5, 3, 2, "B16", "b16");//added by steve _m5pta.add_grid(1, 6, 2, 2, "B12", "b12"); _m5pta.add_grid(3, 7, 3, 3, "B13", "b13"); _m5pta.add_grid(1, 8, 2, 1, "B14", "b14"); _m5pta.add_grid(1, 9, 2, 1, "B15", "b15"); _m5pta.draw(); // Grid Draw Test // GURect g = _gu.convert(3, 5, 3, 2); // canvas.setTextColor(10); // canvas.fillRect(g.x, g.y, g.w, g.h, 0); canvas.pushCanvas(0, 0, UPDATE_MODE_GC16); /* Serial.print(g.x); Serial.print("..."); Serial.print(g.y); Serial.print("..."); Serial.print(g.w); Serial.print("..."); Serial.print(g.h);*/ //230...440...290...180 g.cordinates canvasOP.createCanvas(290, 180); //canvasOP.fillCanvas(5); canvasOP.setTextSize(4); canvasOP.setTextColor(15); canvasOP.drawString("Hello", 20, 100); canvasOP.pushCanvas(230, 440, UPDATE_MODE_GC16); } // Touch Event void bTouch(M5PTAEventContext& ct) { Serial.println("T:" + ct.code); } // Release Event void bRelease(M5PTAEventContext& ct) { Serial.println("R:" + ct.code); } void loop() { _m5pta.loop(); }
-
Cannot compile M5Paper Weather sketch
I have downloaded this sketch along with all of the XX.h files and installed them in my Arduino directory, as I have prviously done with other GIT sketches. https://github.com/Bastelschlumpf/M5PaperWeather/tree/master/weather Unfortunately I cannot get this sketch to compile, it complains that in "..../Time.h MyData was not declared in this scope"
I have noticed that in Time.h there is the line 22 "#pragma once" which is not followed by any local XX.h files as it is in the other local libraries and .h files. I am nor familiar with" #pragma once" and am wondering if another library is supposed to declare MyData. MyData is declared as a class in Data.h.
-
RE: Resetting RTC flag
Thanks for the insights folks. However I am still confused as to how have an RTC restart do one thing and a power button restart do another.
My practical goal is to have the M5Paper go online and retrieve the NTP time data on a button power on but, in order to save battery charge to simply use the RTC for time data on an RTC restart.
-
Resetting RTC flag
I cannot get the RTC flag on my M5paper to work correctly. Using the example RTC_WakeUp the screen always reads "Power on by: RTC timer" however the device was started. Even if I press the reset button first and then the on button, the screen still says "Power on by: RTC timer". I seems the if ((data & 0b00000100) == 0b00000100) statement is always true. How can I reset it?
#include <M5EPD.h> M5EPD_Canvas canvas(&M5.EPD); void setup() { // Check power on reason before calling M5.begin() // which calls RTC.begin() which clears the timer flag. Wire.begin(21, 22); uint8_t data = M5.RTC.readReg(0x01); M5.begin(); bool flagRTC = false; // Check timer flag if ((data & 0b00000100) == 0b00000100) { flagRTC = true; Serial.println("Power on by: RTC timer"); } else { Serial.println("Power on by: PWR Btn"); } M5.EPD.SetRotation(90); M5.TP.SetRotation(90); M5.EPD.Clear(true); M5.RTC.begin(); canvas.createCanvas(540, 960); canvas.setTextSize(3); if (flagRTC) canvas.drawString("Power on by: RTC timer", 25, 250); // <= this one we should when waking up from sleep else canvas.drawString("Power on by: PWR Btn", 25, 250); canvas.drawString("Press PWR Btn for sleep!", 45, 350); canvas.drawString("after 5 sec wakeup!", 70, 450); canvas.pushCanvas(0, 0, UPDATE_MODE_DU4); } void loop() { if (M5.BtnP.wasPressed()) { canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550); canvas.pushCanvas(0, 0, UPDATE_MODE_DU4); delay(1000); M5.shutdown(5); // shut donw now and wake up after 5 seconds } M5.update(); delay(100); }
-
RE: Converting M5CoreInk sketch to M5Paper
Ah, thanks. Now I realise that I will develope the sketch further.
-
Converting M5CoreInk sketch to M5Paper
I have tried to convert a working sketch for the M5CoreInk to work on the M5Paper. The M5CoreInk sketch deliberately doesn't use the loop() in order to extend battery charge life by shutting down and restarting the device. The working CoreInk sketch can be seen at the bottom of this post.
Meanwhile here is the non working M5Paper version. I have been working on it for a few days now and have probably messed it up too much but I would appreciate a few pointers as to what is going wrong. The main problem seems to be that the sketch loads and displays the daty but then just stops and never wakes up.
#include <M5EPD.h> #include <WiFi.h> #include "Secrets.h" rtc_time_t RTCtime; char timeStrbuff[64]; rtc_date_t RTCDate; char dateStrbuff[64]; char connStrbuff[64]; // every hour at minute 45 do a full ink display refresh #define FULL_REFRESH_MINUTE (45) static const char* wd[7] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; char temStr[10]; char humStr[10]; char Humidity[10]; M5EPD_Canvas canvas(&M5.EPD); M5EPD_Canvas canvas2(&M5.EPD); M5EPD_Canvas canvasTime(&M5.EPD); M5EPD_Canvas canvasConnect(&M5.EPD); RTC_SLOW_ATTR bool ntpDataFlag = false; const char* ssid = SECRET_SSID; const char* password = SECRET_PASS; const char* ntpServer = SECRET_NTP; const long gmtOffset_sec = 3600; const int daylightOffset_sec = 3600; time_t t; struct tm* tm; struct tm timeinfo; //tm = localtime(&t); void getRTCtime() { M5.RTC.getTime(&RTCtime); sprintf(timeStrbuff, "%02d:%02d:%02d", RTCtime.hour, RTCtime.min, RTCtime.sec); sprintf(dateStrbuff, "%02d:%02d:%02d", RTCDate.day, RTCDate.mon, RTCDate.year); } void SetRTC() { // struct tm timeinfo; tm = localtime(&t); if (getLocalTime(&timeinfo) == false) { Serial.println("Failed to obtain time"); return; } Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); RTCtime.hour = timeinfo.tm_hour; RTCtime.min = timeinfo.tm_min; RTCtime.sec = timeinfo.tm_sec; M5.RTC.setTime(&RTCtime); RTCDate.week = timeinfo.tm_wday; RTCDate.day = timeinfo.tm_mday; RTCDate.mon = timeinfo.tm_mon + 1; RTCDate.year = timeinfo.tm_year + 1900; M5.RTC.setDate(&RTCDate); } void getNTPTime() { // Try to connect for 10 seconds uint32_t connect_timeout = millis() + 10000; Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while ((WiFi.status() != WL_CONNECTED) && (millis() < connect_timeout)) { delay(500); Serial.print("."); } if (WiFi.status() != WL_CONNECTED) { Serial.print("Connection failed"); //WiFi connection failed - set fantasy time and date RTCtime.hour = 00; RTCtime.min = 00; RTCtime.sec = 00; M5.RTC.setTime(&RTCtime); RTCDate.year = 2022; RTCDate.mon = 11; RTCDate.day = 27; M5.RTC.setDate(&RTCDate); return; } //Serial.println("Connected"); canvasConnect.drawString("Connecting to NTP", 00, 00); //Draw a string. canvasConnect.pushCanvas(10, 900, UPDATE_MODE_DU4); configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); SetRTC(); WiFi.disconnect(true); WiFi.mode(WIFI_OFF); //Serial.println("Disconnected"); canvasConnect.drawString("Disconnected from WiFi", 00, 00); //Draw a string. canvasConnect.pushCanvas(10, 900, UPDATE_MODE_DU4); } void getTempHum() { M5.SHT30.UpdateData(); float tem = M5.SHT30.GetTemperature(); float hum = M5.SHT30.GetRelHumidity(); String bufTem; bufTem += String(tem, 2); bufTem += F("*C"); String bufHum; bufHum += String(hum, 2); bufHum += F("%"); float batLevel = M5.getBatteryVoltage(); batLevel = batLevel * 100 / 4350; String bufBat; bufBat += String(batLevel); bufBat += F("%"); canvasTime.drawString(bufTem, 0, 150); canvasTime.drawString(bufHum, 0, 200); canvasTime.drawString(bufBat, 0, 250); canvasTime.pushCanvas(250, 500, UPDATE_MODE_DU4); } void drawTimeAndDate() { getRTCtime(); int weekday = RTCDate.week; const char* wday = wd[weekday]; canvasTime.createCanvas(270, 300); //Create a canvas. canvasTime.setTextSize(4); //Set the text size. canvasTime.drawString(timeStrbuff, 0, 0); canvasTime.drawString(dateStrbuff, 0, 50); canvasTime.drawString(wday, 0, 100); getTempHum(); } void setup() { Wire1.begin(21, 22); uint8_t data = M5.RTC.readReg(0x01); M5.begin(); canvasConnect.createCanvas(540, 80); //Create a canvas. canvasConnect.setTextSize(4); //Set the text size. bool flagRTC = false; // Check timer flag if ((data & 0b00000100) == 0b00000100) { flagRTC = true; Serial.println("Power on by: RTC timer"); } else { Serial.println("Power on by: PWR Btn"); } M5.EPD.SetRotation(90); M5.EPD.Clear(true); M5.RTC.begin(); getNTPTime(); canvas.createCanvas(450, 500); // 450 wide and 500 high canvas.drawPngFile(SD, "/ClockwoBG.png"); //canvas.fillCanvas(0xFFFF); // Fill the drawn area with black. canvas.pushCanvas(90, 10, UPDATE_MODE_GC16); //Place 90 in and 10 down canvas2.createCanvas(270, 300); //Create a canvas. canvas2.setTextSize(4); //Set the text size. canvas2.drawString("TIME IS..", 00, 00); //Draw a string. canvas2.drawString("DATE IS..", 00, 50); //Draw a string. canvas2.drawString("DAY IS...", 00, 100); canvas2.drawString("TEMP IS..", 00, 150); canvas2.drawString("HUM IS...", 00, 200); canvas2.drawString("BATTERY..", 00, 250); canvas2.pushCanvas(20, 500, UPDATE_MODE_DU4); //Update the screen drawTimeAndDate(); if (flagRTC) Serial.println("Power on by: RTC timer"); else Serial.println("Power on by: PWR Btn"); // Wait until full minute, e.g. seconds are 0 while (timeinfo.tm_sec != 0) { Serial.println(timeinfo.tm_sec); delay(200); Serial.printf("Shutdown...\n"); // Full refresh once per hour if (timeinfo.tm_min == FULL_REFRESH_MINUTE - 1) { // Allow extra time for full ink refresh // Shutdown for 55 seconds only M5.shutdown(55); return; } // Shutdown for 58 seconds M5.shutdown(5); } } void loop() { }
Here is the CoreInk working sketch:
#include "M5CoreInk.h" #include <WiFi.h> #include "time.h" #include "esp_adc_cal.h" #include "secrets.h" const char* ssid = SECRET_SSID; const char* password = SECRET_PASS; const char* ntpServer = SECRET_NTP; const long gmtOffset_sec = 3600; const int daylightOffset_sec = 3600; // every hour at minute 45 do a full ink display refresh #define FULL_REFRESH_MINUTE (45) Ink_Sprite TimePageSprite(&M5.M5Ink); void printLocalTimeAndSetRTC() { struct tm timeinfo; if (getLocalTime(&timeinfo) == false) { Serial.println("Failed to obtain time"); return; } Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); RTC_TimeTypeDef time; time.Hours = timeinfo.tm_hour; time.Minutes = timeinfo.tm_min; time.Seconds = timeinfo.tm_sec; M5.rtc.SetTime(&time); RTC_DateTypeDef date; date.WeekDay = timeinfo.tm_wday; date.Date = timeinfo.tm_mday; date.Month = timeinfo.tm_mon + 1; date.Year = timeinfo.tm_year + 1900; M5.rtc.SetDate(&date); } String getBatteryVoltage() { analogSetPinAttenuation(35, ADC_11db); esp_adc_cal_characteristics_t* adc_chars = (esp_adc_cal_characteristics_t*)calloc(1, sizeof(esp_adc_cal_characteristics_t)); esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 3600, adc_chars); uint16_t adcValue = analogRead(35); float floatvoltage = esp_adc_cal_raw_to_voltage(adcValue, adc_chars) * 25.1 / 5.1 / 1000; int batteryPercentage = ((floatvoltage < 3.2) ? 0 : (floatvoltage - 3.2) * 100) - 10; String battPercent; battPercent += F("BATT "); battPercent += String(batteryPercentage); battPercent += F("%"); return battPercent; } void getNTPTime() { // Try to connect for 10 seconds uint32_t connect_timeout = millis() + 10000; Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while ((WiFi.status() != WL_CONNECTED) && (millis() < connect_timeout)) { delay(500); Serial.print("."); } if (WiFi.status() != WL_CONNECTED) { // WiFi connection failed - set fantasy time and date RTC_TimeTypeDef time; time.Hours = 6; time.Minutes = 43; time.Seconds = 50; M5.rtc.SetTime(&time); RTC_DateTypeDef date; date.Date = 4; date.Month = 12; date.Year = 2020; M5.rtc.SetDate(&date); return; } Serial.println("Connected"); configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printLocalTimeAndSetRTC(); WiFi.disconnect(true); WiFi.mode(WIFI_OFF); } String getDay(int day) { String weekday = "Non"; switch (day) { case 0: weekday = "SUN"; break; case 1: weekday = "MON"; break; case 2: weekday = "TUE"; break; case 3: weekday = "WED"; break; case 4: weekday = "THU"; break; case 5: weekday = "FRI"; break; case 6: weekday = "SAT"; break; Default: Serial.println("This shouldn't happen"); break; } return weekday; } void drawTimeAndDate(RTC_TimeTypeDef time, RTC_DateTypeDef date) { char buf[15]; snprintf(buf, 4, "%03s", getDay(date.WeekDay)); TimePageSprite.drawString(65, 00, buf, &AsciiFont24x48); snprintf(buf, 6, "%02d:%02d", time.Hours, time.Minutes); TimePageSprite.drawString(40, 40, buf, &AsciiFont24x48); snprintf(buf, 11, "%02d.%02d.%02d", date.Date, date.Month, date.Year - 2000); TimePageSprite.drawString(4, 80, buf, &AsciiFont24x48); String volts = getBatteryVoltage(); snprintf(buf, 15, "%s", volts); TimePageSprite.drawString(04, 160, buf, &AsciiFont24x48); } void setup() { // Check power on reason before calling M5.begin() // which calls Rtc.begin() which clears the timer flag. Wire1.begin(21, 22); uint8_t data = M5.rtc.ReadReg(0x01); M5.begin(); // Green LED - indicates ESP32 is running digitalWrite(LED_EXT_PIN, LOW); if (M5.M5Ink.isInit() == false) { Serial.printf("Ink Init failed"); while (1) delay(100); } RTC_TimeTypeDef time; RTC_DateTypeDef date; // Check timer flag if ((data & 0b00000100) == 0b00000100) { Serial.println("Power on by: RTC timer"); M5.rtc.GetTime(&time); M5.rtc.GetDate(&date); // Full refresh once per hour if (time.Minutes == FULL_REFRESH_MINUTE - 1) { M5.M5Ink.clear(); } } else { Serial.println("Power on by: power button"); M5.M5Ink.clear(); // Fetch current time from Internet getNTPTime(); M5.rtc.GetTime(&time); M5.rtc.GetDate(&date); } // After every shutdown the sprite is created anew. // But the sprite doesn't know about the current image on the // ink display therefore the same time and date, as have been // drawn before the shutdown, are redrawn. // This is required, else drawing new time and date only adds // pixels to the already drawn pixels instead of clearing the // previous time and date and then draw the new time and date. TimePageSprite.creatSprite(0, 0, 200, 200); drawTimeAndDate(time, date); TimePageSprite.pushSprite(); // Wait until full minute, e.g. seconds are 0 while ((time.Seconds != 0)) { M5.rtc.GetTime(&time); delay(200); } M5.rtc.GetDate(&date); // Draw new time and date drawTimeAndDate(time, date); TimePageSprite.pushSprite(); Serial.printf("Shutdown...\n"); Serial.flush(); // Full refresh once per hour if (time.Minutes == FULL_REFRESH_MINUTE - 1) { // Allow extra time for full ink refresh // Shutdown for 55 seconds only M5.shutdown(55); return; } // Shutdown for 58 seconds M5.shutdown(58); } void loop() { }
-
M5Paper, SD card stuck
I have a brand new M5Paper and was just starting to work with jpg files on the SD card. My first attempts worked and the SD card entered and exited the slot easily enough. Then, after modifying my pictures I re-inserted the SD card and the picture didn't appear after running the sketch. I tried to eject the SD card by pushing it in, as usual, but it simply went into the casing. I cannot get the SD card out and it is blocking the way for another SD card in the slot. The only way I can think of to remove the card would be to open the case of the M5Paper. What is the best way to do that?
-
How to add font to M5CoreInk.h
The basic library includes AsciiFont24x48 and AsciiFont8x16, how can I use other fonts?
-
RE: How to use the fonts available in /Arduino/libraries/M5GFX/src/lgfx/Fonts/GFXFF
I have found out how to use the fonts within the M5GFX library;
#include <Arduino.h> #include <M5GFX.h> M5GFX display; void setup() { display.begin(); display.setTextDatum(middle_center); uint16_t x = display.width() / 2; uint16_t y = display.height() / 2; display.setFont(&fonts::FreeMonoBold24pt7b); display.drawString("Test", x, y); } void loop() { }
-
How to use the fonts available in /Arduino/libraries/M5GFX/src/lgfx/Fonts/GFXFF
I have used the example "RTC_Clock" from the M5Core_Ink library as attached. The sketch works fine on my M5CoreInk module. I would like to modify the fonts however and I find that only AsciiFont24x48 and AsciiFont8x16 are available to use. Even though some other fonts are available under /Arduino/libraries/M5GFX/src/lgfx/Fonts if I try and use them in place of AsciiFont24x48 in the sketch below I get the error "'FontXXX' was not declared in this scope". How do I declare these additional fonts?
Also, I have seen that the Library MGFX has lots of fonts under /M5GFX/src/lgfx/Fonts/GFXFF. But I cannot find a simple example of using the M5GFX library to display a text string, any help would be appreciated.
One final point, if I include the M5GFX library tn the RTC_Clock sketch the compiler complains that AsciiFont24x48 is ambiguous as it has found two versions, how do I fix this?
#include "M5CoreInk.h" #include <WiFi.h> #include "time.h" const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASSWORD"; const char* ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 3600; const int daylightOffset_sec = 3600; // every hour at minute 45 do a full ink display refresh #define FULL_REFRESH_MINUTE (45) Ink_Sprite TimePageSprite(&M5.M5Ink); void printLocalTimeAndSetRTC() { struct tm timeinfo; if (getLocalTime(&timeinfo) == false) { Serial.println("Failed to obtain time"); return; } Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S"); RTC_TimeTypeDef time; time.Hours = timeinfo.tm_hour; time.Minutes = timeinfo.tm_min; time.Seconds = timeinfo.tm_sec; M5.rtc.SetTime(&time); RTC_DateTypeDef date; date.Date = timeinfo.tm_mday; date.Month = timeinfo.tm_mon + 1; date.Year = timeinfo.tm_year + 1900; M5.rtc.SetDate(&date); } void getNTPTime() { // Try to connect for 10 seconds uint32_t connect_timeout = millis() + 10000; Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while ((WiFi.status() != WL_CONNECTED) && (millis() < connect_timeout)) { delay(500); Serial.print("."); } if (WiFi.status() != WL_CONNECTED) { // WiFi connection failed - set fantasy time and date RTC_TimeTypeDef time; time.Hours = 6; time.Minutes = 43; time.Seconds = 50; M5.rtc.SetTime(&time); RTC_DateTypeDef date; date.Date = 4; date.Month = 12; date.Year = 2020; M5.rtc.SetDate(&date); return; } Serial.println("Connected"); configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printLocalTimeAndSetRTC(); WiFi.disconnect(true); WiFi.mode(WIFI_OFF); } void drawTimeAndDate(RTC_TimeTypeDef time, RTC_DateTypeDef date) { char buf[11]; snprintf(buf, 6, "%02d:%02d", time.Hours, time.Minutes); TimePageSprite.drawString(40, 20, buf, &AsciiFont24x48); snprintf(buf, 11, "%02d.%02d.%02d", date.Date, date.Month, date.Year - 2000); TimePageSprite.drawString(4, 70, buf, &AsciiFont24x48); } void setup() { // Check power on reason before calling M5.begin() // which calls Rtc.begin() which clears the timer flag. Wire1.begin(21, 22); uint8_t data = M5.rtc.ReadReg(0x01); M5.begin(); // Green LED - indicates ESP32 is running digitalWrite(LED_EXT_PIN, LOW); if (M5.M5Ink.isInit() == false) { Serial.printf("Ink Init failed"); while (1) delay(100); } RTC_TimeTypeDef time; RTC_DateTypeDef date; // Check timer flag if ((data & 0b00000100) == 0b00000100) { Serial.println("Power on by: RTC timer"); M5.rtc.GetTime(&time); M5.rtc.GetDate(&date); // Full refresh once per hour if (time.Minutes == FULL_REFRESH_MINUTE - 1) { M5.M5Ink.clear(); } } else { Serial.println("Power on by: power button"); M5.M5Ink.clear(); // Fetch current time from Internet getNTPTime(); M5.rtc.GetTime(&time); M5.rtc.GetDate(&date); } // After every shutdown the sprite is created anew. // But the sprite doesn't know about the current image on the // ink display therefore the same time and date, as have been // drawn before the shutdown, are redrawn. // This is required, else drawing new time and date only adds // pixels to the already drawn pixels instead of clearing the // previous time and date and then draw the new time and date. TimePageSprite.creatSprite(0, 0, 200, 200); drawTimeAndDate(time, date); TimePageSprite.pushSprite(); // Wait until full minute, e.g. seconds are 0 while ((time.Seconds != 0)) { M5.rtc.GetTime(&time); delay(200); } M5.rtc.GetDate(&date); // Draw new time and date drawTimeAndDate(time, date); TimePageSprite.pushSprite(); Serial.printf("Shutdown...\n"); Serial.flush(); // Full refresh once per hour if (time.Minutes == FULL_REFRESH_MINUTE - 1) { // Allow extra time for full ink refresh // Shutdown for 55 seconds only M5.shutdown(55); return; } // Shutdown for 58 seconds M5.shutdown(58); } void loop() { }