Hello, I'm building a custom fixed-wing UAV and I couldn't figure out data transmission with structs. When I try to send something that changes over time or not, I just get a corrupted value on the other side. Any ideas to fix that issue? I've tried so many things but none of them worked.
Corrupted lines looks like this in serial monitor:
data 168 235 24 249 68 0 0
data 31 0 0 0 255 168 235
Thanks.`
Sender Code
#include <SoftwareSerial.h>
#define RXD PC11
#define TXD PC10
SoftwareSerial HC12B = SoftwareSerial(RXD, TXD);
struct RxStruct {
uint8_t aileronData;
uint8_t elevatorData;
uint8_t throttle;
uint8_t yaw;
uint8_t flaps;
bool navLights;
bool uavTxE;
byte padding[10];
};
RxStruct rxData ={ 168, 235, 24, 249, 68, 0, 0 }; // fixed values for testing purposes
void setup() {
HC12B.begin(9600);
}
void loop() {
HC12B.write((byte *)&rxData, rxDataLen);
delay(10);
}
Reciever
#define RXD2 16 //Connect to the TX pin of the HC-12
#define TXD2 17 //Connect to the RX pin of the HC-12
#define HC12E Serial2
struct RxStruct {
uint8_t aileronData;
uint8_t elevatorData;
uint8_t throttle;
uint8_t yaw;
uint8_t flaps;
bool navLights;
bool uavTxE;
byte padding[10];
};
RxStruct rxData;
void setup() {
HC12E.begin(9600);
Serial.begin(115200);
delay(4000);
Serial.println("serial active");
}
void loop() {
if (HC12E.available()) {
HC12E.readBytes((byte*)&rxData, sizeof(rxData));
Serial.print("data ");
Serial.print(' ');
Serial.print(rxData.aileronData);
Serial.print(' ');
Serial.print(rxData.elevatorData);
Serial.print(' ');
Serial.print(rxData.throttle);
Serial.print(' ');
Serial.print(rxData.yaw);
Serial.print(' ');
Serial.print(rxData.flaps);
Serial.print(' ');
Serial.print(rxData.navLights);
Serial.print(' ');
Serial.println(rxData.uavTxE);
}
}