Author Topic: nRF24L01+ / RF24 not working?  (Read 49639 times)

PeterF

  • Hero Member
  • *****
  • Posts: 877
nRF24L01+ / RF24 not working?
« on: September 18, 2013, 04:22:12 am »
Hi,

Was trying to get the nRF24L01+ module working as I already have a couple of these running around the house as part of a weather station project. I already had the RF24 and MiRF libraries installed, so I used the modified  RF24 radio(53,52); command as specified in the wiki, but it didn't work. So I thought it must be my libaries, so I moved them out as to use the versions included with DigiX. No change. When I compiled the RF24\GettingStared example without any changes, I got this error :

Code: [Select]
In file included from GettingStarted.pde:22:
/printf.h: In function 'void printf_begin()':
printf.h:30: error: 'fdevopen' was not declared in this scope

I comment out the offending line, as I thought it's probably something that worked with the AVRs, but not with the SAM architecture. No problem, just means the printf calls in the main code  won't output anything. At least it would compile.

I then get the following errors from the RF24 library?!? I *did* change the hardware\arduino folder to hardware\digix, but the error was occuring before I made that change.

Code: [Select]
Arduino: 1.5.3 (Windows NT (unknown)), Board: "Digistump DigiX"

D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::csn(int)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:24: error: 'SPI_CLOCK_DIV4' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::print_status(uint8_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:188: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:193: error: 'printf_P' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::print_observe_tx(uint8_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:204: error: 'printf_P' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::print_byte_register(const char*, uint8_t, uint8_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:212: error: 'printf_P' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::print_address_register(const char*, uint8_t, uint8_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:223: error: 'printf_P' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::printDetails()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:325: error: 'printf_P' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::begin()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:382: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::startListening()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:398: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::powerDown()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:429: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::powerUp()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:436: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'bool RF24::write(const void*, uint8_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:468: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::startWrite(const void*, uint8_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:510: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'bool RF24::available(uint8_t*)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:552: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'bool RF24::read(void*, uint8_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:585: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::whatHappened(bool&, bool&, bool&)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:594: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::openReadingPipe(uint8_t, uint64_t)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:652: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::enableDynamicPayloads()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:671: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::enableAckPayload()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:700: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::setAutoAck(uint8_t, bool)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:770: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:774: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::setPALevel(rf24_pa_dbm_e)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:799: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'rf24_pa_dbm_e RF24::getPALevel()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:832: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'bool RF24::setDataRate(rf24_datarate_e)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:864: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'rf24_datarate_e RF24::getDataRate()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:907: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::setCRCLength(rf24_crclength_e)':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:933: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'rf24_crclength_e RF24::getCRCLength()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:957: error: '_BV' was not declared in this scope
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp: In member function 'void RF24::disableCRC()':
D:\Dropbox\Programming\Ardiuno\hardware\digix\sam\libraries\RF24\RF24.cpp:974: error: '_BV' was not declared in this scope

Any ideas? I'm happy to poke, prod and break things :)

Cheers,
Peter

PeterF

  • Hero Member
  • *****
  • Posts: 877
Re: nRF24L01+ / RF24 not working?
« Reply #1 on: September 18, 2013, 05:51:29 am »
Just an info update.

After a hour or so more of searching, changing code, and getting it to work, I came across a forum post of someone else who had also just got it working, and posted his changes. It appears to be an Arduino Due related issue, so naturally impacts on the DigiX.

For his github changelog that details the changes: https://github.com/mcrosson/RF24/commit/ac05a9d8f755dcc7ff12b7e08021f62c0b5f3543

I made one extra change, to printf so I can continue to use it with the AVR microcontrollers:


changed line 30 of printf.h from
Code: [Select]
fdevopen( &serial_putc, 0 );
to

Code: [Select]
#if !defined(__arm__)
fdevopen( &serial_putc, 0 );
#endif

There are no compile errors, but printf and associated functions seem to not work at all, so printDetails() isn't working, and scanner example isn't working.

The nRF24L01+ *did* receive some data whilst I was stomping around in the RF24 code, but seems to have stopped receiving now. Will post when I know more.

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: nRF24L01+ / RF24 not working?
« Reply #2 on: September 27, 2013, 03:15:31 pm »
print.h issue fixed in newest release http://digistump.com/wiki/digix/tutorials/software

PeterF

  • Hero Member
  • *****
  • Posts: 877
Re: nRF24L01+ / RF24 not working?
« Reply #3 on: September 29, 2013, 03:55:07 am »

Tried the latest v04 of the DigiX addons, no change on the scanner example compiling - still doesn't work on Arduino 1.5.4. Thanks for renaming the hardware folder thou :).


Finally had some time and awake enough brain cells to debug this gremlin further, and finally got it working (although not a neatly as I'd like). Anyway, here are the changes..


Add the following to rf24_config.h (could add to any of the rf24 files - .h, .cpp, but rf24_config.h contains all the environment specific 'fidely' bits):


Code: [Select]
//ARM specific code


#ifdef __arm__
#define SPI_CLOCK_DIV4 21
#define _BV(bit) (1 << (bit))
#define printf_P printf
#endif


Add to sketch in question or printf.h:


Code: [Select]
  int kkprintf(char *format, ...)  {
  int n;
  char buf[128];
  va_list args;
  va_start (args, format);
  vsnprintf(buf, sizeof(buf), format, args); // does not overrun sizeof(buf) including null terminator
  va_end (args);
  // the below assumes that the new data will fit into the I/O buffer. If not, Serial may drop it.
  // if Serial had a get free buffer count, we could delay and retry. Such does exist at the device class level, but not at this level.
  n = strlen(buf) - Serial.print(buf); // move chars to I/O buffer, freeing up local buf
  return n; // number of chars unable to fit in device I/O buffer (see bug notice above)
}


Make sure you change calls to printf() in sketch code to kkprintf().


I now how a DigiX board running the scanner example using the on-board nRF24L01+ module, telling me my wifi router is using the high end of the low end of the 2.4Ghz spectrum :)




digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: nRF24L01+ / RF24 not working?
« Reply #4 on: September 29, 2013, 07:01:49 pm »
Erg - I guess I really totally shipped the wrong version of this library - I had a version all pre=modified that I meant to ship - I'll look for it and make sure it makes the next release - but basically I did what @pferrick did.

Girl_Luvzer_Mac

  • Newbie
  • *
  • Posts: 2
Re: nRF24L01+ / RF24 not working?
« Reply #5 on: December 11, 2013, 12:29:35 pm »
Not to dig up an old thread, but I've managed to get the "Getting Started" RF example to compile and upload using your changes, pfeerick… Though I still don't see anything in the serial monitor. The sketch works fine when uploaded to my UNO and I get output in the serial monitor when the baud rate is set to 57600.


I'd also like to add that I was able to use the AnalogReadSerial sketch and see the expected output in the serial monitor.

It's probably just a n00b mistake on my part; any ideas or suggestions? I think I'm missing some sort of connect between the kkprintf/printf/serial.println, perhaps.
« Last Edit: December 11, 2013, 12:34:17 pm by Girl_Luvzer_Mac »

Girl_Luvzer_Mac

  • Newbie
  • *
  • Posts: 2
Re: nRF24L01+ / RF24 not working?
« Reply #6 on: December 12, 2013, 06:12:07 pm »
I got this working for the 'Getting Started' sketch; it seems like radio.printDetails() which prints out the configuration of the module, was overfilling the buffer and hanging/muting anything that could follow. Once I commented out that line, everything else worked without a hitch according to the changes you'd made.

Many many thanks, without your work I wouldn't have been able to get this far!

mtnbikeray

  • Newbie
  • *
  • Posts: 5
Re: nRF24L01+ / RF24 not working?
« Reply #7 on: December 25, 2013, 07:26:49 pm »
Using the current libraries should the RF24 examples work ?  I'm having a hard time just gettting the 'getting started' example doing anything.  I think it's related to printf not working.  Even after removing the printf's it stilll doesn't work.
I have a few sketches that worked on my uno, but not on the digiX.

any insight ?

Ray

dag

  • Newbie
  • *
  • Posts: 1
Re: nRF24L01+ / RF24 not working?
« Reply #8 on: December 26, 2013, 04:14:03 pm »
I think I got the scanner working, using the hacks described above. I also needed to add the digix serial hack:

Code: [Select]
  //DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
  while(!Serial.available()){
    Serial.println("Enter any key to begin");
    delay(1000);

But - I don't know what I am seeing now :D

What das this mean?

Code: [Select]

5646778643377874368a85565aac857646355698813678ba83110000000000032200000000000000000000000000000000000000000000000000000000000044

31123377541257976445534211488a56656666765243565543000004000221221000000000000000000000000000000000000000000000000000000000000053

6688b87866537b9ddaa97b9786900c89777599b850016874510000040220000000000000000000000000000000000000000000000000000000000000000000a9

Any suggestions?

Adalricus

  • Newbie
  • *
  • Posts: 8
Re: nRF24L01+ / RF24 not working?
« Reply #9 on: December 28, 2013, 06:10:37 am »
Any fix for this yet? cause even after i made the changes it still doesnt work. I am able to upload the sketch but nothing in the serial monitor.

wallerron

  • Newbie
  • *
  • Posts: 1
Re: nRF24L01+ / RF24 not working?
« Reply #10 on: December 28, 2013, 08:58:31 pm »
I can't even compile any of the Examples.
This is from the RF24/Scanner example

(Sorry about the major textblock here)


[suspicious]Arduino:1.5.5 (Windows 7), Board: "Digistump DigiX"

[SNIPPED IT]

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
[/suspicious]


EDIT:
This is just another example of not reading this Thread thoroughly. My apologies. ^^
« Last Edit: December 29, 2013, 02:30:30 pm by wallerron »

Adalricus

  • Newbie
  • *
  • Posts: 8
Re: nRF24L01+ / RF24 not working?
« Reply #11 on: December 29, 2013, 05:43:49 am »
I think I got the scanner working, using the hacks described above. I also needed to add the digix serial hack:

Code: [Select]
  //DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
  while(!Serial.available()){
    Serial.println("Enter any key to begin");
    delay(1000);

But - I don't know what I am seeing now :D

What das this mean?

Code: [Select]

5646778643377874368a85565aac857646355698813678ba83110000000000032200000000000000000000000000000000000000000000000000000000000044

31123377541257976445534211488a56656666765243565543000004000221221000000000000000000000000000000000000000000000000000000000000053

6688b87866537b9ddaa97b9786900c89777599b850016874510000040220000000000000000000000000000000000000000000000000000000000000000000a9

Any suggestions?

I guess you should change your baud rate in the monitor  57600 I think it was. 

Can you upload your library/sketch cause I can't get it working right?

Adalricus

  • Newbie
  • *
  • Posts: 8
Re: nRF24L01+ / RF24 not working?
« Reply #12 on: January 02, 2014, 02:04:58 am »
Erik do you maybe have a working library for me. I would love to get it working.

Dennis

  • Newbie
  • *
  • Posts: 15
Re: nRF24L01+ / RF24 not working?
« Reply #13 on: January 02, 2014, 04:59:10 pm »
@dag:

I just got the scanner running.

The Scanner should provide an output that looks similar to:
Code: [Select]

RF24/examples/scanner/

00000000000000001111111111111111222222222222222233333333333333334444444444444444555555555555555566666666666666667777777777777777

0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

01233210012332100123321001233210000000000000000000000121012333310123320000000000000000000000000000000000000000000000000000000010

01233210012332100123321001233210000000000000000000000011013333210233320000000000000000000000000000000000000000000000000000000010

01233210012332100123321001233210000000000000000000000022023444321233420000000000000000000000000000000000000000000000000000000010

00233320012333100123331002333100000000000000000000000021012333310123300000000000000000000000000000000000000000000000000000000021

01233221122332100123321001232210000000000000000000000021013333210133320000000000000000000000000000000000000000000000000000000010

0123321001233210012332100123221000000000000000000000002212333321123332000000000000000000000000000000000000000000000000000000001

00110000111100001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

You can see that I have interferences on channels 0, 1, 3 and 4. If I now remove the WIFI power jumper and put my DigiX into its anti-static bag, than I got lines with all zeros, i.e. no interferences. (The anti-static bag works like a Faraday cage.)
« Last Edit: January 02, 2014, 05:02:41 pm by Dennis »

pkourany

  • Newbie
  • *
  • Posts: 25
Re: nRF24L01+ / RF24 not working?
« Reply #14 on: January 03, 2014, 08:10:35 pm »
I have the latest DigiX add-on.  I loaded the GettingStarted sketch (IDE v1.5.5 beta) and fixed the code as per this thread and it ran, printing the "Now sending.." message with the time.  However, the only output I got is "failed".  The message was not received by the second node (when I had a second terminal connected to it, nothing printed past the setup message).  So basically, it did not work.

So I either a) Have bad nrf24L01 devices or b) the sketch and the libraries are NOT ready for prime time or c) I am missing something.

Any advice?

:)
« Last Edit: January 03, 2014, 08:34:43 pm by pkourany »