Sie sind auf Seite 1von 6

Arduino UNO con nRF24L01P 2.4GHz wireless transceiver

Innanzitutto occorre mettere un condensatore da 10 uF fra Vcc e GND per ridurre il rumore sull’alimentazione, fondamentale per il corretto funzionamento del dispositivo radio.

Successivamente occorre connettere la scheda Arduino UNO con il modulo nRF24L01P seguendo il seguente schema di connessione.

As nRF24L01+ transceiver module require a lot of data transfer, they will give the best performance when connected up to the hardware SPI pins on a microcontroller. The hardware SPI pins are much faster than ‘bit-banging’ the interface code using another set of pins.

Note that each Arduino Board has different SPI pins which should be connected accordingly. For Arduino boards such as the UNO/Nano V3.0 those pins are digital 13 (SCK),

12 (MISO) and 11 (MOSI).

If you have a Mega, the pins are different! You’ll want to use digital 50 (MISO), 51 (MOSI),

52 (SCK), and 53 (SS). Refer below table for quick understanding.

and 53 (SS). Refer below table for quick understanding. Hardware SPI pin config Arduino MOSI MISO

Hardware SPI pin config

Arduino

MOSI

MISO

SCK

UNO

11

12

13

NANO

11

12

13

MEGA

51

50

52

PINOUT CONNECTIONS

Arduino

UNO

nRF24L01P

GND

GND

1

VCC

3.3V

2

CE

9

3

CSN

8

4

SCK

13

5

MOSI

11

6

MISO

12

7

GND is the Ground Pin. It is usually marked by encasing the pin in a
GND
GND

is the Ground Pin. It is usually marked by encasing the pin in a square so it can be used

as a reference for identifying the other pins.

V C C supplies power for the module. This can be anywhere from 1.9 to VCC supplies power for the module. This can be anywhere from 1.9 to 3.9 volts. You can

connect it to 3.3V output from your Arduino. Remember connecting it to 5V pin will likely destroy your nRF24L01+ module!

CE (Chip Enable)

is an active-HIGH pin. When selected the nRF24L01 will either transmit

or receive, depending upon which mode it is currently in.

CSN (Chip Select Not)

is an active-LOW pin and is normally kept HIGH. When this pin goes

low, the nRF24L01 begins listening on its SPI port for data and processes it accordingly.

accepts clock pulses provided by the SPI bus Master.

SCK (Serial Clock)

MOSI (Master Out Slave In)

MISO (Master In Slave Out)

is SPI input to the nRF24L01. is SPI output from the nRF24L01.

IRQ
IRQ

is an interrupt pin that can alert the master when new data is available to process.

il modulo nRF24L01P usa SPI per comunicare, la libreria TMRH20 nRF24 semplifica la gestione del modulo. Tale libreria dipende dalla libreria SPI, quindi occorre includere anche la libreria SPI nello sketch.

#include<SPI.h>

#include<nRF24L01.h>

#include<RF24.h>

Si procede quindi ad istanziare l’oggetto radio definendo i pin CE (9) e CSN(8)

RF24 radio(9,8); // CE, CSN pins

Definiamo quindi la pipe di comunicazione

const uint64_t pipe[1] = {0xF0F0F0F0E1LL};

Configuriamo i parametri radio dell’nRF24L01P impostando l’autoACK

radio.setAutoAck(true);

radio.enableAckPayload();

radio.enableDynamicPayloads();

poi settiamo il datarate ad 1 Mbps

radio.setDataRate(RF24_1MBPS);

ed il canale di comunicazione a 100, ossia a 2.500 GHz

radio.setChannel(100);

//sets frequency to channel 100

nonchè i Retries nel caso di mancato ACK, 5 retries distanziati di (3+1)*250 usec

radio.setRetries(3,5);

Codice del trasmettitore TX con AutoACK abilitato

#include<SPI.h>

#include<nRF24L01.h>

#include<RF24.h>

int msg[1] = {1}; int rec[1] = {5}; bool stat = true; RF24 radio(9,8);

const uint64_t pipe[1] = {0xF0F0F0F0E1LL};

// CE, CSN pins

void setup()

{

}

Serial.begin(9600);

radio.begin();

delay(100);

radio.setAutoAck(true); radio.enableAckPayload(); radio.enableDynamicPayloads();

radio.setDataRate(RF24_1MBPS);

radio.setChannel(100);

radio.stopListening();

radio.openWritingPipe(pipe[0]);

radio.setRetries(3,5);

//sets frequency to channel 100

// 5 retries distanced by 4*250usec

void loop()

{

if(stat)

{

if(radio.write(msg,sizeof(msg)))

{

Serial.print( msg[0] );

Serial.println("

if(radio.isAckPayloadAvailable())

tx success");

{

radio.read(rec,sizeof(int)); Serial.print("received ACK payload is : ");

Serial.println(rec[0]);

}

else

{

stat = false; //doing this completely shuts down the transmitter if an ACK payload is not received !!

here

}

}

Serial.println("status has become false so stop ");

}

msg[0]+=3;;

if(msg[0]>=100)

{msg[0]=1;}

delay(1000);

}

Codice del ricevitore RX con AutoACK abilitato

#include<SPI.h>

#include<nRF24L01.h>

#include<RF24.h>

const uint64_t pipe[1]= {0xF0F0F0F0E1LL};

RF24 radio(9,8); int rec[1] = {2}; int red; void setup()

// CE, CSN pins

{

Serial.begin(9600);

radio.begin();

delay(100);

radio.setAutoAck(true); radio.enableAckPayload(); radio.enableDynamicPayloads();

radio.setDataRate(RF24_1MBPS);

radio.setChannel(100);

//sets frequency to channel 100

radio.openReadingPipe(1,pipe[0]);

radio.startListening();

radio.setRetries(3,5);

}

void loop()

{

if ( radio.available() ) { radio.writeAckPayload( 1, rec, sizeof(int) ); radio.read( &red,sizeof(red) );rec[0]+=2; Serial.print("integer got is : "); Serial.println(red);

}

}

Hi. Not possible with the mini board directly unless the ceramic oscillator is replaced, but for 2 AA batteries the best method is to have no voltage regulator, use a 4MHz crystal, a 4MHz bootloader and modified board files (can recompile the Optiplex boot loader), and set the fuses correctly, amongst which is setting brown out detection to 1.8 volt. It stops working at 2.7 volt as that is the brown out detection level set by default for higher clock rates. Running at 4MHz the Arduino is quite happy down to 1.8 volt, which allows more capacity to be used from the AA cells. I've had a small temperature sensor working for a couple of years on 2 AA cells with the Arduino waking once a minute. Of course processing speed is reduced but for most applications needing battery power it doesn't matter too much.