I am quite confused by the behavior I am seeing when trying to transfer data from one arduino nano to another via the RadioHead library. I am using an RXB8 module as a receiver and unfortunately don't have the name of the sender modules - I bought a no-name 433Mhz sender/receiver package in the past, and while it transferred data correctly, the range was only in the centimeters. When reading about that topic, I discovered that the receiver is supposed to be crucial, so I bought the RXB8 module to replace the no-name receiver.
For testing, I have a minimal debugging-setup, two Arduino Nanos, one as a sender and one as receiver:
Sender
#include <RH_ASK.h>
#define TRANSMITTER_PIN 12
#define UNUSED_RECEIVER_PIN A1
#define UNUSED_TT_PIN A2
#define SEND_PACKET_TIMEOUT 1000
RH_ASK rf_driver(2000, UNUSED_RECEIVER_PIN, TRANSMITTER_PIN, UNUSED_TT_PIN, false);
uint8_t dataToSend[4];
void setup() {
Serial.begin(9600);
rf_driver.init();
rf_driver.setModeTx();
}
void loop() {
dataToSend[0] = 10;
dataToSend[1] = 22;
dataToSend[2] = 30;
dataToSend[3] = 40;
radioSend();
delay(1000);
}
void radioSend() {
char dump[30];
sprintf(dump, "Sending: (%d %d %d %d)", dataToSend[0], dataToSend[1], dataToSend[2], dataToSend[3]);
Serial.println(dump);
delay(500);
rf_driver.send(dataToSend, 4);
rf_driver.waitPacketSent(SEND_PACKET_TIMEOUT);
}
Receiver
#include <RH_ASK.h>
#define RECEIVER_PIN 11
#define UNUSED_TRANSMITTER_PIN A0
#define UNUSED_TT_PIN A1
RH_ASK rf_driver(2000, RECEIVER_PIN, UNUSED_TRANSMITTER_PIN, UNUSED_TT_PIN, false);
void setup() {
Serial.begin(9600);
rf_driver.init();
rf_driver.setModeRx();
}
void loop() {
checkForEventRadio();
}
void checkForEventRadio() {
uint8_t localRadioBuf[4];
if (rf_driver.recv(localRadioBuf, 4)) {
char dump[30];
sprintf(dump, "Received: (%d %d %d %d)", localRadioBuf[0], localRadioBuf[1], localRadioBuf[2], localRadioBuf[3]);
Serial.println(dump);
}
}
The sending arduino is powered by a 9v battery which also directly powers the sender module. The Arduino's Pin 12 is of course connected to its data pin and they share a ground. The receiving Arduino's Pin 11 is connected to the data pin of the RXB8, they share a ground and the RXB8 is powered by the Arduino's 5v Pin.
Now the serial output of the sender looks like:
...
22:45:53.054 -> Sending: (10 22 30 40)
22:45:54.669 -> Sending: (10 22 30 40)
22:45:56.249 -> Sending: (10 22 30 40)
22:45:57.839 -> Sending: (10 22 30 40)
22:45:59.432 -> Sending: (10 22 30 40)
...
While the output of the receiver looks like:
...
22:45:00.404 -> Received: (42 42 56 44)
22:45:02.006 -> Received: (42 42 56 44)
22:45:03.600 -> Received: (42 42 56 44)
22:45:05.173 -> Received: (42 42 56 44)
22:45:06.765 -> Received: (42 42 56 44)
...
I am quite confused. The difference between timestamp makes sense regarding the code (a bit over 1.5 seconds between messages) but how come the received message is so differently?
Am I making an obvious mistake in the code? Or is the RXB8 maybe not compatible with RadioHead? Or do I have to use another driver from the library? In the RadioHead Documentation I can only find RX-B1 mentioned explicitly to be used with RH_ASK... maybe somebody has an idea?