Introduction: RASPBERRY PI NRF24L01+ Mini-Hat/Proto-Board
I wanted a custom board to add nRF24L01+ radios to my Raspberry Pi's. I wanted the solution to be reasonably elegant and fit into my Pi cases without removing the capability of adding a camera and other accessories. This basically fit the requirement of the HAT, although I did not want to stick too rigidly to the specification. So, after three prototypes, this is the custom PCB I came up with.
Step 1: Schematic
I used Fritzing to sketch out a very simple schematic. The DHT11 sensor was an afterthought, an idea from a previous prototype, but they are fairly cheap and there is always room for a sensor or two. In fact the DHT22 will fit in the same place, without any modification to the hardware.
Step 2: Prototype and Custom PCB
For my third prototype I used a 60mm x 40mm protype board and cut it down to 55mm x 40mm using a Dremmel tool. I found this would fit on top of the Raspberry Pi, and also sit inside the case(with the lid off). This prompted me to complete the design and order a custom PCB. I used the usual supplier ($13 for 10 boards, with shipping at $28, this way the boards end up costing around $4 each). The Gerber files are included in this section for download.
Step 3: Parts List and Build
Description, No. Required, Source, Unit Cost, Total Unit Cost
- Custom PCB, 1 , PCBWay , $4.00 each , $4.00 (when 10 units are produced, unit price drops when more boards are ordered for production)
- DHT11 , 1 , Amazon , $1.60 each , $1.60
- 40-pin Female Header , 2 , Amazon , $0.21 each , $0.42
- 10μF electrolytic capacitor, 1 , Amazon , $0.10 , $0.10
- 220Ω , ¼ Watt resistor, 2 , Amazon , $0.05 each , $0.10
- 10KΩ, ¼ Watt resistor, 1 ,Amazon , $0.05 each , $0.05
- LED (5mm), 2 , Amazon , $0.04 each , $0.08
- nRF24L01+, 1 , Amazon , $1.09 each , $1.09
Total Cost for components in the Project $7.44
The use of prototyping board will significantly reduce the cost of this project to around $4.
This board has 10 pieces, it is a very simple assembly job. Probably the most difficult part will be cutting the 40-pin Female headers. You will need two 20-pin headers and two 4-pin headers, typically one pin in the header block is sacrificial, so cut at the 21st pin to give one 20-pin header and one 19-pin header.
Step 4: Pin Assignments
Pin Assignments for the Raspberry Pi 40 pin Header
nRF24L01+ Radio Transceiver Pin Connections
pin 1, GND connected to pin 25, GND of the Raspberry Pi
pin 2, 3V3 connected to pin 17, 3V3 of the Raspberry Pi
pin 3, CE connected to pin 15, GPIO22 of the Raspberry Pi
pin 4, CSN connected to pin 24, GPIO8 of the Raspberry Pi
pin 5, SCK connected to pin 23, SCKL of the Raspberry Pi
pin 6, MOSI connected to pin 19, MOSI of the Raspberry Pi
pin 7, MISO connected to pin 21, MISO of the Raspberry Pi
pin 8, IRQ this pin is not connected
LED Connection to the Raspberry Pi
LED1 connected to pin 33 GPIO13 of the Raspberry Pi
LED2 connected to pin 29 GPIO5 of the Raspberry Pi
DHT11 Connection to the Raspberry Pi
DHT11 data pin connected to pin 7 GPIO4 of the Raspberry Pi
Step 5: Installation of RF24 and Python Libraries
Note 1: at the present time (December 2015) it would appear that the Raspberry Pi B+ Python module will not install correctly in Raspbian Jessie using these instructions, so ensure that a Raspberry Pi B+ is running Raspbian Wheezy.
Note 2: this may no longer be the case in February 2016, however I have not tested using a B+ again. My preference for the present is to keep my B+'s as Wheezy and my Pi 2's as Jessie. The procedure for the installation of the libraries is the same for both models.
The Raspberry Pi Model 2 will install using Raspbian Jessie, using these instructions also.
The Python library will require libboost, so we will go ahead and install it first, before continuing with the nRF24 library installation.
The step wise library installation for the Raspberry Pi may be found here (TmRh20 instructions).
sudo apt-get update sudo apt-get upgrade sudo apt-get install libboost1.50-all sudo apt-get update sudo apt-get upgrade wget http://tmrh20.github.io/RF24Installer/RPi/install.sh chmod +x install.sh ./install.sh
and follow the installation prompts presented as the installation script runs.
cd rf24libs/RF24/ make sudo make install cd~
cd rf24libs/RF24/RPi/pynrf24 sudo ./setup.py build sudo ./setup.py install cd ~
cd rf24libs/RF24/examples_RPi/ make sudo make install cd ~
Do this for all of the library folders that you have installed.
Step 6: Install the DHT11 Libraries
Install the Adafruit DHT libraries.
git clone https://github.com/adafruit/Adafruit_Python_DHT.git cd Adafruit_Python_DHT sudo apt-get update sudo apt-get install build-essential python-dev sudo python setup.py install
Step 7: NRF24L01+ Antenna Modification
Diagram of the modified nRF24L01 Radio Module (2.4GHz = 12.5 cm)
The nRF24L01+ radios were modified according to this Instructable. The modifications add significant improvement to the range and reliability of the radios.
Step 8: Test the Device: NRF24L01+
Now we need to set up two Raspberry Pi units (or use one Arduino) in order to make a test using the pingpair_dyn sketch examples in the RF24 library. Set one unit as the Transmitter, set the other as the Receiver. I used two Raspberry Pi's, and also a bare-bones ATmega328 to perform this test.
Open a Terminal window on one of the Raspberry Pi's (we will set this unit as the Receiver).
enter 0 to the request, this will set this Raspberry Pi as the Receiver.
Now set up a second Raspberry Pi (or Arduino) as the Transmitter, enter 1 at the request prompt. You should see the responses fly across the screen as the units ping-pong back and forth.
The pictures and screen shots show the successful testing of two Raspberry Pi units and a bare-bones ATmega328 microcontroller.
Step 9: Test the Device: DHT11 Temperature and Humidity Sensor
Now let us use the Adafruit DHT example library to test our DHT11 (or DHT22) sensor.
cd ~ cd Adafruit_Python_DHT/examples
Now create a modified version of the simpletest.py program
change (see the screen shots for clarification)
sensor = Adafruit_DHT.DHT11 pin = 4
give the file a new name
Save file under a DIFFERENT NAME?
Now let us try the program and test our sensor.
sudo python modified_simpletest.py
Now we have temperature and humidity output from the DHT11 sensor. If you have used a DHT22 then you will need to name the sensor accordingly in the program, i.e. don't change it, by default the program references the DHT22.
Step 10: Test the Device: LED1 and LED2
Now let us see if the LED's work.
cd ~ clear
echo "5" > export
echo "out" > direction
echo "1" > value
this should turn LED1 ON
echo "0" > value
this should turn LED1 OFF
now lets look at LED2
echo "13" > export
echo "out" > direction
echo "1" > value
this should turn LED2 ON
echo "0" > value
this should turn LED2 OFF
play with the GPIO, then turn everything off
echo "5" > unexport echo "13" > unexport
All GPIO should now be turned off.
Step 11: Conclusions
This project was successful. The custom PCB along with the nRF24L01+ antennae modifications work extremely well.
The prototyping area on the board should allow a limited number of sensors to be attached, however perhaps the placement of the nRF24L01+ radio might be adjusted, so that it does not overhang this area.
Perhaps the radio headers might be turned to the right, so that the radio will face out over the USB connectors. At the moment this is not a revision I will perform.
Time to move forward with the data collection project this board was designed for.
Step 12: Use in Another Project: Raspberry Pi B+ Base Controller Unit
The Base Controller unit is a Raspberry Pi Model B+, with the Optimized nRF24 Libraries installed.
The communication software is written in Python 2.7. At this early stage it suffices that it merely collects data and publishes to a Google form.
The nRF24L01+ communication has not been added yet, the project directly grows from an earlier project. That read local temperature and humidity along with the Raspberry Pi internal temperature, and then posted this directly to a Google form.
This will probably form the basis of another Instructable once the routine has been finalized for this board.
Step 13: Update: Modify a Standard Case
I modified the standard Raspberry Pi clear case, to fit my custom PCB. I simply roughly marked out where the case needed to be cut using a permanent marker. Then I used my Dremmel tool to make the cut-outs and drill the holes. I think the photographs show this quite clearly. Basically the header hole needed to be widened to accommodate the nRF24L01+ header and the components around it. The holes were drilled to allow the tip of the led's to poke through.
Step 14: Update: Stackable 40 Pin Header
Using a stackable header brings the GPIO pins all the way through to the top of the board. This allows all of the pins to be readily accessed without resorting to soldering. Much easier and neater.