Navigation

    M5Stack Community

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

    JackRazors

    @JackRazors

    0
    Reputation
    2
    Posts
    841
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    JackRazors Follow

    Posts made by JackRazors

    • RE: How to run LVGL on M5Stack

      Here is what I came up with (and works with lvgl/lvgl 8.1 on my Core 2).

      #include <M5Core2.h>
      #include <Arduino.h>
      #include <lvgl.h>
      #include <Wire.h>
      #include <SPI.h>
      
      // init the tft espi
      static lv_disp_draw_buf_t draw_buf;
      static lv_disp_drv_t disp_drv;  // Descriptor of a display driver
      static lv_indev_drv_t indev_drv; // Descriptor of a touch driver
      
      M5Display *tft;
      
      static void ta_event_cb(lv_event_t * e);
      static lv_obj_t * kb;
      
      static void ta_event_cb(lv_event_t * e)
      {
          lv_event_code_t code = lv_event_get_code(e);
          lv_obj_t * ta = lv_event_get_target(e);
          if(code == LV_EVENT_CLICKED || code == LV_EVENT_FOCUSED) {
              /*Focus on the clicked text area*/
              if(kb != NULL) lv_keyboard_set_textarea(kb, ta);
          }
      
          else if(code == LV_EVENT_READY) {
              LV_LOG_USER("Ready, current text: %s", lv_textarea_get_text(ta));
          }
      }
      
      static void btnPowerOff_event(lv_event_t * event)
      {
          M5.Axp.PowerOff();
      }
      
      void tft_lv_initialization() {
        M5.begin();
      
        lv_init();
      
        static lv_color_t buf1[(LV_HOR_RES_MAX * LV_VER_RES_MAX) / 10];  // Declare a buffer for 1/10 screen siz
        static lv_color_t buf2[(LV_HOR_RES_MAX * LV_VER_RES_MAX) / 10];  // second buffer is optionnal
      
        // Initialize `disp_buf` display buffer with the buffer(s).
        lv_disp_draw_buf_init(&draw_buf, buf1, buf2, (LV_HOR_RES_MAX * LV_VER_RES_MAX) / 10);
      
        tft = &M5.Lcd;
      }
      
      // Display flushing
      void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
        uint32_t w = (area->x2 - area->x1 + 1);
        uint32_t h = (area->y2 - area->y1 + 1);
      
        tft->startWrite();
        tft->setAddrWindow(area->x1, area->y1, w, h);
        tft->pushColors((uint16_t *)&color_p->full, w * h, true);
        tft->endWrite();
      
        lv_disp_flush_ready(disp);
      }
      
      void init_disp_driver() {
        lv_disp_drv_init(&disp_drv);  // Basic initialization
      
        disp_drv.flush_cb = my_disp_flush;  // Set your driver function
        disp_drv.draw_buf = &draw_buf;      // Assign the buffer to the display
        disp_drv.hor_res = LV_HOR_RES_MAX;  // Set the horizontal resolution of the display
        disp_drv.ver_res = LV_VER_RES_MAX;  // Set the vertical resolution of the display
      
        lv_disp_drv_register(&disp_drv);                   // Finally register the driver
        lv_disp_set_bg_color(NULL, lv_color_hex3(0x000));  // Set default background color to black
      }
      
      void my_touchpad_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
      {
        TouchPoint_t pos = M5.Touch.getPressPoint();
        bool touched = ( pos.x == -1 ) ? false : true;  
      
        if(!touched) {    
          data->state = LV_INDEV_STATE_RELEASED;
        } else {
          data->state = LV_INDEV_STATE_PRESSED; 
          data->point.x = pos.x;
          data->point.y = pos.y;
        }
      }
      
      void init_touch_driver() {
        lv_disp_drv_register(&disp_drv);
      
        lv_indev_drv_init(&indev_drv);
        indev_drv.type = LV_INDEV_TYPE_POINTER;
        indev_drv.read_cb = my_touchpad_read;
        lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);  // register
      }
      
      void setup()
      {
        tft_lv_initialization();
        init_disp_driver();
        init_touch_driver();
      
        lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
        lv_obj_t * label = lv_label_create(btn1);
        lv_obj_align(btn1, LV_ALIGN_CENTER, 0, 0);
        lv_label_set_text(label, "Power Off");
        lv_obj_center(label);
        lv_obj_add_event_cb(btn1, btnPowerOff_event, LV_EVENT_CLICKED, NULL);
      }
      
      void loop()
      {
        M5.update();
        lv_task_handler();
      }
      
      posted in PROJECTS
      J
      JackRazors
    • Random restarts of the M5Stack Core 2 (code/backtrace included)

      Hi! I am building a tower light. It has the following features:

      • Battery (AXP125)
      • 3 x 12 5050 Neopixel rings
      • Enclosure that fits the M5Stack Core 2
      • OOB, it goes into config mode (AP mode) and has a web interface to 'scan' and join a WiFi network as a client
      • RESTful API for controlling the lights

      I've been having random reboots of the M5Stack Core 2 using tasks. I've stripped down 99% of my code to a simple example. Any ideas how I can figure out whats causing the restarts?

      Also, M5.BtnA.wasPressed() doesn't work either when the button is pressed.

      My code:

      #include <Arduino.h>
      #include <M5Core2.h>
      #include <Adafruit_NeoPixel.h>
      #include "logo.h"
      
      // create a couple task handles
      TaskHandle_t TaskBtnScr;
      TaskHandle_t Task2;
      
      //BtnScrController: Displays sprite output and looks for button presses
      void BtnScrController( void * pvParameters ){
        for(;;){ // emulate a void loop()
          M5.update();
          if (M5.BtnA.wasPressed()) {
            Serial.println("Button was pressed.");
            delay(1000);
          }    
        } 
      }
      
      //Task2code: blinks an LED every 700 ms
      void Task2code( void * pvParameters ){
        Serial.print("Task2 running on core ");
        Serial.println(xPortGetCoreID());
      
        for(;;){
          M5.Lcd.clearDisplay();
          M5.Lcd.setCursor(0, 0);
          M5.Lcd.setTextColor(WHITE);
          M5.Lcd.println("task 2 code");
          delay(2500);
        }
      }
      
      
      void setup() {
        M5.begin(true, true, false, true, kMBusModeOutput);
        Serial.begin(115200);
      
        // logo
        M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logo);
        delay(2500);
        M5.Lcd.clearDisplay();
        M5.Lcd.setCursor(0, 0);
        M5.Lcd.setTextColor(WHITE);
      
        //create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
        xTaskCreatePinnedToCore(
                          BtnScrController,   /* Task function. */
                          "ButtonScreenController",     /* name of task. */
                          10000,       /* Stack size of task */
                          NULL,        /* parameter of the task */
                          1,           /* priority of the task */
                          &TaskBtnScr,      /* Task handle to keep track of created task */
                          0);          /* pin task to core 0 */                  
        delay(500); 
      
          //create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
        xTaskCreatePinnedToCore(
                          Task2code,   /* Task function. */
                          "Task2",     /* name of task. */
                          10000,       /* Stack size of task */
                          NULL,        /* parameter of the task */
                          1,           /* priority of the task */
                          &Task2,      /* Task handle to keep track of created task */
                          1);          /* pin task to core 1 */
          delay(500); 
      }
      
      void loop() {
        
      }
      

      Terminal:

      
      rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
      configsip: 0, SPIWP:0xee
      clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
      mode:DIO, clock div:2
      load:0x3fff0018,len:4
      load:0x3fff001c,len:1044
      load:0x40078000,len:10124
      load:0x40080400,len:5828
      entry 0x400806a8
      [E][sd_diskio.cpp:194] sdCommand(): Card Failed! cmd: 0x00
      [E][sd_diskio.cpp:775] sdcard_mount(): f_mount failed: (3) The physical drive cannot work
      [E][sd_diskio.cpp:194] sdCommand(): Card Failed! cmd: 0x00
      Task2 running on core 1
      E (19249) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
      E (19249) task_wdt:  - IDLE0 (CPU 0)
      E (19249) task_wdt: Tasks currently running:
      E (19249) task_wdt: CPU 0: ButtonScreenCon
      E (19249) task_wdt: CPU 1: loopTask
      E (19249) task_wdt: Aborting.
      abort() was called at PC 0x400e7717 on core 0
      
      ELF file SHA256: 0000000000000000
      
      Backtrace: 0x4008a490:0x3ffbe4f0 0x4008a709:0x3ffbe510 0x400e7717:0x3ffbe530 0x40086195:0x3ffbe550 0x4000cffa:0x3ffb4600 0x40081573:0x3ffb4620 0x400d1d70:0x3ffb4640 0x400d1ee5:0x3ffb4690 0x400d15f5:0x3ffb46b0 0x400d14ca:0x3ffb46d0 0x4008b70e:0x3ffb46f0
      
      Rebooting...
      ets Jul 29 2019 12:21:46
      
      rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
      configsip: 0, SPIWP:0xee
      clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
      mode:DIO, clock div:2
      load:0x3fff0018,len:4
      load:0x3fff001c,len:1044
      load:0x40078000,len:10124
      load:0x40080400,len:5828
      entry 0x400806a8
      [E][sd_diskio.cpp:194] sdCommand(): Card Failed! cmd: 0x00
      [E][sd_diskio.cpp:775] sdcard_mount(): f_mount failed: (3) The physical drive cannot work
      [E][sd_diskio.cpp:194] sdCommand(): Card Failed! cmd: 0x00
      Task2 running on core 1
      E (19249) task_wdt: Task 
      
      posted in Core 2
      J
      JackRazors