Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 21 of 21

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:	245 
Size:	130.7 KB 
ID:	1310Click image for larger version. 

Name:	2014-01-21 23.03.32.jpg 
Views:	145 
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
    130

    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
    2,127
    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
    2,127
    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
    2,127
    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.

  9. #9
    Junior Member
    Join Date
    Oct 2014
    Posts
    2
    wondering if anyone managed to get this library working on the Teensy 3.1 ?

    https://github.com/TMRh20/RF24

  10. #10
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,127
    You know about this library that supports the Nordic and many other radios?
    http://www.airspayce.com/mikem/arduino/RadioHead/

  11. #11
    Junior Member
    Join Date
    Oct 2014
    Posts
    2
    wow, nice library, thanks so much!

  12. #12
    One gotcha I noticed with the #pragma pack(1) solution is that duff2013's enormously useful LowPower_Teensy3 lib defines a structure that works only because it isn't normally packed. Ye olde 32 bit processor and addressing word alignment complement to the structure packing ying-yang. You can fix it by adding padding 3 padding bytes in LowPower_Teensy3.h thusly:

    Code:
    typedef struct sleep_block_struct {
        /* Structure wake source */
        volatile uint32_t wake_source;
        /* Structure RTC Config */
        unsigned long rtc_alarm;
        /* Module Wake Type */
        uint32_t modules;
        /* Structure GPIO Config */
        uint16_t gpio_pin;
        uint16_t gpio_mode;
        /* Structure LPTMR Config */
        uint16_t lptmr_timeout;
        /* Structure TSI Config */
        uint16_t tsi_threshold;
        uint8_t tsi_pin;
        uint8_t pad1;
        uint8_t pad2;
        uint8_t pad3;
        /* pointer to callback function */
        void (*callback)();
        sleep_block_struct() : wake_source(0), rtc_alarm(0), modules(0),
                               gpio_pin(0), gpio_mode(0), lptmr_timeout(0),
                               tsi_threshold(0), tsi_pin(0), callback(NULL) {};
    } sleep_block_t;
    Or by moving elements in the structure around to word-align. I didn't play around with that.

    This got me up and running with my nrf24 hibernating, waking, flinging packets, hibernating and whatnot.

  13. #13
    Junior Member
    Join Date
    May 2015
    Location
    Ahmedabad, Gujarat, India
    Posts
    7
    anyone got teensy 3 working with nrf24 and radiohead??

  14. #14
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,127
    On the RadioHead forum, Mike said that he's re-tested the Nordic nrf24 radios with Teensy 3.1. All OK he says.
    Is there a PCB for using this with Teensy 3?

    I don't care for the nrf24 radios - too crude. And for low volume telemetry, sub-GHz like HopeRF radio modules provide much better range and fade margins, and don't have to compete for air time with WiFi.

  15. #15
    Junior Member
    Join Date
    May 2015
    Location
    Ahmedabad, Gujarat, India
    Posts
    7
    humm Then I think its time and space problem with my teensy and nrf24 which seems to work great with pro mini's and radiohead but not teensy3.1.
    while I have checked every thing and has been doing this for 1week. Just one thing is left is to put this stuff under logic analyzer and to try the init().
    which aarduino and teensyduino does mike Use and radiohead version?
    Can I get that info...

  16. #16
    Senior Member onehorse's Avatar
    Join Date
    Apr 2014
    Posts
    567
    Is there a PCB for using this with Teensy 3?
    Yup, see here.

    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?
    With the above and its crude pcb antenna I can transmit/receive at 30 feet, or ~10 m through one dry wall.
    Last edited by onehorse; 05-26-2015 at 08:55 PM.

  17. #17
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,127
    thanks.
    You may know that the subGHz radios, at modest bit rates, yield about 100m line of sight. Inherent advantage of 433 or 868/915 (902-928) MHz vs. 2400MHz - less free space loss, less loss from path obstructions. Plus, the subGHz radios often are used with an onboard power amp for 60-100mW vs. typical 2.4GHz radios with 3-30mW. Low transmit duty cycle makes TX power consumption a moot point.

    The relatively new, low cost Long Range (LoRa) radio modules use spread spectrum rather than FM, and use unusually long spreading codes and very low bit rates (like 100's) to get their long range in non-line-of-sight conditions. Most of these are subGHz, used for suburban and rural telemetry/SCADA.

    FYI: a standard two-layer drywall (wallboard) wall, at 2.4GHz, is about 5dB of attenuation. An exterior wall, non-masonry, is much more, e.g., 15dB. Masonry is more yet. There's a NIST report on attenuation vs. frequency for common building materials. A subfloor of plywood in a residence is like 10-20dB at 2.4GHz. A commercial building may have poured concrete over a steel pan subfloor and those are bad news for RF.
    Last edited by stevech; 05-26-2015 at 08:38 PM.

  18. #18
    Senior Member onehorse's Avatar
    Join Date
    Apr 2014
    Posts
    567
    Appreciate the info on db losses. For my purposes of indoor use, small footprint and low power are the key benefits. And the longest distance in my house is ~40 feet, so it is just adequate for my usage. With the shorter wavelength, doesn't the antenna need to be muuuch longer?

    Sorry, got the units wrong, the nRF24L01+ reception is about 10 m through dry walls, or about 30 feet.
    Last edited by onehorse; 05-26-2015 at 08:55 PM.

  19. #19
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,127
    Indeed, short range!

  20. #20
    Junior Member
    Join Date
    May 2015
    Location
    Ahmedabad, Gujarat, India
    Posts
    7
    I had tested with nrf24 PA +LNA and one with crude antenna in ground open space I got it to work at 45m approx. I hit a wall But I think I could go further with that range.
    if I Just use two simple nrf24 I am just able to reach 3-5 meters and its fails multiple time when something. So I got it to work at 250kbps it seems to increase range but not too much. I have not tried to measure things with scales .. But it a good idea to do that once I setup everything again. nrf24 with PA +LNA increases range a lot.
    Next test should be like
    1 normal NRF24 and other nrf24 PA+LNA test
    and both with nrf24 PA+LNA test
    I think there is video on youtube for range test of nrf24.

  21. #21
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,127
    Opinion alert:
    As I recall the nrf24 w/o PA is about 1mW. too puny. Even w/PA it is what, 10 or 20mW?
    2.4GHz is the land of broadband and wee little low speed devices are much better off in sub-GHz.
    Last edited by stevech; 05-26-2015 at 11:03 PM.

Posting Permissions

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