Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Transfer Between ESP 32 And Arduino Mega #108

Open
mostafaemad10 opened this issue Mar 29, 2023 · 4 comments
Open

Data Transfer Between ESP 32 And Arduino Mega #108

mostafaemad10 opened this issue Mar 29, 2023 · 4 comments
Assignees

Comments

@mostafaemad10
Copy link

I want to transfer data from arduino mega to Esp32 when I use the example sketches ( uart_tx_data on arduino and uart_rx_data on esp32 ) the code generates wrong output ($ovf | ld) . i tried many options i found out that when the whole structure is of the same type (float/bool) it works well but when i mix between data types in the same structure it generates wrong output depends on the order of structure elements (if the first element is char , second float and third is float the output becomes the char value then all 0 but if the order is float char float the output becomes first value is right then char is right then the third element is 0 so the order matters ) also if the data type is int or double the output becomes totally wrong values.

I need to send data from the arduino mega to the Esp32 in a structure with mixed data types if possible and i need in these types double ( 8 bytes ).
Is this possible and if you could help with any tips or recommendation.
Thanks in advance.

@PowerBroker2 PowerBroker2 self-assigned this Mar 29, 2023
@PowerBroker2
Copy link
Owner

This is really interesting - the examples should work for arduino <-> ESP32. How about revamping the examples so that you're transferring dummy data that matches what you want to transfer in your project? We can debug further from there for your specific case.

@proasnet
Copy link

proasnet commented Jul 19, 2024

Dear @PowerBroker2, I am trying the same. ESP32 as reader and Atmel as sender. Compilling both, ok.
But ESP32 cyclic restarting.

ESP32 code

#include "SerialTransfer.h"
#include <HardwareSerial.h>

#define RX 14
#define TX 12

SerialTransfer myTransfer;

struct __attribute__((packed)) STRUCT {
  char z;
  float y;
} testStruct;


void setup() {
  Serial2.begin( 115200 , SERIAL_8N1 , RX , TX , false );
}

void loop() {
    if(myTransfer.available())
  {
    myTransfer.rxObj(testStruct);
    Serial.print(testStruct.z);
    Serial.println(testStruct.y);
  }
}

Atmel code

#include "SerialTransfer.h"

SerialTransfer myTransfer;

struct __attribute__((packed)) STRUCT {
  char z;
  float y;
} testStruct;


void setup() {
  Serial1.begin( 115200 );
  testStruct.z = '$';
  testStruct.y = 4.5;
}

void loop() {
  myTransfer.sendDatum(testStruct);
  delay(500);
}

esp console, repeating cyclic

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_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:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400d1738  PS      : 0x00060830  A0      : 0x800d1418  A1      : 0x3ffb2240  
A2      : 0x3ffc1c58  A3      : 0xffffffff  A4      : 0x0000000e  A5      : 0x0000000e  
A6      : 0x0000000c  A7      : 0x00000078  A8      : 0x800d2084  A9      : 0x3ffb21d0  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x3ffb7d48  A15     : 0x00000000  SAR     : 0x0000000e  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x40085f6c  LEND    : 0x40085f77  LCOUNT  : 0xffffffff  


Backtrace: 0x400d1735:0x3ffb2240 0x400d1415:0x3ffb2270 0x400d26b1:0x3ffb2290




ELF file SHA256: 9ca8412a952522ad

Rebooting...

@nomakewan
Copy link

nomakewan commented Sep 22, 2024

Dear @PowerBroker2, I am trying the same. ESP32 as reader and Atmel as sender. Compilling both, ok. But ESP32 cyclic restarting.

You forgot to initialize your SerialTransfer object on the Serial port you intend to use for inter-device communication. So for the ESP32, after the line in setup() Serial2.begin( 115200 , SERIAL_8N1 , RX , TX , false ); you would put myTransfer.begin(Serial2, false);. Then on the Atmel, after the line in setup() Serial1.begin( 115200 ); you would put myTransfer.begin(Serial1, false);.

For OP, I know it's been over a year since you posted and you never responded to the maintainer, but ESP32<->Mega with arbitrary data types works perfectly fine. You simply use a struct to store the variables and their types, and make sure that that struct's definition is identical on both ends. As long as both ends have the same definition for the struct, it will be correctly interpreted on the receiving end. A project I work on has two Mega 2560s and an ESP32 and they all use SerialTransfer to send multiple arbitrary data types. Works a treat!

@proasnet
Copy link

Thank you @PowerBroker2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants