Arduino NRF24L01 Tutorial Download Page 6

Description:

So we need to include the basic SPI and the newly installed RF24 libraries and create an 
RF24 object. The two arguments here are the CSN and CE pins.

1.RF24 radio(7, 8); // CE, CSN

Next we need to create a byte array which will represent the address, or the so called pipe 
through which the two modules will communicate.

1.const byte address[6] = "00001";

We can change the value of this address to any 5 letter string and this enables to choose 
to which receiver we will talk, so in our case we will have the same address at both the 
receiver and the transmitter.

In the setup section we need to initialize the radio object and using the 
radio.openWritingPipe() function we set the address of the receiver to which we will send 
data, the 5 letter string we previously set.

1.radio.openWritingPipe(address);

On the other side, at the receiver, using the radio.setReadingPipe() function we set the 
same address and in that way we enable the communication between the two modules.

1.radio.openReadingPipe(0, address);

Then using the radio.setPALevel() function we set the Power Amplifier level, in our case I 
will set it to minimum as my modules are very close to each other.

1.radio.setPALevel(RF24_PA_MIN);

Note that if using a higher level it is recommended to use a bypass capacitors across GND
and 3.3V of the modules so that they have more stable voltage while operating.

Next we have the radio.stopListening() function which sets module as transmitter, and on 
the other side, we have the radio.startListening() function which sets the module as 
receiver.

1.// at the Transmitter
2.radio.stopListening();

1.// at the Receiver
2.radio.startListening();

In the loop section, at the transmitter, we create an array of characters to which we assign 
the message “Hello World”. Using the radio.write() function we will send that message to 
the receiver. The first argument here is the variable that we want to be sent.

1.void loop() {
2.const char text[] = "Hello World";
3.radio.write(&text, sizeof(text));
4.delay(1000);
5.}

Summary of Contents for NRF24L01

Page 1: ...le Hello World message from one Arduino to another and in the second example we will have a bi directional communication between the Arduino boards where using the Joystick at the first Arduino we wil...

Page 2: ...ch unit can communicate with up to 6 other units at the same time The power consumption of this module is just around 12mA during transmission which is even lower than a single LED The operating volta...

Page 3: ...used for setting the module in standby or active mode as well as for switching between transmit or command mode The last pin is an interrupt pin which doesn t have to be used So once we connect the NR...

Page 4: ...al 3 Example 1 Transmitter Code 4 5 by Dejan Nedelkovski www HowToMechatronics com 6 7 Library TMRh20 RF24 https github com tmrh20 RF24 8 9 include SPI h 10 include nRF24L01 h 11 include RF24 h 12 RF2...

Page 5: ...rh20 RF24 8 9 include SPI h 10 include nRF24L01 h 11 include RF24 h 12 RF24 radio 7 8 CE CSN 13 const byte address 6 00001 14 void setup 15 Serial begin 9600 16 radio begin 17 radio openReadingPipe 0...

Page 6: ...t the same address and in that way we enable the communication between the two modules 1 radio openReadingPipe 0 address Then using the radio setPALevel function we set the Power Amplifier level in ou...

Page 7: ...ments called text in which we will save the incoming data 1 void loop 2 if radio available 3 char text 32 4 radio read text sizeof text 5 Serial println text 6 7 Using the radion read function we read...

Page 8: ...Joystick Module Amazon Arduino Board Amazon Servo Motor Amazon Pushbutton Amazon LED Amazon...

Page 9: ...addresses 6 00001 00002 15 boolean buttonState 0 16 void setup 17 pinMode 12 OUTPUT 18 radio begin 19 radio openWritingPipe addresses 1 00001 20 radio openReadingPipe 1 addresses 0 00002 21 radio setP...

Page 10: ...1 00002 16 Servo myServo 17 boolean buttonState 0 18 void setup 19 pinMode button INPUT 20 myServo attach 5 21 radio begin 22 radio openWritingPipe addresses 0 00002 23 radio openReadingPipe 1 address...

Page 11: ...d the data to the receiver 1 radio stopListening 2 int potValue analogRead A0 3 int angleValue map potValue 0 1023 0 180 4 radio write angleValue sizeof angleValue On the other side using the radio st...

Page 12: ...but some talented people have written Arduino libraries that make them easy to us They all use the same pinout as shown in the following diagram which is a TOP VIEW Correction Here are details of the...

Page 13: ...o 3 3V not 5 0V although the Arduino itself may run at 5 0V and the signals will be OK The NRF24L01 IC is a 3 3V device but its I O pins are 5 V tolerant which makes it easier to interface to Arduino...

Page 14: ......

Reviews: