0

I'm new to Arduino programming and I'm trying to get a simple 433 MHz transmitter and receiver module working on an Arduino Uno board. Unsurprisingly, it's not working as expected and I'm trying to debug the problem.

I'm using RadioHead and read in the documentation that the send() and waitPacketSent() methods return a boolean to indicate success. However, I disconnected the data wire and the send() method still returns true. As the module is no longer connected to the arduino I would have expected it to return false.

I understand that the messages are sent as unreliable datagrams, but I'm just trying to work out whether the transmitter has actually sent something. Is there some way I can do this?

The code I'm using is relatively short, so I've included it in full below, for what it's worth

#include <RH_ASK.h>
#include <RadioHead.h>

#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif

RH_ASK driver;

bool sent;

void setup()
{
#ifdef RH_HAVE_SERIAL
    Serial.begin(9600);    // Debugging only
#endif
    if (!driver.init())
#ifdef RH_HAVE_SERIAL
      Serial.println("init failed");
#else
  ;
#endif
  sent = false;
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);

    const char *msg = "hello";
    bool sendSuccess;
    bool waitSuccess;
    
    if (!sent) {
      Serial.println("sending");
      sendSuccess = driver.send((uint8_t *)msg, strlen(msg));
      if (sendSuccess) {
        Serial.println("Send completed successfully");
      } else {
        Serial.println("Send Error");
      }
      Serial.println("Waiting");
      
      waitSuccess = driver.waitPacketSent();
      if (waitSuccess) {
        Serial.println("Wait Sent Success");
      } else {
        Serial.println("Wait Sent Error");
      }
      Serial.println("Done Sending");
      sent = true;
      delay(1000);
    }
    
    if (driver.recv(buf, &buflen)) // Non-blocking
    {
      Serial.println("driver.recv");

      // Message with a good checksum received, dump it.
      driver.printBuffer("Got:", buf, buflen);
    }
}

The output on the serial monitor is as follows

22:22:30.647 -> sending

22:22:30.647 -> Send completed successfully

22:22:30.684 -> Waiting

22:22:30.753 -> Wait Sent Success

22:22:30.753 -> Done Sending

Thanks in advance!

1

There is no concept of "did the packet arrive", only "did it get sent" - and by "sent" I mean the data squirted out of the data pin for the attached module to send.

These 433MHz modules are dumb. Very dumb. You toggle the transmitter's pin high and low and the receiver sees that toggling, if it is in range, and toggles its output pin to mirror the signal.

The only way you can know if the packet arrived is if the receiver also has a transmitter and the transmitter also has a receiver. When a message arrives at the receiving node it sends a message back to the transmitting node to say "I got it". That takes a lot of work to get right, though. Especially since the original message may have arrived fine, but the acknowledgement didn't, and all sorts of horrible things can happen if you don't handle packet sequencing right.

Better is to pick a better module that does all these things for you, such as the nRF24L01+ with Auto-ACK turned on.

5
  • Thanks for the quick reply Majenko! I know I don't have any way of checking if the packets arrived. I'm just debugging at the moment and trying to check if it was sent. I would have thought that because the data pin isn't connecting the Arduino to the transmitter module then send() should fail? Have I misunderstood this? Jun 7 '20 at 21:38
  • 1
    You have misunderstood that. The Arduino neither knows not cares what is connected. Is there is nothing there the data pin still gets toggled. If a tree falls over in the forest and there's no one there to hear it the tree still fell over and the air still vibrated.
    – Majenko
    Jun 7 '20 at 21:44
  • Ah, Ok. Thanks for clearing that up. Thanks also for the recommendation. Will check out the module you mentioned above. Jun 7 '20 at 21:47
  • 1
    Get a 2nd Arduino and let it receive the data pin signal. Then you'll know the signal is being created. You cannot send and receive with one Arduino, you need a 2nd. I think there will be some data wrapped around the message that is sent; some sync bytes, some padding to ensure there are enough hi/low and low/hi transitions to ensure all data is recognizable on the receive end. The Radiohead web pages discuss it in more detail. It's basically Software Serial, but with radio modules stuck in the middle.
    – CrossRoads
    Jun 7 '20 at 21:53
  • @CrossRoads Thanks. This was the problem. I had been trying to send and receive from the same board. When I got a second arduino to act as the receiver it worked as expected. Jul 14 '20 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.