Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Jop
    • Continue chat with Jop
    • Start new chat with Jop
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    Jop

    @Jop

    Some experience with programming ESP32
    A newbie on the M5Stack-platform; I only have now a M5Paper

    1
    Reputation
    12
    Posts
    1233
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online
    Location Ede, Netherlands

    Jop Follow

    Posts made by Jop

    • RE: [M5Paper] integrated speaker

      @zontex
      I have same wish for the M5Paper and "speaker" means for me, that it would be enough for only programmed alert/alarm-sounds for certain situations (f.e. temperature is above/under certain level a.s.o)

      posted in Features Wish List
      Jop
    • RE: [M5Paper] Ideas for a revision or V2 model - a font with degree-Celsius and degree-Fahrenheit

      Hi @zontex, thanx,
      I think a lot of developers will be pleased.
      One suggestion: isn't it possible already now to implement an easy solution by an update of the M5EPD-library?

      posted in Features Wish List
      Jop
    • [M5Paper] Ideas for a revision or V2 model - a font with degree-Celsius and degree-Fahrenheit

      Now it is too complicated if the standard font suits your needs but only the degree character is missing, to get those symbols available.
      We should get possibility to get a font with changeable characters or something like that. Nice would be to have on a easy way the degree-Celsius (℃) and degree-Fahrenheit (℉) as just one character available.

      posted in Features Wish List
      Jop
    • [M5Paper] Ideas for a revision or V2 model - external WiFi-antenna

      Re: [M5Paper] Ideas/recommendations for a revision or V2 model
      Possibility for an external WiFi-antenna connected by the Groove connector.

      posted in Features Wish List
      Jop
    • RE: M5Paper Shutdown() / Deep Sleep / Wakeup

      As I promised here at end of my post under another thread, the shutdown() is rather buggy in the way awakening is performed.
      I'll describe here what I experienced.

      Anyway one should take this advice of @felmue in account.
      There are different shutdown() overload variations and here bugs or weird things I found.

      My goal was holding the M5Paper as much as possible sleeping, but at intervals of every full 5 minutes he should awake for about 10 to 15 seconds, perform some tasks (sensors) and go again sleeping to the next full 5-minute moment.

      • overload-2 int shutdown( int seconds );
        Even if I calc enough seconds to next 5-minute moment, it seems impossible to stay asleep for remaining 5 minutes. Every 3th minute it is awakening too. This consumes unnecessary double battery power.
        So where I want to have this wake up schedule: hh:00 hh:05 hh:10 hh:15 hh:20 ...and so on...
        I get this wake up schedule: hh:00 hh:03 hh:05 hh:08 hh:10 hh:13 hh:15 hh:18 hh:20 ...and so on...
        This overload-2 has no problems by passing the midnight moment.

      • overload-3
        int shutdown( const rtc_time_t &RTC_TimeStruct );
        This variation works best. Passing midnight (so date change) is no problem but 24:00u should be given als 00:00u.

      • overload-4
        int shutdown( const rtc_date_t &RTC_DateStruct, const rtc_time_t &RTC_TimeStruct );
        is working, but passing midnight in a way to set awake time at 00:00h and increasing the date-parameter does NOT work! Also 24:00u without increasing the date does NOT work.
        The only way to pass midnight is awaking just some seconds before midnight and stay awake till after midnight, do the things that has to be done (sample sensors) and go asleep for remaining period (in my case to 00:05u).

      I hope others can take advantage of this info.

      posted in Cores
      Jop
    • RE: M5Paper wakeup cause

      @felmue
      Hello Felix,

      No, didn't try rename rtc. What difference should it make? (In C++ rtc and RTC are different identifiers, is n't it).
      The reason for introduction of the own internal rtc of the ESP32 was looking for a simple way to set the system clock from the M5Paper RTC after awakening and without connecting to WiFi (this is very time- and battery-consuming).

      The weird thing is: syncing with NTP is rather simple in ESP32-Arduino environment, but just setting the system time equal to the 'external' BM8563 RTC-time is more complicated. There is no simple routine. I found some not so elegant way with mktime().

      Another point: I discovered bugs with awakening the M5Paper when this awakening moment should be exactly at midnight: so at 24:00u or 00:00u.
      See a next post (if I find time to describe).

      posted in Cores
      Jop
    • RE: M5Paper wakeup cause

      @felmue

      Hi Felix,

      In addition to my last post, I wrote that the shutdown() looks rather buggy.

      Now I found reason for this behavior - partly reason - some overload variations are now OK, but one has still problem as I described in my last post.
      The reason for buggy behavior, I included this:
      #include <ESP32Time.h>
      ESP32Time rtc;
      to make it possible to set also the ESP32 internal RTC that's present in this processor, named by me with "rtc".
      The external BM8563 I named as "RTC".
      Maybe these library is interfering with the BM8563-code.

      I said "partly reason" as Overload-2 still has the same problem as I wrote before.

      posted in Cores
      Jop
    • RE: M5Paper wakeup cause

      @felmue
      Hi Felix,

      Thnx for your fast response.

      I out commented the 2 lines you mentioned, this seems to work, but I experience more problems.
      This shutdown() logic of the M5Paper is rather buggy. I think some engineers of M5Stack should inspect this modules and repair.
      For example: I want my M5Paper to be waked up by the RTC every full 5 minutes, then it has to run for about 10 to 15 seconds and to go in sleepmode for the rest of that 5-minute period. For that I wrote routine goSleep() to calculate the next moment of awakening.
      I tried several possibilities for the different overlaid methods of shutdown():

      1. calculate remaining seconds to go sleep and used overload-2
      2. calculate timestamp for the next 5-minute moment and used overload-3
      3. calculate date & timestamps for the next 5-minute moment and used overload-4

      Now comes the weird thing (so the bugs), in any of these cases the wakeup comes ALSO at every 3-minute, so both at every 3-minute and at every 5-minute moments.
      So where I want to have this wake up schedule: hh:00 hh:05 hh:10 hh:15 hh:20 ...and so on...
      I get this wake up schedule: hh:00 hh:03 hh:05 hh:08 hh:10 hh:13 hh:15 hh:18 hh:20 ...and so on...

      Before your suggested patch I tried only method 1 (as 2 did not work without your patch) and then it was every 4-minute and every 5-minute my M5Paper woke up by the RTC.
      I inspected my calculations logic and this is OK. The problem is somewhere in the M5Paper library.

      If necessary I can isolate the code I use to show you; but that's a bit more work.

      posted in Cores
      Jop
    • RE: M5Paper wakeup cause

      @felmue
      Hi Felix,

      Good tip. It works.

      Here the update code based on an example from the M5EPD library:

      #include <M5EPD.h>
      
      // m5paper-wakeup-cause
      // see forum: https://community.m5stack.com/topic/2851/m5paper-wakeup-cause/6
      
      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);
      }
      

      One extra remark (maybe for a new topic): the shutdown() routine has some overloaded variations. Unfortunately not very well documented, as the version with only time (see: int shutdown( const rtc_time_t &RTC_TimeStruct); ) seems not to work as expected. If add the date too (last overloaded version) it works. Maybe my expectations are wrong. Sometimes one should like a bit more specifications from M5Stack in this documentation (is a timesaver).

      Anyway thnx for your suggestion Wire1 => Wire.

      posted in Cores
      Jop
    • RE: M5Paper wakeup cause

      Hi @felmue,

      Interesting post you wrote - nice solution to detect reason for awakening the M5Paper. But unfortunately the code you gave for M5Corelink doesn't compile on a M5Paper.

      I did some trial and error modifications and within 5 minutes I got code that does compile.
      Here just the relevant code in setup() - sketch from an example in the M5EPD library:

      #include <M5EPD.h>
      
      // is not yet working as should be
      
      M5EPD_Canvas canvas(&M5.EPD);
      
      void setup() {
        // Check power on reason before calling M5.begin()
        //  which calls Rtc.begin() which clears the timer flag.
        Wire1.begin(21, 22);                  // Jop: compiles
      //uint8_t data = M5.rtc.ReadReg(0x01);  // Jop: compiles NOT
        uint8_t data = M5.RTC.readReg(0x01);  // Jop: compiles   
         
        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 see always
        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);
        }
        M5.update();
        delay(100);
      }
      

      As you see I had to change just some capital-mode in identifiers to get it compiled.
      But apparently not the right register or bits are used for detecting wakeup cause.

      Maybe someone else is triggered by this to find the full solution for the M5Paper.

      posted in Cores
      Jop