I have used send and receive data (a String) from a Node MCU ESP8266 to another Node MCU ESP8266 through the RF module using the RadioHead library.
After uploading the sample code of the RadioHead lib to the Node MCU ESP8266 and opening the SerialMonitor, I can not see the log, i.e the RadioHead lib does not work with ESP8266.
But I see in the document of RadioHead lib, it supported ESP8266 already.
Can anyone help?
This is the code for Arduino (Transmitter)
// ask_transmitter.ino
// For Arduino Uno
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endifRH_ASK driver;
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),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
}void loop()
{
const char *msg = "hello";driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
This is the code for ESP8266
// ask_receiver
// For ESP8266, rxpin = D3 (GPIO0)#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endifRH_ASK driver(2000, 0); // ESP8266 or ESP32: do not use pin 11 or 2
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),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
}void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;// Message with a good checksum received, dump it.
driver.printBuffer("Got:", buf, buflen);
}
}