For troubleshooting, you can separate radio issues from code issues by connecting the TX pin of the sender to the RX pin of the receiver with a jumper, rather than taking them to/from the RF modules.
I would have thought radio head would be smart enough to deal with random noise... I'm not familiar with it's protocol though.
A 433mhz RF ASK/OOK receiver's output pin will typically transition randomly in the absence of a signal, because of the automatic gain control - if there's no signal, it will crank the gain up until there is one
If you are using a SYN470-based receiver, you can connect a 5-10 meg resistor between VDDRF and CTH pins per datasheet, which will squelch this noise - but usually the receiving software is smart enough to ignore it and you wouldn't have to do that.
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop()
{
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
}
}
void loop()
{
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
Serial.print("Message: ");
Serial.println((char*)buf);
}
}
With buf[12] in loop() it needs to be explicitly initialized. By default, regular arrays of local scope (for example, those declared within a function) are left uninitialized. This means that none of its elements are set to any particular value; their contents are undetermined at the point the array is declared. I'm not certain if the memory location is the same each pass through the loop.