nRF24L01+ working in Teensy++ 2.0 and Teensy 3.0

Status
Not open for further replies.

dc740

Active member
I got this module working and I wanted to share my experience so no one else has to fight with it.

I'm currently using this fork that has some extra optimizations and fixes in general:
https://github.com/TMRh20/RF24
https://github.com/TMRh20/RF24Network
This libraries work fine with Teensy 3.0, Arduino Mega and a RPi. It's also more reliable than the original versions

Getting started
NOTE: the following zip contains the original libraries, but TRMRh20 new libraries are better. Check them out too. They use the same API, and it's a direct replacement.
  1. Download View attachment RF24_teensy2_and_3.zip and unzip it in "arduino_installation_dir/libraries"
  2. Download these example projects:View attachment pingpong test.zip
  3. Modify the CE and CSN pins in the code to match your pinout.
  4. If you are using Teensy 2 or Arduino Mega, uncomment the lines that set SS as output.
  5. Upload "Pingtest" to one device
  6. Upload "Pongtest" to the other
  7. Open the serial monitor in the "Pingtest" to make sure the other device is replying to your packets


Pinout

Teensy3 -> nrf24l01
Gnd 1. GND
VCC 2. VCC
Pin 9 3. CE
Pin 10 4. CSN
Pin 13 5. SCK
Pin 11 6. MOSI
Pin 12 7. MISO
no connected 8. IRQ

Teensy++ 2.0 -> nrf24l01
Gnd 1. GND
VCC 2. VCC (*)
Pin 11 3. CE
Pin 12 4. CSN
Pin 23 7. MISO
Pin 22 6. MOSI
Pin 21 5. SCK
Pin 20 X. SS
no connected 8. IRQ

Arduino Mega -> nrf24l01
Gnd -> 1. GND
VCC -> 2. VCC (**)
48 -> 3. CE
49 -> 4. CSN
50 -> 7. MISO
51 -> 6. MOSI
52 -> 5. SCK
53 -> X. SS
no connected 8. IRQ

Teensy 3.0:
Newer versions of Teensyduino don't need any changes in the code to work. (tested on Teensyduino 1.21 test#2)
DEPRECATED:
You will get lots of errors about "printf" not working and IF_SERIAL_DEBUG not defined. Edit RF24.cpp and comment all lines that mention printf and IF_SERIAL_DEBUG (Thanks Matheus Bratfisch for the tip!). I attached a zip file with working code if you don't want to do it manually. View attachment RF24_teensy2_and_3.zip


Teensy++ 2.0 advice:
Important: set pin20 (SS) as OUTPUT

Power supply
These small modules fail if your power supply is not good enough. I have tested the following schematics on a Raspberry Pi, and two Arduino Mega (which is known to cause issues with the power supply in these modules).

Teensy++ 2.0 only:
Don't fight with voltage level conversion. Make your teensy run at 3.3V using this: http://www.pjrc.com/teensy/3volt.html
Once you do that, the 5V pin will become 3.3V, and you don't need to do anything else. Just power the nRF24L01+ from there (printed on pcb and external antennas should work out of the box).

Teensy 3.0/3.1, Raspberry pi, Arduino Mega, etc:

For the small, printed antenna, modules:
Teensy 3.0/3.1: just get your 3.3v from the teensy directly. The internal regulator is enough: https://forum.pjrc.com/threads/24343-Teensy-3-0-3-3V-pins-maximal-Current
Arduinos and RaspberryPi: Try to take 5V from Rpi or Arduino and then use an L78L33 regulator to get 3.3V. The standard 78L33 design with one .33uF and one .1uF cap works fine
L78L33.jpg

For the bigger modules with external detachable antennas:
Get 5V from Teensy, RPi or Arduino, then use a bigger regulator! This module consumes up to 115 mA, and the 78L33 and Teensy internal regulator are rated at 100mA max, so none of these will work.

What I did: I live in Argentina and I couldn't find any decent 3.3v regulator in my city so I ended up using the LM317. It's a variable voltage regulator and you can change the output with two resistances. I verified the nrf24L01+ datasheet and when the input signals come from a 5V source (like the Arduino Mega, or the RPi), then you need to supply from 2.7 to 3.3v max.
I used R1=220 and R2=330 to get 3.125 volts from the regulator, and the module worked great. The LM317 can supply up to 1.5Amps and you only need 115mA (so it will run very very cool)
lm317.png


Raspberry users:
To make the examples work (ping between teensy<->raspberry) you have to make a few small changes to the librf24-bcrm examples:
1) set CE and CSN correctly (check wich raspberry you have, verify the GPIO values)
2) Make sure you set the payload size during setup. It's commented out in the RPi examples, so you will have to change that.
3) change "RF24_PA_LOW" to "RF24_PA_MAX" to make sure it's not a signal strength related issue.
4) Enable SPI from the Advanced menu, in raspi-config

PIC users:
For the love of whatever you love the most... if you get this module working with a 5V pic (specifically 18f4550), please email me! I've used level shifters for the MISO signal with no luck. I can't manage to get SPI working. (I also tried pinguino)

32 bit users (ie: teensy 3.1):
if your code works on arduinos, but it doesn't work on Teensy, you may find this post useful:
http://forum.pjrc.com/threads/24940-Teensy-3-1-nrf24l01-issue


Open source networks
tmrh20 (recommended libs): TCP/IP, RF24Network, RF24 and RF24Mesh libraries:
http://tmrh20.github.io/
Original library:
https://github.com/maniacbug/RF24
Raspberry pi port for the original lib
https://github.com/gnulnulf/RF24
Original RF24Network
http://maniacbug.github.io/RF24Network/index.html
RF24SH
http://www.matbra.com/en/code/rf24sh-internet-das-coisas/
RadioHead
http://www.airspayce.com/mikem/arduino/RadioHead/


I hope you guys find this post useful. Good Luck!
 
Last edited:
Hi,

I'm having problems compiling the Geting Started example in you library for the Teensy 3.0. I've used the .zip files attached in you post. The error message is:

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.5 (Windows 7), Board: "Teensy 3.0"
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/bin/ld.exe: section .progmem.data loaded at [0000ce9c,0000cead] overlaps section .data loaded at [0000ce9c,0000d667]
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x14): undefined reference to `_fstat'
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text+0x12): undefined reference to `_isatty'
collect2.exe: error: ld returned 1 exit status
 
Hi,

I'm having problems compiling the Geting Started example in you library for the Teensy 3.0. I've used the .zip files attached in you post. The error message is:

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.5 (Windows 7), Board: "Teensy 3.0"
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/bin/ld.exe: section .progmem.data loaded at [0000ce9c,0000cead] overlaps section .data loaded at [0000ce9c,0000d667]
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x14): undefined reference to `_fstat'
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text+0x12): undefined reference to `_isatty'
collect2.exe: error: ld returned 1 exit status

UPDATE:
I found your problem. That one is not my library. ManiacBug is the owner. He released it a long time ago.

The Getting started example in his library uses lots of printf. Arduino for Teensy 3.0 has a bug and you can't use it (you can if you use Teensy 2.0).

Replace all references to printf by "Serial.println" OR use the "ping/pong" test project I uploaded to the original post. These are the errors I was referencing to when I wrote about teensy 3.0 problems
 
Last edited:
It depends... It says that it's free for personal projects, but what is the license for commercial usage? The license defines if the code is usable. So far it's easier to use Serial.println
 
It depends... It says that it's free for personal projects, but what is the license for commercial usage? The license defines if the code is usable. So far it's easier to use Serial.println
printf.... I'm just so accustomed to being able to simply nicely formatted output with printf, or sprintf, and all in one statement. Lots of public domain printf. I have one for the T3 that's all public domain C code and does all formatting except floats, and is small and reentrant.
 
Hello,

The ping/pong test works!! I have two Teensys 3.0 talking to one another now.
Thanks a lot for the library and the help.
 
I updated the attached library. ManiacBug added one method to RF24.h, and you can't use RF24Network without it.
 
I updated the post with some extra information on the Octal addressing used by RF24Network for a multinode setup with parent and child nodes.
 
Updated original post with a new fork that fixes a few problems with the maniacbug original implementation.
 
I'm pretty stuck and this thread seems to be the only mention of the Teensy++ 2.0. I'm unable to have anything broadcast: radio.write returns a failed result.
Teensy++ 2.0 is running at 5V with an LE33 3V3 regulator for the NRF24L01+. Oscilloscope shows a stable 3.3V (100uF capacitor didn't change radio.write results)

I'm using maniacbug's library, running GettingStarted.
printDetails shows
Code:
RF24/examples/GettingStarted/
ROLE: Pong back
*** PRESS 'T' to begin transmitting to the other node
STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	= 0xe7e7e7e7e7 0xc2c2c2c2c2
RX_ADDR_P2-5	= 0xc3 0xc4 0xc5 0xc6
TX_ADDR		 = 0xe7e7e7e7e7
RX_PW_P0-6	= 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA		 = 0x3f
EN_RXADDR	= 0x03
RF_CH		 = 0x02
RF_SETUP	= 0x0f
CONFIG		 = 0x08
DYNPD/FEATURE	= 0x00 0x00
Data Rate	 = 2MBPS
Model		 = nRF24L01+
CRC Length	 = 8 bits
PA Power	 = PA_HIGH

Sending "T" to begin transmission results with
Code:
*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK
Now sending 8307...failed.
Failed, response timed out.
Now sending 10009...failed.
Failed, response timed out.
Now sending 11710...failed.
Failed, response timed out.
Now sending 13412...failed.
Failed, response timed out.
Now sending 15114...failed.
Failed, response timed out.
Now sending 16816...failed.
Failed, response timed out.
Now sending 18518...failed.
Failed, response timed out.
Now sending 20219...failed.
Failed, response timed out.
Now sending 21920...failed.
Failed, response timed out.
Now sending 23621...failed.
Failed, response timed out.
Now sending 25322...failed.
Failed, response timed out.

Would be grateful if anyone could shed light on where I'm going wrong.
Cheers
 
Can you post a pic of your teensy? To verify that you connected the right pins. Also, did you set the SS pin as output?

I successfully used the teensy++2.0 in several ocasions. The only difference I see is that I used the oficial 3.3v regulator (MCP1825) instead of the L33. (I used the L33 in the arduino Mega without problems though)

I don't know if 3.3V level signals trigger correctly in the teensy++ 2.0. If I were you, I would try with the oficial regulator. That way you know for sure the teensy will accept the 3.3V signal from the nrf24l01 module.
 
Thanks for the quick reply, though I had already given up and turned in for the night.
I didn't think setting pin20 (SS) would make a difference and hadn't done so, I tried it this morning with the same results.
Code:
void setup(void)
{
  // Set SS pin output (pin 20)
  pinMode(20, OUTPUT);
  
  //
  // Print preamble
  //

  Serial.begin(57600);

As for the 3.3V, the LE33 is stepping down 5V just for the NRF. The Teensy is still operating at 5V.
2014-11-29 11.30.14 (Medium).jpg
 
do you have the as-really-wired slave/chip-select pin # in the class instance (constructor's info), to override the default?
 
As for the 3.3V, the LE33 is stepping down 5V just for the NRF. The Teensy is still operating at 5V.

That's what I'm talking about. For example: The pic 18f4550 does NOT work when connected to the nrf24l01 directly because it can only "interpret" signals around 0.8*5V (depending on the port) So even when the nrf module is correctly powered, the pic won't be able to talk to it because it only understands 4V. This is probably your current problem. I insist, try to run the teensy at 3.3v too.

Here is a little more detail of what's going on (they talk about a PIC, but it could also be your problem)
However, every PIC datasheet I've examined states that the minimum high input voltage (Vih) is 0.8 Vdd for inputs with Schmitt-trigger buffers. (Inputs such as SPI In and INT all utilize Schmitt-trigger buffers.) Since Vdd for the PIC is nominally 5 volts, that means that the minimum Vih is 4 volts, which is greater than the maximum output of the nRF.
https://forum.sparkfun.com/viewtopic.php?t=4904

You have to read the datasheet about the at90usb1286 to find the minimum trigger voltage. Probably other members know this (I don't).
http://www.atmel.com/devices/at90usb1286.aspx
 
Just a note for those contemplating using this wonderful little nRF24L01+ 2.4 GHz radio, I am offering a small (17.91 mm x 19.66 m) add-on board at Tindie that mounts directly onto the Teensy 3.1 for a compact remote communication solution.
 
Just a note for those contemplating using this wonderful little nRF24L01+ 2.4 GHz radio, I am offering a small (17.91 mm x 19.66 m) add-on board at Tindie that mounts directly onto the Teensy 3.1 for a compact remote communication solution.

For some reason, The pictures don't show
 
@stevech
Do you mean having the CE and CSN pins same as the code? If so, I have pin 9 as CE and pin 10 as CSN, as is specified in the code by default (figured it would be better than using different pins and having to make sure all references in the code was changed)

@dc740
Going by the specification sheets on both the AT90USB1286 and NRF24L01+, the working voltages are within range (I didn't use expected 5V/3.3V either, I measured and monitored supply voltages and used these in calculating the range of working voltages), but as it is the only difference between your setup and mine, I am thinking that it is the issue. However, I am loathe to doing this as I'm wanting to drive 5V relays and I'd have to source the regulators from outside of Oceania (scratch this, I don't think I was sane last time I tried searching for it)

Outside of running the teensy at 3.3V, are there any other differences? I'm running the teensy at 16MHz (just in case you have it different at 3.3V) and the NRF is running at 2MBPS as opposed the the 1MBPS I encounter when looking at others' experiences.

Also, my status reports all 0's, is this normal? The only one which isn't 0 is the hardcoded 7 (B111) for RX_P_NO.

I will take the plunge and use my LE33's to supply the Teensy with 3.3V order two of these voltage regulators tomorrow morning unless something obvious has been pointed out before then. I have just spent my entire day figuring out how to get eclipse to play nice with AVR and this Teensy (I'm at the point where I'm willing to write my own code from scratch to see exactly where it's going wrong).
 
Last edited:
Update:

I have gotten the MCP 3.3v regulators for the Teensy, soldered it on and cut the connection to run the whole lot at 3.3v (with a 47uF cap between vcc and gnd) then checked with multimeter to make sure everything was good. Still no success, the same results.

At the same time, I've also bought new NRF's just in case the ones sent were faulty. Again, no success. This leads me to believe that the fault lies with the code. I'm afraid this endeavour will take much more time than I had originally expected. Will update again at a later date
 
Tick, I'm still surprised you are having so many problems. It works "out of the box" with the 3.3 regulator. I even soldered the teensy++ 2.0 to the module "on the air", I didn't even use a proper PCB, nor a protoboard, just plain wires and it simply worked at first try.

I'll take a look as soon as I get home. Did you try the attachment in the first thread instead of downloading the source from the maniacbug github? I really don't know what's the problem, but you could try that, so you know you are using the same code as I did. I insist there must be some wiring problem. Can you post a picture were we can clearly see your new wiring (the simplified version, with the teensy working at 3.3v)
 
Yeah, I'm really hoping it's something stupid and simple that I messed up on.

Here's a picture of the set up
2014-12-10 18.00.02 (Large).jpg

and a diagram of it to make it easier
wiring.png

I've tried both maniacbug's and the one posted here teensy 2 and 3.
 
1) That's the very same configuration I used. No differences except for:
Pin 11 3. CE
Pin 12 4. CSN

(you used 9 and 10)... I honestly don't know about any other difference. And that shouldn't cause any problems, since CE and CSN can be changed... only MISO, MOSI and SCK should be respected:
http://www.pjrc.com/teensy/pinout.html

2) Can you remove all those leds and try just the teensy and the nrf module? Nothing else connected to it. Are you sure the other side is connected exactly like the teensy?

3) Use the demo code only, don't add anything else (software or hardware) until you get it to work.

4)
and the NRF is running at 2MBPS as opposed the the 1MBPS I encounter when looking at others' experiences.

Also, try at 1Mbps

5) you showed one side, what about the other one? Is it another teensy?

6) What is the address of each node?
 
Status
Not open for further replies.
Back
Top