Tuesday, March 25, 2014

The nRF24L01+ Nightmare

I got these cool RF tranciever breakout boards from eBay based on the nRF24L01+ chip from Nordic Semiconductors. You can find lots of info from the web on interfacing these with Arduino boards. More info on these chips can be found here. My main intent is to use the breakouts with  Teensy 3.x development boards using the RF24 library by maniacbug. A few adjustments are necessary to make the library compile with the Teensy e.g. removal of a printf based API. I have a Teensy 3.0 and a Teensy 3.1, one is to act as a transmitter [TX] and the other, a reciever [RX]. I did not care to use the available examples like the ping pong etc. Instead i wrote my own program to remotely blink an led using the value transmitted by the TX. Following are actual events that occured to get the whole thing running properly at max power and 1 Mbps datarate.

Day 1:

nRFs interfaced to both Teensy's. All connections double checked. Program the TX. Program the RX. Nothing happens. A webhunt ensues. Lots of people facing problems with interfacing Teensy to the nRFs but nothing relevant to mine. Have i purchased defective merchandise ? Time to print sh**. Time to use my Arduino UNO board, as the RF24 library worked without any problems with the printf API. Printed the device status which turned out to be OK. I let the arduino do the TX, still nothing happened. I pull the USB programming cable out of the RX Teensy and reset it. After 5 hours of starting all this, I am jack's flashing LED. The LED connected to the RX board started to blink. So now the Arduino does all the TX and the Teensy the RX. Call it a fu**in' day.

Day 2:

So now we know that if you leave the USB cable connected to the Teensy, the nRF does not work. Well, i found in RX mode that the nRF consumes 11.5 mA as its continuously checking for data. So i used a breadboard power supply sourced from a 12V 2.5A DC adapter. Now both RX and TX are powered from the breadboad powersupply. The TX is on a separate breadboard to which power lines have been connected from the RX BB. Same code as Day 1. Program both RX and TX. Unplug the USB cable. Power OFF, Power ON. Nothing happens.....

Day 3:

Interchange the roles of the breakouts and tested on Arduino without any problem. So there has to be only one problem - the breadboard. I removed the Teensy from the TX BB and placed it on the RX BB, which is much larger as shown below. Connections complete. programming done, USB cable out. Power OFF, Power ON........LED Flashing. So, it had something to do with the breadboard, i am guessing it had a short somewhere or was not of good quality - one of those spring types. Also the SPI bus operation at high frequency and breadboards are not a good match. The circuit does operate with a few glitches now and then, but much better that what it used to do before. If you connect the USB cable to the Teensy USB port in the middle of a successful operation the transmission screws up. This does not happen with an Arduino. That is some wierd bullshit. So, a lesson learnt -  Use good quality breadboards when messing with SPI peripherals. Infact it's best to design a small PCB with proper ground plane to accomodate SPI peripherals and reduce as much web-of-wires as possible. If you read this and have any info  that could be useful, feel free to leave it in the comments section.

The final setup. The L.H.S is the RX and R.H.S the TX. Highly recommended to avoid such a setup on a breadboard with the Teensy's and nRFs and all those wires.

Following is the code for the RX and TX Teensy's. RX is on a Teensy 3.1 and TX on a 3.0.


bb.mat said...

Might consider the Radiohead library from airspayce.com. I just started with these modules and teensy 3.1 today. Seem to be working, was just about to try RF24 but sounds like you're having issues!

Venkateswarareddy Medagam said...

i need to communicate between arduino uno and teensy 3.1 using nrf24l01,i tried using many librarries but i cant able to do....can any one pls help