I have set up a 433 MHz transmitter and receiver pair on one Arduino Uno board. Using the RCSwitch library, I could successfully send and receive signals. Using the Radiohead library however, I could only send and got no reception. I am curious why and grateful for any help.
Here is the sketch. Both receiver and transmitter draw power from Arduino 5V and GND. The DATA pin of transmitter is attached to pin 12 of Arduino. The DATA pin of receiver is attached to pin 11. These appear to be "hard-coded" in the Radiohead library. My reciever has an additional chip select (CS) pin which I have wired to pin 10.
Using the serial monitor, it looks like transmitter and receiver are initialized without problem and message is sent. I have used the RCSwitch library with transmitter and receiver on the same board and that worked, (i.e. messages sent were received correctly) so I am curious why the issue with Radiohead.
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependent SPI Library
#include <SPI.h>
// Create Amplitude Shift Keying Object
RH_ASK rf_receiver;
RH_ASK rf_transmitter;
void setup()
{
// Initialize ASK Object
if (!rf_receiver.init())
Serial.println("Failed to initialize receiver.");
if (!rf_transmitter.init())
Serial.println("Failed to initialize transmitter.");
Serial.begin(9600);
digitalWrite(10, HIGH); // enable CS on some receiver devices
}
void loop()
{
const char *msg = "Hello world!";
rf_transmitter.send((uint8_t *)msg, strlen(msg));
rf_transmitter.waitPacketSent();
Serial.print("Message sent: ");
Serial.println((char*)msg);
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (rf_receiver.recv(buf, &buflen))
{
Serial.print("Message received: ");
Serial.println((char*)buf);
}
else
{
Serial.print("No message rec'd: ");
Serial.println(*&buflen);
Serial.println((char*)buf);
}
delay(1000);
}