Navigation

    M5Stack Community

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

    koichirose

    @koichirose

    0
    Reputation
    5
    Posts
    937
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    koichirose Follow

    Posts made by koichirose

    • RE: High power consumption with deep sleep

      @felmue that's really unfortunate. The C-plus actually has a 120mAh battery, not that it makes a difference...
      The Core2 actually lasts a while, I have one that's been unplugged for a few days (doing the same thing, just showing the battery level) and it's still alive.

      @robalstona what do you mean by "check when the power button is pressed to power on device" ?

      Thanks

      posted in M5 Stick/StickC
      K
      koichirose
    • High power consumption with deep sleep

      My goal: make the "M5" button behave like the power button.
      The "M5" button is more user friendly.
      This code runs once, puts the M5Stick C Plus into deep sleep, then the "M5" button wakes it up:

      #include <M5StickCPlus.h>
      
      //seconds
      const int timeout = 10;
      
      hw_timer_t * timer = NULL;
      bool go_to_sleep = false;
      
      void IRAM_ATTR onTimer()
      {
        Serial.println("onTimer called");
        go_to_sleep = true;
      }
      
      void setup() {
        sleep_wake();
        M5.begin();
        M5.Lcd.fillScreen(BLACK);
        set_backlight();
        setCpuFrequencyMhz(80);
        timer = timerBegin(0, 80, true);
        timerAttachInterrupt(timer, &onTimer, true);
        timerAlarmWrite(timer, timeout * 1000 * 1000, true);
        timerAlarmEnable(timer);
        M5.Lcd.setCursor(0, 35, 4);
        battery_display();
      }
      
      void loop() {
        delay(1000);
        sleep_check();
      }
      
      void sleep_check(void)
      {
        if(go_to_sleep == true) {
          deep_sleep();
        }
      }
      
      void set_backlight(void)
      {
          M5.Axp.ScreenBreath(8);
      }
      
      void clear_txt(void)
      {
        M5.Lcd.fillScreen(BLACK);
      }
      
      void battery_display(void)
      {
        M5.Lcd.setCursor(20, 20, 4);
        M5.Lcd.setTextSize(2);
        M5.Lcd.printf("%d%%", (int) battery_level());
        M5.Lcd.print("\n");
        M5.Lcd.setTextSize(1);
        M5.Lcd.printf("%fV", M5.Axp.GetBatVoltage());
      }
      
      double battery_level(void)
      {
        uint16_t vbatData = M5.Axp.GetVbatData();
        double vbat = vbatData * 1.1 / 1000;
        double percentage = 100.0 * ((vbat - 3.0) / (4.07 - 3.0));
        return min(percentage, 100);
      }
      
      void sleep_wake(void)
      {
        pinMode(GPIO_NUM_37, INPUT_PULLUP);
        esp_sleep_enable_ext0_wakeup(GPIO_NUM_37, LOW);
      }
      
      void backlight_off(void)
      {
        delay(1000);
        M5.Axp.ScreenBreath(0);
      }
      
      void deep_sleep(void) {
        clear_txt();
        M5.Lcd.setCursor(0, 30, 2);
        M5.Lcd.printf("Deep sleep\n");
        delay(1000);
        clear_txt();
        backlight_off();
        delay(3900);
        clear_txt();  
      
        // if I use this function, I can't wake it up with the M5 button anymore
        // M5.Axp.DeepSleep();
      
        // this works
        esp_deep_sleep_start();
      }
      

      Right now it does nothing, it only prints the battery level and goes to sleep after 10 seconds.
      If I unplug the device when fully charged (4.1V), then press the "M5" button once in a while (less than once an hour), I noticed a battery life of about 12 hours, which is way too little.
      I imagine that if I actually make it do stuff (like connecting to WiFi and perform a HTTP request), it would last even less.

      Is this correct? Can I improve it somehow?

      Thanks

      posted in M5 Stick/StickC
      K
      koichirose
    • Deep Sleep with MicroPython

      Hi, I'd like to press the M5 button on my M5StickC-Plus, do something, turn it off/deep sleep and turn it back on with the 'M5' button, as it is easily accessible. Basically I think this is how one of those Dash buttons used to work.

      I tried with:

      axp.setLDO2State(False)
      axp.setLDO3State(False)
      

      The screen turns off, but the device seems very much alive (I tried issuing commands from the REPL) and, when unplugged, completely discharges in a short period of time (maybe a few hours?)

      Is there a way to do this? I saw there may be something for Arduino, not sure if it works reliably, but I'd be willing to port my code to Arduino to have this functionality.

      posted in M5 Stick/StickC
      K
      koichirose
    • Preferred development flow

      I'm having trouble finding a nice development flow for my M5Stack Core2 with Micropython.
      The VS code extension is nice, it includes a file manager but not a REPL for debugging while coding. I can't connect via screen as the resource is busy while Visual Studio Code is open.
      Mu works and has a working REPL, but no file manager, so I'd need to manually upload files when needed.

      Ideally, I'd like to work on my local files (versioned with Git) and have the IDE upload those to the device (like Arduino IDE does, but with Micropython).

      What's your usual way of doing things?

      posted in Micropython
      K
      koichirose
    • Getting started with M5Core2

      I just got a Core2 (the AWS one) and I tinkered a little with UIflow.
      While it is nice, I'd like to use Python to code. I installed this: https://marketplace.visualstudio.com/items?itemName=curdeveryday.vscode-m5stack-mpy

      I can't figure out which functions are available and can't find any documentation online.
      For example, how to control the screen, the RGB bars etc. Where can I find a list of available APIs?
      Ctrl-clicking on "m5stack" from VS Code doesn't work. Apart from running some examples I found around, I can't code anything useful since I don't know how to call functions.

      This seems outdated: https://github.com/m5stack/UIFlow-Code/wiki/Display

      Thank you!

      posted in Micropython
      K
      koichirose