Im using the radiohead library and 433Mhz pair to send data from a nano to an UNO:
The Tx code is:
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
//Define the object to access and cotrol the Gyro and Accelerometer (We don't use the Gyro data)
//MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
//Define packet for the direction (X axis and Y axis)
int data[2];
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup() {
Serial.begin(9600);
//mpu.initialize(); //Initialize the MPU object
// Initialize ASK Object
rf_driver.init();
}
void loop() {
delay(2000);
//With this function, the acceleration and gyro values of the axes are taken.
//If you want to control the car axis differently, you can change the axis name in the map command.
//mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
//In two-way control, the X axis (data [0]) of the MPU6050 allows the robot to move forward and backward.
//Y axis (data [0]) allows the robot to right and left turn.
data[0] = map(255, -17000, 17000, 300, 400 ); //Send aX axis data
data[1] = map(333, -17000, 17000, 100, 200); //Send aY axis data
//I hardcoded the values 255 and 333 in order to test the data format...************************
rf_driver.send((const uint8_t*)data, sizeof(data));
rf_driver.waitPacketSent();
}
while the Rx code is:
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
//Define packet for the direction (X axis and Y axis)
int data[2];
void setup() {
Serial.begin(9600);
rf_driver.init();
}
void loop() {
// Set buffer to size of expected message
int receivedData[3] = {0};
uint8_t buflen = sizeof(receivedData);
if (rf_driver.recv((uint8_t*)receivedData, &buflen)) {
//if data is not an array, use &receivedData
for (byte i = 0; i < 3; i++) {
Serial.print(receivedData[i]);
Serial.print('\t');
Serial.println(receivedData[i],HEX);
}
}
}
I understand I will have a value for data[0] and another for data[1] where the former is X-axis and the latter is y-axis. The map function takes the ax value, which occurs from -17,000 to +17,000 and maps it to a value between 300 and 400. ay is treated similarly to a value between 100-200. So in the end I will have:
data[0] = 350 maybe and
data[1] = 150 maybe.
the data is:
350 15E
150 96
0 0
350 15E
150 96
0 0
350 15E
150 96
0 0
350 15E
150 96
0 0
Isee that first its the dec value and then the hex value. Im guessing the author of that bit of code I borrowed from was using it just to ensure the received values, but what about the 0,0? Is there a usual reason to use this way of sending/receiving data for verification purposes maybe, or was it just coincidence it was used this way?
This is where I got it from:
Im guessing the hex was just because the OP in that question had actually sent/received data in different formats so maybe the responder was pointing out the hex to decimal conversion, but what about the 0,0 at the end?