Convert Core code to Core2
-
Hi
How can I change this code so it compiles for M5Stack-Core2 AWS instead of M5Stack-Core?
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.
Thanks!
/* device_B.ino */ #include <M5Stack.h> #include <LoRaWan.h> #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, &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 < 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(); } }
Here's a couple of the first errors that occurs
In file included from C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Core2\src/M5Core2.h:78,
from C:\Users\Thomas Nilsson\Documents\Arduino\M5-ProductExampleCodes\Module\LORAWAN\Arduino\lorawan_receiver\lorawan_receiver.ino:6:
C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Core2\src/utility/M5Button.h:804:7: error: redefinition of 'class Button'
class Button : public Zone {
^~~~~~
In file included from C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Stack\src/M5Stack.h:110,
from C:\Users\Thomas Nilsson\Documents\Arduino\M5-ProductExampleCodes\Module\LORAWAN\Arduino\lorawan_receiver\lorawan_receiver.ino:5:
C:\Users\Thomas Nilsson\Documents\Arduino\libraries\M5Stack\src/utility/Button.h:18:7: note: previous definition of 'class Button'
class Button {
^~~~~~ -
Hello @Thomasx
to make it compile I only had to include <M5Core2.h> instead of <M5Stack.h>. (The error you posted suggests that you probably include both. You only need one or the other though.)
Note: If that produces working code I cannot say as I don't have the LoraWAN module.
Thanks
Felix -
Thanks!
For some reason I had to remove the M5Stack library entirely from the libs-folder, then it worked. Annoying.