Navigation

    M5Stack Community

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

    Posts made by Hamnet

    • M5Paper: can't reconnect to WiFi after 'esp_light_sleep' (on power)

      I'm working on an app for M5Paper which will spend most of it's time asleep or shutdown; waking every few hours to check data from the internet (and depending on the results, either update the display or don't).

      So the loop function attempts to connect to WiFi and load the data, then disconnects; then either updates the display or doesn't; then attempts to shutdown. If the M5paper is on power, then the M5.shutdown command has no effect, so the code then calls esp_light_sleep_start.

      When it wakes up, if the unit is on battery (so it's a complete start-up) it all works as normal. If it is on power (so it's just resuming after 'light sleep') then it fails to connect to WiFi.

      If I replace the call to esp_light_sleep_start with a call to delay for the same period, then it connects repeatedly without issue.

      A summary of the code (this is using the WiFiMulti (ESP8266WiFiMulti) library by Markus Sattler, dated 16.05.2015, to support working across several locations with different WiFi availability):

      WiFiMulti wifiMulti;
      
      boolean connectToWifi()
      {
        uint8_t tRes;
      
        for (int i = 0; i < NUMWIFINETWORKS; i++) {
          wifiMulti.addAP(aWifiNetworks[i], aWifiPasswords[i]);
        }
      
        Serial.printf("Connecting Wifi... trying %d networks\n", NUMWIFINETWORKS);
        if ((tRes = wifiMulti.run()) == WL_CONNECTED) {
          Serial.print("WiFi connected ");
          Serial.println(WiFi.SSID());
          Serial.print("IP address: ");
          Serial.println(WiFi.localIP());
          return true;
        } else {
          Serial.printf("Failed to connnect to WiFi: %d.\n", tRes);
        }
      
        return false;
      }
      
      void disconnectFromWifi()
      {
        Serial.println("disconnecting from WiFi");
        WiFi.disconnect();
      }
      

      Evidently something in the course of esp_light_sleep_start 'breaks' something that the WiFi needs, so I need to reset it. But I don't know what, or how I can reset it!

      Can anyone shed any light?

      posted in Arduino
      H
      Hamnet
    • RE: M5Paper crashing on EPD.Clear, or SPIFFs.begin

      Hi @felmue,

      Thank you as ever for your helpful assistance.

      It's taken me a while to get back to this and make progress.

      By starting again with the basic sketch at https://github.com/m5stack/M5Unified/blob/master/examples/Basic/Displays/Displays.ino, using the M5unified and M5gfx libraries, I am at last able to build a non-crashing sketch again with the M5Paper, using either Arduino 2 IDE or the Arduino 1.8 IDE.

      However, although the SPIFFS.begin call no longer crashes, it returns an error. (And apparently the ESP32 Sketch Data Upload is not available in the Arduino 2 IDE, and for some reason I am unable to install it on the Arduino 1.8 IDE on this machine, although I was able to on the previous machine.)

      And I am sad to lose all the functions from the M5Paper library, which I am not clear to what extent they are replicated in the M5gfx library; or the RTC functions etc.

      Can you help me understand: from the remarks on this thread https://community.m5stack.com/topic/4891/m5paper-won-t-execute-loaded-programs/10 that you pointed me to, is there a simple fix that I can use to continue using M5EPD? Either by commenting out the lines mentioned in GT911.cpp (and presumably recompiling the library?); or by simply reverting to an earlier version of the Arduino libraries?

      Thanks again for your help.

      posted in Arduino
      H
      Hamnet
    • M5Paper crashing on EPD.Clear, or SPIFFs.begin

      Hello,

      I started working on M5Paper in the summer, had fun, got my project more or less working. Then life got in the way, I got a new computer, I moved house.

      Now I've finally opened it up again. Installed the driver and Arduino IDE (2.0.3, previously I was using 1.8) on my new computer (Macbook M1, previously on Intel Macbook); installed the M5Stack board manager, installed the M5EPD library; compiled my program, uploaded it.

      Serial monitor just showed repeated

      M5EPD initializing...OK
      M5EPD initializing...OK
      M5EPD initializing...OK
      

      ... etc

      I added a few more lines of debugging,

        Serial.println("\n\n------- begin ----");
        M5.begin();
        Serial.println("------- SetRotation ----");
        M5.EPD.SetRotation(90);
        Serial.println("------- Clear ----");
        M5.EPD.Clear(true);
      

      now I get repeated

      ------- begin ----
      M5EPD initializing...OK
      ------- SetRotation ----
      ------- Clear ----
      
      ------- begin ----
      M5EPD initializing...OK
      ------- SetRotation ----
      ------- Clear ----
      

      ... etc

      • in other words, it's crashing in M5.EPD.Clear(true);.

      If I comment out the call to M5.EPD.Clear, then I get as far as the next debugging statement, but the next call, to SPIFFS.begin, also crashes.

      Finally I created a new sketch, and copied the 'Hello World' code from https://docs.m5stack.com/en/quick_start/m5paper/arduino into it. Uploaded that, and back to the minimal output:

      M5EPD initializing...OK
      M5EPD initializing...OK
      M5EPD initializing...OK
      

      ... etc

      Can anyone suggest what might be going on here? Is there a problem with the 2.0.3 IDE? Do I need to update firmware to account for some updated libraries?

      Thanks in advance for any help you can give.

      posted in Arduino
      H
      Hamnet
    • RE: Some questions about power

      Thank you Felix. Disappointing that all the substantial sleep modes cause a reboot!

      My remaining question then is about how to enter light sleep.

      I found your post here from two years ago. And this post. There was also this, which is not M5 specific.

      From these I think that I need to do something like this:

        M5.disableEPDPower();
        M5.disableEXTPower();
      
        // then this??
        M5.Axp.LightSleep(SLEEP_SEC(5));
        
       // or this??
       esp_sleep_enable_timer_wakeup(5 * 1000 * 1000);
       esp_light_sleep_start();
      

      Can you clear up my confusion? And (for light sleep) do I need to do anything special with GPIO settings, which I can see from some of your earlier notes?

      thanks again.

      posted in Arduino
      H
      Hamnet
    • Some questions about power

      I've nearly completed my project on M5Paper, with thanks to the people on this forum who've helped me over many hurdles. The crucial last aspect is to get it running as long as possible on battery.

      Basically my project loads about 5 days worth of data from an internet resource; and then should update a display based on this data every 10 minutes or so.

      My original intention (based on this line in the product description "battery life can be further preserved by using the RTC to set the device into deep sleep and wake it up again when needed") was that it could shut down completely, leaving the display intact; wake up every 10 minutes to update just a bit of the display; and every 4-5 days refresh the data feed.

      However, it now appears that using the shutdown function with a time delay actually reboots the device when the time expires, rather than just waking up.

      Q1: Is that correct, or have I missed an option that will to shut down everything except the RTC, but preserve state so that it doesn't reboot on wake up?

      The second issue is that I don't want the display flashing every 10 minutes; it's an essential aspect of this project that the display should be discreet. Hence I only want to make small updates to the display every 10 minutes; larger updates every six hours or so.

      From experiments, it's evident that the basic arduino 'delay' function makes little or no difference to power consumption.

      I understand from the data on @felmue's info page and from this forum post that it should be possible to use either "light sleep" or "deep sleep". But (a) I've not been able to figure out the code for this and (b) I'm not clear from these sources whether I need to make a hardware modification before it is safe (and effective?) to use these functions. (I'm using an M5Paper V1.1.)

      Q2: Is deep sleep my next best option to conserve power between updates, without causing massive screen blink?

      Q3: Do I need to make a hardware modification in order to access this?

      Finally, if I indeed I can get somewhere with the rest of this, I'm thinking that I'll do a completely shutdown for six hours or so in the middle of the night. That will probably mean reloading the data every 24 hours instead of every 4-5 days.

      Q4: If I shut down the wifi immediately after loading data; is the power required to start up the wifi, find the access point, load the data etc more often significant? Or is the power draw of the device as a whole remain fairly steady regardless of whether the wifi is on? If I do shutdown every night, is it worth writing the data to SPIFFS so that it can recover it locally after rebooting, rather than getting it from the internet each time?

      TIA for answers to any or all of these questions!

      posted in Arduino
      H
      Hamnet
    • RE: Accessing SPIFFS independently of loading program

      @felmue Thank you so much Felix, you've helped me again.

      posted in Arduino
      H
      Hamnet
    • Accessing SPIFFS independently of loading program

      I have some questions about SPIFFS.

      I think I understand how to access it from within my program (theoretically, I haven't tried this). But I've a couple of theoretical questions, and one practical one:

      Do the contents survive hard reset?
      Do the contents survive uploading new software?

      My interest is in using it to store font files for use on M5Paper. I've seen examples referencing a font file on SPIFFS. My practical question is how they get there! Is there a way to store data on SPIFFS independently of the program I upload. That is, can I upload some font files; and then access them regardless of the programs I'm uploading? Or does each program have to first download the font file from somewhere, store it on SPIFFS, so it can then access it?

      (Or do I need to write a program to load a file on to SPIFFS, run that, then overwrite it with the program that will use those files?)

      Apologies if this is covered somewhere in docs, I couldn't see it.

      TIA

      posted in Arduino
      H
      Hamnet
    • RE: Retrieving data over HTTPS (M5 Paper, but I think this is a generic question)

      @felmue Thanks Felix, that got me over the hump! I think the issue was trying to convert my existing example directly.

      posted in Arduino
      H
      Hamnet
    • RE: Retrieving data over HTTPS (M5 Paper, but I think this is a generic question)

      (I should add - as a temporary workaround I can access an https: resource by calling client.setInsecure(); but I'm looking for a proper solution.)

      posted in Arduino
      H
      Hamnet
    • Retrieving data over HTTPS (M5 Paper, but I think this is a generic question)

      I'm sure this is basic but it's driving me crazy. I can retrieve data over wifi from an "http:" source with no problem. But I can't figure out how to access a URL over https.

      All the examples I can find online - for Arduino, ESp32, or M5 - seem to use http: URLs in their demos. I've found references to WifiClientSecure, but not a usable example. Evidently simply substituting it for WifiClient is not sufficient!

      The canvas.drawJpgUrl function works with an "https:" URL, so clearly there is no fundamental difficulty.

      Googling led me to this excellent library "Fetch": but alas the examples don't compile, a problem others have noted.

      Probably part of the problem is the number of different libraries with similar or even identical names, and different versions of the same library.

      Please can someone recommend the current best (or at least good!) library to use, and point me at a working example?

      Thanks in advance!

      posted in Arduino
      H
      Hamnet
    • RE: Another basic question: how do the APIs interact?

      @ajb2k3

      To clarify, I think you're implying that some of the other APIs are available to me on M5Paper, but some aren't - is that correct?

      Yes, correct.

      Is there any way to tell which ones can and which can't? Is it API by API, or is it more granular - certain functions documented under other APIs are available?

      For example, are the functions under https://docs.m5stack.com/en/api/core/power available - lightSleep, deepSleep etc?

      Thanks again for all the help.

      posted in Arduino
      H
      Hamnet
    • RE: M5Paper v1.1: Detect charging state and progress

      Hi @MauriceX111 I've also just got an M5 Paper v1.1 (my first experience of M5 or ESP32) and it is a very nice product but I'm also struggling to find out things... Very grateful that this community - and especially @felmue - are here, otherwise I'd be completely stuck!

      Felix pointed me at the code that the device ships with.

      Searching this, I found here the following code

          // Battery
          _bar->setTextDatum(CR_DATUM);
          _bar->pushImage(498, 8, 32, 32, ImageResource_status_bar_battery_32x32);
          uint32_t vol = M5.getBatteryVoltage();
      
          if (vol < 3300) {
              vol = 3300;
          } else if (vol > 4350) {
              vol = 4350;
          }
          float battery = (float)(vol - 3300) / (float)(4350 - 3300);
          if (battery <= 0.01) {
              battery = 0.01;
          }
          if (battery > 1) {
              battery = 1;
          }
          uint8_t px = battery * 25;
          sprintf(buf, "%d%%", (int)(battery * 100));
          // _bar->drawString(buf, 498 - 10, 27);
          _bar->fillRect(498 + 3, 8 + 10, px, 13, 15);
      

      So that doesn't help with finding out whether the battery is charging; but it does seem to be the best available way to represent the charge level.

      HTH.

      posted in PRODUCTS
      H
      Hamnet
    • RE: Another basic question: how do the APIs interact?

      @teastain that post looks very relevant, I'll see if I can understand it! My use case is that I'm trying to create a unit that will run on battery power for as long as possible; fetching data over WiFi only once every few days; updating the display perhaps 4-5 times/hour. So I want it to consume as little as possible most of the time.

      @ajb2k3 thank you, I'll check out the videos (I normally avoid videos, I find it easier to learn from text). To clarify, I think you're implying that some of the other APIs are available to me on M5Paper, but some aren't - is that correct?

      posted in Arduino
      H
      Hamnet
    • RE: Another basic question: how do the APIs interact?

      Well I wrote loads of programs in C (and a bit of C++) 20 years ago; and I've fiddled with Arduino a tiny bit a few years ago; so I think I'm comfortable in principle with working at that level. But I don't have any experience with ESP32, let alone M5 - and finding it hard to get both detailed (accurate!) reference documentation, and also the basic orientation.

      posted in Arduino
      H
      Hamnet
    • RE: Another basic question: how do the APIs interact?

      Hi Terry @teastain you can't patronise me! I really know nothing - I'm new to all of this - M5, ESP32, etc. Thanks for taking the time to help.

      So to be clear: can I use any of the other APIs? (E.g. Core, Core2?)

      And in relation to this particular example, how can I turn the power off or put the device into deep sleep until the RTC wakes it up, given that Axp.PowerOff(); isn't available? (The PAPER API system/button/power docs reference shutdown taking a delay to wake up again - but that does a full restart.)

      posted in Arduino
      H
      Hamnet
    • Another basic question: how do the APIs interact?

      The docs at https://docs.m5stack.com/en/api/ are divided into various APIs: CORE API, CORE2 API, PAPER API etc.

      A very basic question: when programming an M5 Paper, is the PAPER API the only one available?

      I sort of assumed it would be, because of the overlaps. But then I noticed that the example for SetAlarmIRQ on https://docs.m5stack.com/en/api/m5paper/rtc contains a call to M5.Axp.PowerOff();, which isn't covered in the PAPER API docs:

      void loop() {
        M5.update();
        M5.Rtc.GetTime(&TimeStruct);
        M5.Lcd.setCursor(0, 15);
        M5.Lcd.printf("Time: %02d : %02d : %02d/n",TimeStruct.Hours, TimeStruct.Minutes, TimeStruct.Seconds);
        if(M5.BtnA.wasPressed()){
          M5.Lcd.println("M5Core2 Will Close, Restore After 5 seconds ");
          delay(2000);
          M5.Rtc.clearIRQ();
          M5.Rtc.SetAlarmIRQ(5);
          delay(10);
          M5.Axp.PowerOff();
        }
      }
      

      So can we use any of the M5 APIs? Or is there some that we can use on M5 Paper, and some not?

      (e.g. the COREINK and M5GFX APIs support sprites - can I use those on M5 Paper?)

      TIA

      posted in Arduino
      H
      Hamnet
    • RE: M5paper: source code of the default apps?

      @felmue thank you.
      I've installed VS Code, and installed the PlatformIO IDE into it.
      Under Devices, it can see the one corresponding to the M5paper.
      Under Boards, it offers many of the M5 APIs, but M5paper isn't in the list.
      I can open the "M5Paper_FactoryTest" project; it has "board" set to "m5stack-fire".

      After a few false starts, it builds and installs on the device, so that's all good.

      Is there anything I can/should do to set the board correctly? Does it matter?

      posted in SOFTWARE
      H
      Hamnet
    • RE: M5paper: source code of the default apps?

      Thank you Felix @felmue, that's very helpful.

      A naive question - how can I compile that back on to the device? The only mechanism I've got working to talk to it is Arduino - I see a reference to Arduino in the .ini file, but can't open it as a project in the Arduino IDE.

      Is there something different I need to open it in Arduino? Or do I need to use some different method altogether.

      Thanks again for all your assistance.

      posted in SOFTWARE
      H
      Hamnet
    • RE: M5 Paper - please help me understand the canvas

      Thanks Felix and @ajb2k3. I've found the root of my problem, which is that I was using a different update mode (DU4) in the loop than in the setup (GC16).

      From this I infer that there are least two buffers in a canvas (one for graphics, one for text); since when I pushed the canvas shifted to a different position, using DU4, it placed the text in a shifted position, but didn't update the graphic.

      Is that correct, and are there more than two buffers?

      posted in Arduino
      H
      Hamnet