Ciao ho tutti, sto usando 2 moduli NRF24 2.4GHz per scambiarmi dei semplici messaggi a distanza tra un Arudino Uno ed un Nano (Usavo i moduli ESP ma son impazzito, troppi problemi ed ho acqquistato questi).
Facendo riferimento alle ultime librerie RF24 (GitHub - nRF24/RF24: OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux Devices) ho provato a testare il file esempio GettingStarted per capire se i moduli sono funzionanti ma ottengo "Now sending-failed-Failed, response timed out."
Comunque nonostante cio' delle vecchie librerie NRF24 permettevano di vedere dei codici esadecimali della radio nel caso fosse attiva e testando i 2 moduli ho avuto il riscontro atteso, se invece scollegavo un pin i codici stampati a monitor andavano tutti a 0!
Detto questo ora sto cercando di farle comunicare anche inviando un semplice numero o testo ma non riesco usando questa libreria e questo codice!
Qualcuno che ha la stessa radio potrebbe dirmi se e' il codice la parte sbagliata?
RX
/* YourDuinoStarter Example: Simple nRF24L01 Receive
- WHAT IT DOES: Receives simple fixed data with nRF24L01 radio
- SEE the comments after "//" on each line below
Start with radios about 4 feet apart.
- SEE the comments after "//" on each line below
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
Uses the RF24 Library by TMRH2o here:
https://github.com/TMRh20/RF24
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 7
4 - CSN to Arduino pin 8
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
V1.02 02/06/2016
*/
//ARDUINO UNO
/*-----( Import needed libraries )-----*/
#include <SPI.h> // Comes with Arduino IDE
#include "RF24.h" // Download and Install (See above)
/*-----( Declare Constants and Pin Numbers )-----*/
//None yet
/*-----( Declare objects )-----*/
// (Create an instance of a radio, specifying the CE and CS pins. )
RF24 myRadio (7, 8); // "myRadio" is the identifier you will use in following methods
/*-----( Declare Variables )-----*/
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataReceived; // Data that will be received from the transmitter
void setup() /****** SETUP: RUNS ONCE ******/
{
// Use the serial Monitor (Symbol on far right). Set speed to 115200 (Bottom Right)
Serial.begin(115200);
delay(1000);
Serial.println(F("RF24/Simple Receive data Test"));
Serial.println(F("Questions: PiDay314"));
myRadio.begin(); // Start up the physical nRF24L01 Radio
myRadio.setChannel(108); // Above most Wifi Channels
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
myRadio.setPALevel(RF24_PA_MIN);
// myRadio.setPALevel(RF24_PA_MAX); // Uncomment for more power
myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
myRadio.startListening();
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
if ( myRadio.available()) // Check for incoming data from transmitter
{
while (myRadio.available()) // While there is data ready
{
myRadio.read( &dataReceived, sizeof(dataReceived) ); // Get the data payload (You must have defined that already!)
}
// DO something with the data, like print it
Serial.print("Data received = ");
Serial.println(dataReceived);
} //END Radio available
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//None yet
//*********( THE END )***********
TX
/* YourDuinoStarter Example: Simple nRF24L01 Transmit
- WHAT IT DOES: Transmits simple fixed data with nRF24L01 radio
- SEE the comments after "//" on each line below
Start with radios about 4 feet apart.
- SEE the comments after "//" on each line below
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
Uses the RF24 Library by TMRH2o here:
https://github.com/TMRh20/RF24
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 7
4 - CSN to Arduino pin 8
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
V1.02 02/06/2016
*/
//ARDUINO NANO
/*-----( Import needed libraries )-----*/
#include <SPI.h> // Comes with Arduino IDE
#include "RF24.h" // Download and Install (See above)
/*-----( Declare Constants and Pin Numbers )-----*/
//None yet
/*-----( Declare objects )-----*/
// (Create an instance of a radio, specifying the CE and CS pins. )
RF24 myRadio (7, 8); // "myRadio" is the identifier you will use in following methods
/*-----( Declare Variables )-----*/
byte addresses[][6] = {"1Node"}; // Create address for 1 pipe.
int dataTransmitted; // Data that will be Transmitted from the transmitter
void setup() /****** SETUP: RUNS ONCE ******/
{
// Use the serial Monitor (Symbol on far right). Set speed to 115200 (Bottom Right)
Serial.begin(115200);
delay(1000);
Serial.println(F("RF24/Simple Transmit data Test"));
Serial.println(F("Questions: Pipidayday314"));
dataTransmitted = 100; // Arbitrary known data to transmit. Change it to test...
myRadio.begin(); // Start up the physical nRF24L01 Radio
myRadio.setChannel(108); // Above most Wifi Channels
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
myRadio.setPALevel(RF24_PA_MIN);
// myRadio.setPALevel(RF24_PA_MAX); // Uncomment for more power
myRadio.openWritingPipe( addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now)
delay(1000);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
myRadio.write( &dataTransmitted, sizeof(dataTransmitted) ); // Transmit the data
Serial.print(F("Data Transmitted = "));
Serial.print(dataTransmitted);
Serial.println(F(" No Acknowledge expected"));
dataTransmitted = dataTransmitted + 1; // Send different data next time
delay(500);
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//*********( THE END )***********
Monitor TX
RF24/Simple Transmit data Test
Questions: Pipidayday314
Data Transmitted = 100 No Acknowledge expected
Data Transmitted = 101 No Acknowledge expected
Data Transmitted = 102 No Acknowledge expected
...
Monitor RX
RF24/Simple Receive data Test
Questions: PiDRF24/Simple Receive data Test
Questions: PiDay314
Dimenticavo, i pin li ho collegati nel modo giusto, controllati e ricontrollati!