-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Anhadimos codigo del emisor y receptor
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <SPI.h> | ||
#include <nRF24L01.h> | ||
#include <RF24.h> | ||
|
||
//Declaremos los pines CE y el CSN | ||
#define CE_PIN 9 | ||
#define CSN_PIN 10 | ||
|
||
//Variable con la dirección del canal por donde se va a transmitir | ||
byte direccion[5] ={'c','a','n','a','l'}; | ||
|
||
//creamos el objeto radio (NRF24L01) | ||
RF24 radio(CE_PIN, CSN_PIN); | ||
|
||
//vector con los datos a enviar | ||
float datos[3]; | ||
|
||
void setup() | ||
{ | ||
//inicializamos el NRF24L01 | ||
radio.begin(); | ||
//inicializamos el puerto serie | ||
Serial.begin(9600); | ||
|
||
//Abrimos un canal de escritura | ||
radio.openWritingPipe(direccion); | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
//cargamos los datos en la variable datos[] | ||
datos[0]=analogRead(0)* (5.0 / 1023.0);; | ||
datos[1]=millis(); | ||
datos[2]=2.3; | ||
//enviamos los datos | ||
bool ok = radio.write(datos, sizeof(datos)); | ||
//reportamos por el puerto serial los datos enviados | ||
if(ok) | ||
{ | ||
Serial.print("Datos enviados: "); | ||
Serial.print(datos[0]); | ||
Serial.print(" , "); | ||
Serial.print(datos[1]); | ||
Serial.print(" , "); | ||
Serial.println(datos[2]); | ||
} | ||
else | ||
{ | ||
Serial.println("no se ha podido enviar"); | ||
} | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <SPI.h> | ||
#include <nRF24L01.h> | ||
#include <RF24.h> | ||
|
||
//Declaremos los pines CE y el CSN | ||
#define CE_PIN 9 | ||
#define CSN_PIN 10 | ||
|
||
//Variable con la dirección del canal que se va a leer | ||
byte direccion[5] ={'c','a','n','a','l'}; | ||
|
||
//creamos el objeto radio (NRF24L01) | ||
RF24 radio(CE_PIN, CSN_PIN); | ||
|
||
//vector para los datos recibidos | ||
float datos[3]; | ||
|
||
void setup() | ||
{ | ||
//inicializamos el NRF24L01 | ||
radio.begin(); | ||
//inicializamos el puerto serie | ||
Serial.begin(9600); | ||
|
||
//Abrimos el canal de Lectura | ||
radio.openReadingPipe(1, direccion); | ||
|
||
//empezamos a escuchar por el canal | ||
radio.startListening(); | ||
|
||
} | ||
|
||
void loop() { | ||
uint8_t numero_canal; | ||
//if ( radio.available(&numero_canal) ) | ||
if ( radio.available() ) | ||
{ | ||
//Leemos los datos y los guardamos en la variable datos[] | ||
radio.read(datos,sizeof(datos)); | ||
|
||
//reportamos por el puerto serial los datos recibidos | ||
Serial.print("Dato0= " ); | ||
Serial.print(datos[0]); | ||
Serial.print(" V, "); | ||
Serial.print("Dato1= " ); | ||
Serial.print(datos[1]); | ||
Serial.print(" ms, "); | ||
Serial.print("Dato2= " ); | ||
Serial.println(datos[2]); | ||
} | ||
else | ||
{ | ||
Serial.println("No hay datos de radio disponibles"); | ||
} | ||
delay(1000); | ||
} | ||
|