Hi all,
So, I'm building a remote controlled robot using an Arduino Uno R4 Minima as a remote and an Arduino Nano for the "on-board" things. The two is communicating using nRF24L01 modules.
I want to send 3 datapieces to the robot in one package (the values of 3 potmeter on the remote to control different servos on the robot). I make a struct and send it via radio like so:
struct Data_Package {
int pot0;
int pot1;
int pot2;
};
Data_Package data;
/////////////////// setting up radio blah blah //////////////////////
int potValue0= analogRead(A0);
int angleValue0 = map(potValue0, 0, 1023, 65, 0);
int potValue1 = analogRead(A1);
int angleValue1 = map(potValue1, 0, 1023, 0, 45);
int potValue2 = analogRead(A2);
int angleValue2 = map(potValue2, 0, 1023, 0, 100);
data.pot0 = angleValue0;
data.pot1 = angleValue1;
data.pot2 = angleValue2;
radio.write(&data, sizeof(Data_Package));
On the receiving device I use this code to get the data out of the message:
void loop() {
if (radio.available()) {
// Read data package
radio.read(&data, sizeof(Data_Package));
}
However, when I check the content of the struct it seems to be misaligned?
When I transform the data back into the same struct I get the following data:
Sent vs Received
pot0 ---------> pot0
pot1 ---------> 0
pot2 ---------> pot1
The third value of the struct is missing entirely and the second value takes up the place of the third. The data I'm sending is pure int, always between the given limits. When I check the contents of the struct on the sending device it seems to be fine. The error is either on the receiving end or lost in the void.
Any idea how to get my missing data? My robot is pretty sad without it.