[SOLVED] RadioHead / RXB8 - receiving different values than sent

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?

To test the code, connect the two Arduinos with wires (TX on one to RX on the other, and GND to GND).

I discovered that the receiver is supposed to be crucial, so I bought the RXB8 module to replace the no-name receiver.

Antennas are far more important.

I get 300 meters line of sight range with no-name 433 MHz TX and RX modules, using a balanced dipole antenna on both ends, like this:

RadioHead: RadioHead: RadioHead Packet Radio library for embedded microprocessors.
VirtualWire: VirtualWire: VirtualWire library for Arduino and other boards.

Did you have a look at the examples ?
RadioHead / examples / ask /ask_receiver / ask_receiver.pde

There is only one way to receive data:

uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);

if (driver.recv(buf, &buflen))

You have something very different.

The RadioHead is not meant for the basic Arduino boards, such as the Nano. The RadioHead uses a lot of sram memory and does not even use it. It will work, but you can not add other libraries that use a lot of sram memory.
I think your receiver is good. It has a crystal for the frequency, and I think the quality is okay.

Edit: This will not work:

  uint8_t localRadioBuf[4];
 
  if (rf_driver.recv(localRadioBuf, 4)) {

The "4" in the .recv call argument list must be the address of a variable, as the actual number of bytes received will be stored there.

I agree that VirtualWire is much preferred over RadioHead, for this simple application.

I misinterpreted the examples - I thought, you had to provide the expected length of a message to be received, which was of course wrong. Thank you, @Koepel and @jremington for bringing that to my attention! And also for the insight, that RadioHead might be too heavy for a nano project, I’ll look for a more lightweight library and also experiment with antennas.

PS is there a convention in the forum to mark threads with questions as solved? Otherwise, I'll just leave it up as it is...

You can edit the title of your original post to add [SOLVED].

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.