Herramientas de usuario

Herramientas del sitio


proyectos:monitorclima_nrf24l01

Tabla de Contenidos

Proyecto que envía una cadena de caracteres concatenando un entero de 3 digitos usando antenas NRF24L01+,

Transmisor

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
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

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
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

proyectos/monitorclima_nrf24l01.txt · Última modificación: por manuel.floresv