Tuesday, December 30, 2014

Sending Messages Between Two nRF24L01 Modules using Arduino

During the holidays I took some 2.4 GHz radio modules from our lab to my home far away from Colombo and tried different interesting things. One of the things I tried is establishing simple communication between nRF24L01 modules to transfer some data. For this purpose I connected two of those radio modules to two Arduino Uno boards and programmed using Arduino IDE and RF24 library. In this article, I'm writing down the steps I followed for my own future reference. I tried it in a machine which runs Ubuntu 12.04 LTS.

(1) Download https://github.com/maniacbug/RF24 library as a ZIP file. Extract it and renamed as 'RF24maniacbug'. Create a directory called 'libraries' in your sketchbook directory inside home directory ('~/sketchbook') only if it wasn't available initially and copy the 'RF24maniacbug' directory into it. I forked the same github project of maniacbug into my account for my future use which is available at https://github.com/asanka-code/RF24.

(2) Wire up the nRF24L01 module with Arduino board according to the pin connection details in the following table. We need two setups like this to be able to send and receive data.
nRF24L01 Pin Arduino Uno Pin
GND GND
VCC 3V3
CE 9
CSN 10
SCK 13
MOSI 11
MISO 12

(3) Plug the two Arduino boards to the computer using two USB cables. Start two instances of Arduino IDE and select the two serial devices separately in two IDE instances. In my machine, one Arduino board was detected as /dev/ttyACM1 and the other as /dev/ttyACM2.

(4) From each Arduino IDE, move in the following menu path and open the GettingStarted example program (sketch). Compile and upload that program into both Arduino boards.

File->Examples->RF24maniacbug->GettingStarted

(5) Open serial monitor in both Arduino IDEs and set the baud rate to 57600. It should show some status information of the nRF24L01 module connectivity to the Arduino board.
Output of serial monitors of sender and receiver
Now, type 'T' on the serial monitor of a one device and then it will start sending messages to the other device. The other device should start sending responses for each message from the first. If we need to change the roles of sender and receiver, type R in the current sender and it will switch to the listening mode. Then type T in the initial receivers serial monitor to make it the sender.

References:
[1] http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/
[2] https://github.com/maniacbug/RF24
[3] I forked maniacbug's RF24 repository for my future use which is available at
https://github.com/asanka-code/RF24

No comments:

Post a Comment