Go Down

Topic: Teensy + nrf24L01 (Read 2369 times) previous topic - next topic


May 22, 2010, 03:48 am Last Edit: May 22, 2010, 04:24 am by tehpopa Reason: 1
To give you an idea of what I'm working with, here's my hardware list.

Teensy 2.0++ Configured using Teensyduino
nRF24L01 Transceiver (http://www.sparkfun.com/commerce/product_info.php?products_id=691)
nRF24L01 Fob (http://www.sparkfun.com/commerce/product_info.php?products_id=9377)

Presently I've got the teensy coded to do a number of small automation tasks that send keystrokes over the USB connection to the PC. This works great so far. My next task was going to be adding a wireless component to trigger these same automated tasks manually from remote.

The problem is that I can't get the code I found at(http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1245058973) to run on a Teensy. After noobing through a bit, I seem to gather it requires an SPI library for the Teensy 2.0++. I've searched for one, but my google-fu seems to be weak. I stole the spi.h file out of the ethernet example for the teensy, but that obviously doesn't work. I don't need someone to do all this for me, I just need a push in the right direction. If that direction is "It's way beyond the level you're at now," I am cool with that.

Oh, I should explain specifically what doesn't work on the Teensy. When I upload the sketch to the Teensy, it crashes in void setup() when setting the rxaddr. If I unplug the teensy and plug it back in, it will load up the last sketch.


May 22, 2010, 05:48 am Last Edit: May 22, 2010, 05:49 am by TBAr Reason: 1
I am not experienced with SPI, but I do have a Teensy++. From that I know that some of the pin assignments on the T++ (AT90USB1286 chip) are different than the standard ATmega168/328 pins.

Specifically, the SPI pins on the ATmega168/328 are hardware pins PB3, PB4 and PB5, referred to in the Arduino context as digital pins 11, 12 and 13. See http://www.arduino.cc/en/Hacking/PinMapping168 for both the Atmel and Arduino notations.

The SPI pins on the T++/AT90USB1286 are PB2, PB3 and PB1, referred to as digital 22, 23 and 21. See http://www.pjrc.com/teensy/pinout.html. Use the top 2 pictures to correlate the Atmel notation to the Teensyduino notation.

I might be duplicating what you found in the spi.h file you mentioned. Just trying to help.


May 22, 2010, 07:34 am Last Edit: May 22, 2010, 08:19 am by tehpopa Reason: 1
I could swear I've tried that before, but likely I had some pin swapped. I'm pulling data down. You, sir, are a godsend. See you guys in a few hours once I get my breakout board for my WizNet board done :)

Scratch that. I've reloaded the board a few times now and I'm back to having issues. It gets through load now though. It never did that before. However now it is slow. It is running really slow for some reason.

Here's my code and serial output.

Code: [Select]
#include <Spi.h>
#include <mirf.h>
#include <nRF24L01.h>

byte data_array[4];

const int ledPin =  14;

int ledState = LOW;  

void setup() {
 Mirf.csnPin = 7;
 Mirf.cePin = 8;
 byte rx_addr[5] = {0xE7, 0xE7, 0xE7, 0xE7, 0xE7};
 Serial.println("Getting close...");
 Serial.println("rx_addr set...");
 Mirf.configRegister(RF_SETUP, 0x07); //Air data rate 1Mbit, 0dBm, Setup LNA
 Mirf.configRegister(EN_AA, 0x00); //Disable auto-acknowledge
 Mirf.payload = 4;
 Mirf.channel = 2;
 Serial.println("mirf has been configed...");
 pinMode(ledPin, OUTPUT);

void loop(){
 if (ledState == LOW)
     ledState = HIGH;
     ledState = LOW;
 digitalWrite(ledPin, ledState);
 if (Mirf.dataReady()){
   Serial.print("Data! : ");
   switch (data_array[0]) {
     case 0x1D: Serial.println("UP"); break;
     case 0x1E: Serial.println("DOWN"); break;
     case 0x17: Serial.println("LEFT"); break;
     case 0x1B: Serial.println("RIGHT"); break;
     case 0x0F: Serial.println("CENTER"); break;
     default: break;

Code: [Select]

Getting close...
rx_addr set...
mirf has been configed...
Data! : 8

During this process the LED starts to blink(slowly) so it's going through loop... just not processing anything as 'dataReady'


Odd. It kept spitting "Data! : XX" where XX was a random hex value. Popped it back onto the Ard(using the same wiring) and it works perfectly.

Go Up