<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[(SOLVED) M5Atom crash when I add M5.dis.drawpix()]]></title><description><![CDATA[<p dir="auto">Hi All,<br />
I'm working on a espnow communication between two M5Atom<br />
the communication works well but when I try to use the built in led, the tx atom crash...</p>
<p dir="auto">this is the working sender sketch (without led):</p>
<pre><code>
#include "M5Atom.h"
#include &lt;Preferences.h&gt;
Preferences preferences;

#include "Leddar.h"

#include &lt;Arduino.h&gt;
#include &lt;esp_now.h&gt;
#include &lt;esp_wifi.h&gt;

byte FilmPlate = 20;
short ToRs232;
short cm1;
short cm2;
short cm3;
short cm4;
short cm5;
short cm6;
short cm7;
short cm8;

float Amp1;
float Amp2;
float Amp3;
float Amp4;
float Amp5;
float Amp6;
float Amp7;
float Amp8;

///////////////// OTA /////////////////////
#include &lt;WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;WebServer.h&gt;
#include &lt;ESPmDNS.h&gt;
#include &lt;Update.h&gt;
const char *host = "xx";
const char *ssid = "xxx";
const char *password = "xxxxx";
WebServer server(80);
///////////////// fine OTA /////////////////////

bool StatoRX;
bool StatoPAIR = 0;

// //////////////////// ESPNOW /////////////////////////
// Set your Board and Server ID
#define BOARD_ID 1
#define MAX_CHANNEL 13  // for North America // 13 in Europe
uint8_t serverAddress[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

typedef struct struct_message2 {
  uint8_t msgType;
  uint8_t id;
  uint8_t macAddr[6];
  short ToRs232;
  bool unit;
} struct_message2;

typedef struct struct_message {
  uint8_t msgType;
  uint8_t id;
  // uint8_t macAddr[6];
  byte FilmPlate;
  short ToRs232;
  short cm1;
  short cm2;
  short cm3;
  short cm4;
  short cm5;
  short cm6;
  short cm7;
  short cm8;
  float Amp1;
  float Amp2;
  float Amp3;
  float Amp4;
  float Amp5;
  float Amp6;
  float Amp7;
  float Amp8;
} struct_message;

typedef struct struct_pairing {  // new structure for pairing
  uint8_t msgType;
  uint8_t id;
  uint8_t macAddr[6];
  uint8_t channel;
} struct_pairing;

//Create 2 struct_message
struct_message myData;   // data to send
struct_message2 inData;  // data received
struct_pairing pairingData;

enum PairingStatus { NOT_PAIRED,
                     PAIR_REQUEST,
                     PAIR_REQUESTED,
                     PAIR_PAIRED,
};
PairingStatus pairingStatus = NOT_PAIRED;

enum MessageType { PAIRING,
                   DATA,
};
MessageType messageType;

#ifdef SAVE_CHANNEL
int lastChannel;
#endif
int channel = 1;


unsigned long currentMillis = millis();
unsigned long previousMillis = 0;  // Stores last time temperature was published
const long interval = 10000;       // Interval at which to publish sensor readings
unsigned long start;               // used to measure Pairing time
unsigned int readingId = 0;

void addPeer(const uint8_t *mac_addr, uint8_t chan) {
  esp_now_peer_info_t peer;
  ESP_ERROR_CHECK(esp_wifi_set_channel(chan, WIFI_SECOND_CHAN_NONE));
  esp_now_del_peer(mac_addr);
  memset(&amp;peer, 0, sizeof(esp_now_peer_info_t));
  peer.channel = chan;
  peer.encrypt = false;
  memcpy(peer.peer_addr, mac_addr, sizeof(uint8_t[6]));
  if (esp_now_add_peer(&amp;peer) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
  }
  memcpy(serverAddress, mac_addr, sizeof(uint8_t[6]));
}

void printMAC(const uint8_t *mac_addr) {
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.print(macStr);
}

void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  // Serial.print("\r\nLast Packet Send Status:\t");
  // Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
  if (status == ESP_NOW_SEND_SUCCESS) {
    // M5.dis.drawpix(0, 0x00ff00);  // GREEN  绿色
    StatoRX = 1;
  } else {
    // M5.dis.drawpix(0, 0xff0000);  // RED  红色
    StatoRX = 0;
  }
}

void OnDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
  // Serial.print("Packet received from: ");
  // printMAC(mac_addr);
  // Serial.println();
  // Serial.print("data size = ");
  // Serial.println(sizeof(incomingData));
  uint8_t type = incomingData[0];
  switch (type) {
    case DATA:  // we received data from server
      memcpy(&amp;inData, incomingData, sizeof(inData));

      ToRs232 = inData.ToRs232;

      break;

    case PAIRING:  // we received pairing data from server
      memcpy(&amp;pairingData, incomingData, sizeof(pairingData));
      if (pairingData.id == 0) {  // the message comes from server
        printMAC(mac_addr);
        Serial.print("Pairing done for ");
        printMAC(pairingData.macAddr);
        Serial.print(" on channel ");
        Serial.print(pairingData.channel);  // channel used by the server
        Serial.print(" in ");
        Serial.print(millis() - start);
        Serial.println("ms");
        addPeer(pairingData.macAddr, pairingData.channel);  // add the server  to the peer list
#ifdef SAVE_CHANNEL
        preferences.begin("C-Wheels", false);
        preferences.putUInt("lastChannel", lastChannel);  // Store to the Preferences
        preferences.end();                                // Close the Preferences

#endif
        pairingStatus = PAIR_PAIRED;  // set the pairing status
      }
      break;
  }
}

PairingStatus autoPairing() {
  switch (pairingStatus) {
    case PAIR_REQUEST:
      Serial.print("Pairing request on channel ");
      Serial.println(channel);
      StatoPAIR = 1;  // probabilmente si puo togliere
      // set WiFi channel
      ESP_ERROR_CHECK(esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE));
      if (esp_now_init() != ESP_OK) {
        Serial.println("Error initializing ESP-NOW");
      }

      // set callback routines
      esp_now_register_send_cb(OnDataSent);
      esp_now_register_recv_cb(OnDataRecv);

      // set pairing data to send to the server
      pairingData.msgType = PAIRING;
      pairingData.id = BOARD_ID;
      pairingData.channel = channel;

      // add peer and send request
      addPeer(serverAddress, channel);
      esp_now_send(serverAddress, (uint8_t *)&amp;pairingData, sizeof(pairingData));
      previousMillis = millis();
      pairingStatus = PAIR_REQUESTED;
      break;

    case PAIR_REQUESTED:
      // time out to allow receiving response from server
      currentMillis = millis();
      if (currentMillis - previousMillis &gt; 250) {
        previousMillis = currentMillis;
        // time out expired,  try next channel
        channel++;
        if (channel &gt; MAX_CHANNEL) {
          channel = 1;
        }
        pairingStatus = PAIR_REQUEST;
      }
      break;

    case PAIR_PAIRED:
      StatoPAIR = 0;
      // nothing to do here
      break;
  }
  return pairingStatus;
}
///////////////////////////FINE ESPNOW///////////////

byte CH;
byte CHold;

bool aggiornaCH;

LeddarVu8 Leddar(115200, 1);  //Baudrate = 115200 Modbus slave ID = 01

void setup() {

  M5.begin();
  // M5.begin(false, false, true);
  Serial.begin(115200);
  Serial1.begin(9600, SERIAL_8N1, 22, 19);  // atom RS232 MOD
  delay(1000);

  M5.update();

  Serial.println();
  Serial.print("Client Board MAC Address:  ");
  Serial.println(WiFi.macAddress());
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  start = millis();

#ifdef SAVE_CHANNEL
  preferences.begin("xxxx", false);
  lastChannel = preferences.getUInt("lastChannel", 0);
  preferences.end();

  Serial.println(lastChannel);
  if (lastChannel &gt;= 1 &amp;&amp; lastChannel &lt;= MAX_CHANNEL) {
    channel = lastChannel;
  }
  Serial.println(channel);
#endif
  pairingStatus = PAIR_REQUEST;

  Serial1.begin(9600, SERIAL_8N1, 23, 19);  //ATOM_RS232

  Leddar.init();

  // M5.dis.drawpix(0, 0xfff000);  // YELLOW 黄色

  M5.update();
}

void loop() {

  char result = Leddar.getDetections();

  if (result &gt;= 0) {
    for (int i = 0; i &lt; Leddar.NbDet; i++) {
      if (Leddar.Detections[i].Segment + 1 == 1) {
        myData.cm1 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp1 = Leddar.Detections[i].Amplitude;
      }
      if (Leddar.Detections[i].Segment + 1 == 2) {
        myData.cm2 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp2 = Leddar.Detections[i].Amplitude;
      }
      if (Leddar.Detections[i].Segment + 1 == 3) {
        myData.cm3 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp3 = Leddar.Detections[i].Amplitude;
      }
      if (Leddar.Detections[i].Segment + 1 == 4) {
        myData.cm4 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp4 = Leddar.Detections[i].Amplitude;

        if (M5.Btn.isPressed()) {  //ATOM
          FilmPlate = 100 - Leddar.Detections[i].Distance;
        }
      }
      if (Leddar.Detections[i].Segment + 1 == 5) {
        myData.cm5 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp5 = Leddar.Detections[i].Amplitude;
      }
      if (Leddar.Detections[i].Segment + 1 == 6) {
        myData.cm6 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp6 = Leddar.Detections[i].Amplitude;
      }
      if (Leddar.Detections[i].Segment + 1 == 7) {
        myData.cm7 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp7 = Leddar.Detections[i].Amplitude;
      }
      if (Leddar.Detections[i].Segment + 1 == 8) {
        myData.cm8 = Leddar.Detections[i].Distance + FilmPlate;
        myData.Amp8 = Leddar.Detections[i].Amplitude;
      }

      myData.FilmPlate = FilmPlate;

    }
  } else {
    Serial.print("Vu8 Error: ");
    Serial.print((int)result);
    Serial.print("\n");
  }

  sendData();

  // if (pairingStatus == PAIR_PAIRED) {
  //   M5.dis.drawpix(0, 0x00ff00);
  // }

  //   M5.dis.drawpix(0, 0x00ff00);
  M5.update();

  delay(20);  //crasha se la tolgo
}

void sendData() {
  if (autoPairing() == PAIR_PAIRED) {
    myData.msgType = DATA;
    myData.id = BOARD_ID;
    esp_err_t result = esp_now_send(serverAddress, (uint8_t *)&amp;myData, sizeof(myData));
  }
}
</code></pre>
<p dir="auto">when I add  M5.dis.drawpix(0, 0x00ff00);</p>
<p dir="auto">the Atom crash..</p>
<p dir="auto">this is the serial monitor output:</p>
<pre><code>M5At
Client Board MAC Address:  D8:A0:1D:5C:95:0C
Pairing request on channel 1

assert failed: xQueueSemaphoreTake queue.c:1545 (( pxQueue ))


Backtrace: 0x400843b1:0x3ffb2060 0x4008cb85:0x3ffb2080 0x400921c5:0x3ffb20a0 0x4008db95:0x3ffb21d0 0x400d4430:0x3ffb2210 0x400d311f:0x3ffb2240 0x400d3459:0x3ffb2270 0x400dc9ed:0x3ffb2290




ELF file SHA256: 75047b7540bb511b

Rebooting...
</code></pre>
<p dir="auto">any idea??</p>
]]></description><link>https://community.m5stack.com/topic/7261/solved-m5atom-crash-when-i-add-m5-dis-drawpix</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 11:33:46 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7261.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 03 Feb 2025 22:55:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to (SOLVED) M5Atom crash when I add M5.dis.drawpix() on Tue, 04 Feb 2025 11:04:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a> You are right!!!</p>
<p dir="auto">I thought that calling M5.begin() without any parameters would set all parameters to true..</p>
<p dir="auto">thanks a lot</p>
]]></description><link>https://community.m5stack.com/post/28097</link><guid isPermaLink="true">https://community.m5stack.com/post/28097</guid><dc:creator><![CDATA[cepics]]></dc:creator><pubDate>Tue, 04 Feb 2025 11:04:00 GMT</pubDate></item><item><title><![CDATA[Reply to (SOLVED) M5Atom crash when I add M5.dis.drawpix() on Tue, 04 Feb 2025 06:19:24 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/cepics" aria-label="Profile: cepics">@<bdi>cepics</bdi></a></p>
<p dir="auto">I think you need to enable LED use first by setting the last parameter in <code>M5.begin()</code> to <code>true</code>. See <a href="https://github.com/m5stack/M5Atom/blob/master/src/M5Atom.h#L75" target="_blank" rel="noopener noreferrer nofollow ugc">here</a>.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/28093</link><guid isPermaLink="true">https://community.m5stack.com/post/28093</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Tue, 04 Feb 2025 06:19:24 GMT</pubDate></item></channel></rss>