Using two Nanos and two RF24L01, I'm sending ultrasonic data from a JSN-SR04T. The Tx serial monitor shows the correct numbers but the Rx shows the asscii value. I have tried several suggestions listed here without success. This is my first attempt to program and surprised I have made it this far. First the Rx then the Tx.
// Measure distance
unsigned int distance_cm = sonar.ping_cm();
// Print distance to Serial Monitor
Serial.print("Distance: ");
distance_cm = (distance_cm)*.393701;
Serial.print(distance_cm);
Serial.println(" inches");
// Prepare data to transmit
int data[sizeof(distance_cm)];
memcpy(data, &distance_cm, sizeof(distance_cm));
// Transmit the data
if (radio.write(data, sizeof(data))) {
}
delay(500); // Wait for 1/2 second
}
``
void loop() {
// Measure distance
unsigned int distance_cm = sonar.ping_cm();
// Print distance to Serial Monitor
Serial.print("Distance: ");
distance_cm = (distance_cm)*.393701;
Serial.print(distance_cm);
Serial.println(" inches");
// Prepare data to transmit
int data[sizeof(distance_cm)];
memcpy(data, &distance_cm, sizeof(distance_cm));
// Transmit the data
if (radio.write(data, sizeof(data))) {
}
delay(500); // Wait for 1/2 second
}
// Prepare data to transmit
int data = distance_cm;
//memcpy(data, &distance_cm, sizeof(distance_cm));
// Transmit the data
if (radio.write(data, sizeof(data))) {
Check the difference between serial.print and serial.write. You should find: "Serial.print() converts data to a human-readable format (ASCII), while Serial.write() sends raw byte data directly. Using Serial.write() can be faster for transmitting binary data, but the output won't be easily readable in the Serial Monitor."