<?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[Convert Core code to Core2]]></title><description><![CDATA[<p dir="auto">Hi</p>
<p dir="auto">How can I change this code so it compiles for M5Stack-Core2 AWS instead of M5Stack-Core?</p>
<p dir="auto">I tried replacing the M5Stack.h include with M5Core2.h but it didn't help. I also tried adding the latter to the first, but it also didn't help.</p>
<p dir="auto">Thanks!</p>
<pre><code>/*
    device_B.ino
*/

#include &lt;M5Stack.h&gt;
#include &lt;LoRaWan.h&gt;

#define SerialUSB Serial

unsigned char buffer[128] = {
    0,
};
uint8_t flag_test_868 = 0;

void key_scan(void *arg)
{
  while (1)
  {
    onReceive();
    // lora.loraDebug();
  }
  vTaskDelete(NULL);
}

void setup(void)
{
  M5.begin(true,true,true,false);
  SerialUSB.begin(9600);
  lora.init();
  delay(2000); // must delay for lorawan power on
  lora.initP2PMode(868, SF12, BW500, 8, 8, 20);
  M5.Lcd.setTextFont(2);
  M5.Lcd.println("Device B");
  M5.Lcd.setTextColor(BLUE);
  int core = xPortGetCoreID();
  // M5.Lcd.println(core);
  xTaskCreatePinnedToCore(key_scan, "key_scan", 2048, NULL, 0, NULL, 0);
}

void loop(void)
{
  // lora.loraDebug();
  if (M5.BtnA.wasPressed())
  {
    M5.Lcd.setCursor(0, 20);
    M5.Lcd.fillRect(0, 20, 320, 215, BLACK);
  }
  if (M5.BtnB.wasPressed()) //send data (433MHz)
  {
    flag_test_868 = 0;
    M5.Lcd.setTextColor(BLUE);
    init_433();
    send_data();
    delay(300);
    Serial2.print("AT+TEST=RXLRPKT\r\n");
        M5.Lcd.println("433M Init and Send \"Hello World\"...");
  }
  if (M5.BtnC.wasPressed()) //send data (868MHz)
  {
    flag_test_868 = 1;
    M5.Lcd.setTextColor(YELLOW);
    init_868();
    send_data();
    delay(300);
    Serial2.print("AT+TEST=RXLRPKT\r\n");
    M5.Lcd.println("868M Init and Send \"Hello World\"...");
  }
  M5.update();
}

void init_433()
{
  lora.initP2PMode(433, SF12, BW500, 8, 8, 20);
}

void init_868()
{
  lora.initP2PMode(868, SF12, BW500, 8, 8, 20);
}

void send_data()
{
  lora.transferPacketP2PMode("hello world");
}

void onReceive()
{
  short length = 0;
  short rssi = 0;

  memset(buffer, 0, 128);
  length = lora.receivePacketP2PMode(buffer, 128, &amp;rssi, 1);

  if (length)
  {
    SerialUSB.print("Length is: ");
    SerialUSB.println(length);
    SerialUSB.print("RSSI is: ");
    SerialUSB.println(rssi);
    SerialUSB.print("Data is: ");
    if (flag_test_868)
    {
      M5.Lcd.print("868M Recv:  ");
    }
    else
    {
      M5.Lcd.print("433M Recv:  ");
    }
    for (unsigned char i = 0; i &lt; length; i++)
    {
      SerialUSB.print((char)buffer[i]);
      M5.Lcd.print((char)buffer[i]);
      //   SerialUSB.print("0x");
      //   SerialUSB.print(buffer[i], HEX);
      //   SerialUSB.print(" ");
    }
    SerialUSB.println();
    M5.Lcd.println();
  }
}
</code></pre>
<p dir="auto">Here's a couple of the first errors that occurs</p>
<blockquote>
<p dir="auto">In file included from C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Core2\src/M5Core2.h:78,<br />
from C:\Users\Thomas Nilsson\Documents\Arduino\M5-ProductExampleCodes\Module\LORAWAN\Arduino\lorawan_receiver\lorawan_receiver.ino:6:<br />
C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Core2\src/utility/M5Button.h:804:7: error: redefinition of 'class Button'<br />
class Button : public Zone {<br />
^~~~~~<br />
In file included from C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Stack\src/M5Stack.h:110,<br />
from C:\Users\Thomas Nilsson\Documents\Arduino\M5-ProductExampleCodes\Module\LORAWAN\Arduino\lorawan_receiver\lorawan_receiver.ino:5:<br />
C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Stack\src/utility/Button.h:18:7: note: previous definition of 'class Button'<br />
class Button {<br />
^~~~~~</p>
</blockquote>
]]></description><link>https://community.m5stack.com/topic/3966/convert-core-code-to-core2</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 11:55:23 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/3966.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Jan 2022 20:17:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Convert Core code to Core2 on Fri, 28 Jan 2022 14:17:29 GMT]]></title><description><![CDATA[<p dir="auto">Thanks!</p>
<p dir="auto">For some reason I had to remove the M5Stack library entirely from the libs-folder, then it worked. Annoying.</p>
]]></description><link>https://community.m5stack.com/post/16375</link><guid isPermaLink="true">https://community.m5stack.com/post/16375</guid><dc:creator><![CDATA[Thomasx]]></dc:creator><pubDate>Fri, 28 Jan 2022 14:17:29 GMT</pubDate></item><item><title><![CDATA[Reply to Convert Core code to Core2 on Fri, 28 Jan 2022 08:07:24 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/thomasx" aria-label="Profile: Thomasx">@<bdi>Thomasx</bdi></a></p>
<p dir="auto">to make it compile I only had to include &lt;M5Core2.h&gt; instead of &lt;M5Stack.h&gt;. (The error you posted suggests that you probably include both. You only need one or the other though.)</p>
<p dir="auto">Note: If that produces working code I cannot say as I don't have the LoraWAN module.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/16363</link><guid isPermaLink="true">https://community.m5stack.com/post/16363</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Fri, 28 Jan 2022 08:07:24 GMT</pubDate></item></channel></rss>