Proyecto que envĂa una cadena de caracteres concatenando un entero de 3 digitos usando antenas NRF24L01+,
====== Transmisor ======
{{ :proyectos:arduino-nrf24l01_bb.png?600 |}}
#include
#include
#include
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001"; //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.
int data=10;
void setup() {
Serial.begin(9600); // Use this for debugging
Serial.println("Iniciando");
radio.begin(); //Starting the Wireless communication
radio.openWritingPipe(address); //Setting the address where we will send the data
radio.setPALevel(RF24_PA_MIN); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
radio.stopListening(); //This sets the module as transmitter
delay(5000);
}
String converter(uint8_t num){
String str;
char buf[3];
str=String(num);
str.toCharArray(buf,3);
return ((char *) buf);
}
void loop()
{
byte bufb[32];
data=data+1;
char cdata[3];
String snum;
String tempo="Datos ";
tempo.getBytes(bufb,tempo.length()+1);
snum=String(data);
snum.toCharArray(cdata,sizeof(cdata));
bufb[sizeof(tempo)+0]=cdata[0];
bufb[sizeof(tempo)+1]=cdata[1];
bufb[sizeof(tempo)+2]=cdata[2];
radio.write(&bufb, sizeof(bufb)); //Sending the message to receiver
Serial.print("Enviando:");
Serial.print(tempo);
Serial.print(cdata[0]);Serial.print(cdata[1]);Serial.println(cdata[2]);
delay(1000);
}
====== Receptor ======
{{ :proyectos:arduino-nrf24l01_bb.png?600 |}}
#include
#include
#include
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600); // Use this for debugging
Serial.println("Iniciando");
radio.begin();
radio.openReadingPipe(0, address); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MIN); //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.startListening(); //This sets the module as receiver
}
void loop()
{
if (radio.available()) //Looking for the data.
{
char text[32] = ""; //Saving the incoming data
radio.read(&text, sizeof(text)); //Reading the data
Serial.println(text);
}
delay(5);
}
===== Referencias =====
* https://create.arduino.cc/projecthub/muhammad-aqib/nrf24l01-interfacing-with-arduino-wireless-communication-0c13d4