Results 1 to 8 of 8

Thread: Teensy 3.1 nrf24l01+ issue

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    4

    Unhappy Teensy 3.1 nrf24l01+ issue

    Code written for communication using nrf24l01+ works if I use two arduino UNOs.
    But when I try to upload the same code for receiver to teensy3.1 using the same nrf24l01+ board, it does not work.
    All I can see on serial monitor is "tick". No data is received.
    "Sender" runs on Arduino UNO.
    SPI library is standard arduino library.

    Pin connection for arduino and teensy is the same:
    controller ->nrf
    gnd -> 1
    vcc -> 2
    9 -> 3
    10 -> 4
    11 -> 6
    12 ->7
    13 ->5
    irq(8) is not connected(black wire)
    All connections are tested.

    Arduino IDE version 1.0.5
    Teensy version 1.18rc2
    Code and photos of connections are attached.
    Click image for larger version. 

Name:	2014-01-21 23.00.11.jpg 
Views:	80 
Size:	130.7 KB 
ID:	1310Click image for larger version. 

Name:	2014-01-21 23.03.32.jpg 
Views:	47 
Size:	121.0 KB 
ID:	1311

    Code for receiver:
    Code:
    #include <SPI.h>
    #include "RF24.h"
    /********** radio ************/
    
    RF24 radio(9,10); // Set up nRF24L01 radio on SPI bus plus pins 9 & 10
    
    const uint64_t reading_pipe = 0xF0F0F0F0E2LL;
    
    void init_radio(void){
      radio.begin();
      radio.setRetries(1,0);
      radio.setCRCLength(RF24_CRC_16);
      radio.setAutoAck(false);
      radio.setPayloadSize(sizeof(int));
      radio.openReadingPipe(1,reading_pipe);
      radio.startListening();
    }
    
    #define RECEIVE_DELAY_MICROS 3300
    
    void transfer_all_payloads(void){
      int data = 0;
      radio.read(& data,sizeof(int));
      Serial.println(data);
    }
    
    void setup(void)
    { 
      Serial.begin(115200);
      init_radio();
    }
    
    void loop(void)
    {
      Serial.println("tick");
      if(radio.available()){
        transfer_all_payloads();
      }
      delay(1000);
    }
    Code for transmitter:
    Code:
    #include <SPI.h>
    #include "RF24.h"
    
    /************************* radio *****************/
    RF24 radio(9,10); // Set up nRF24L01 radio on SPI bus plus pins 9 & 10
    const uint64_t writing_pipe = 0xF0F0F0F0E2LL;
    
    void init_radio(void){
      radio.begin();
      radio.setRetries(1,0);
      radio.setAutoAck(false);
      radio.setCRCLength(RF24_CRC_16);
      radio.setPayloadSize(sizeof(int));
      radio.openWritingPipe(writing_pipe);
    }
    
    void setup(void)
    {
      Serial.begin(115200);
      init_radio();
    }
    
    void loop(void)
    { 
      for(int i=0;i<1000;i++){
        Serial.print("sending ");
        Serial.println(i);
        radio.startWrite(& i,sizeof(int));
        delay(1000);
      }
    }
    RF24 library:
    nRF24L01.h
    RF24_config.h
    RF24.cpp
    RF24.h

  2. #2
    Senior Member Wozzy's Avatar
    Join Date
    Jan 2013
    Location
    Philadelphia, Pennsylvania USA
    Posts
    102

    Try this

    Follow the instructions on DC740's thread here: nRF24L01+ working in Teensy++ 2.0 and Teensy 3.0

    This worked for me between a T3.1 and a T3.0 the on first try.
    Thanks DC740
    Last edited by Wozzy; 01-22-2014 at 08:56 PM.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    I tried to use libraries and sketches mentioned above.
    Still does not work on Teensy 3.1.
    I tried two nrf modules and two teensy 3.1, still no luck.

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    1,199
    I've long wondered... those nF24L01's are low bit rate but very low power. At 2.4GHz, and with a crude on-PCB antenna, do these things achieve range such that a pair can deal with, say, 100 ft. range and 2 or so drywall-walls in the path?

    The on-board PCB antennas can tend to be orientation sensitive due to their pattern.

    This, versus a sub-GHz radio.

  5. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Hooray! I have finally found the error!
    The problem is struct byte alignment is different on arduino and on teensy3. Consider structure
    Code:
    typedef struct{ //5 bytes
      unsigned long timestamp; //4 bytes
      uint8_t crc; //1 byte
    } snapshot_t;
    Since teensy is 32bit,
    Code:
    Serial.println(sizeof(snapshot_t));
    returns 8 on teensy.
    Arduinos are 8 bit, therefore
    Code:
    Serial.println(sizeof(snapshot_t));
    returns 5 on arduino.
    Solution:
    Code:
    #pragma pack(1)
    typedef struct{ //5 bytes
      unsigned long timestamp; //4 bytes
      uint8_t crc; //1 byte
    } snapshot_t;
    Last edited by renatyv; 02-12-2014 at 04:57 PM.

  6. #6
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    1,199
    Yes... common mistake when moving from 8 bit micros.

    #pragma pack(1), on other C compilers, often has an equivalent but different syntax.

    uint8_t long timestamp; //4 bytes
    shouldn't that be: unsigned long timestamp;
    Last edited by stevech; 02-12-2014 at 03:45 PM.

  7. #7
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    You are wright. I fixed the code in the post.

  8. #8
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    1,199
    Quote Originally Posted by renatyv View Post
    You are wright. I fixed the code in the post.
    I wonder why the compiler doesn't error on: uint8_t long timestamp;
    It seems to ignore uint8_t and use long, making this a signed rather than unsigned. That can bite you later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •