Arduino Forum

Using Arduino => Microcontrollers => Topic started by: olivier_arduino on Dec 10, 2017, 03:19 pm

Title: need help porting TMRh20's RF24 library to ESP32
Post by: olivier_arduino on Dec 10, 2017, 03:19 pm
I am trying to drive a nrf24l01+ with a ESP32 so that I can connect a bunch of coin cell nrf24 nodes to the web.

I have done some research but I have found very few things about using the nrf24 with the ESP32.

To have tmrh20's RF24 library compile, I made to following change to the library:

in nRFL01.h in commented out this line:
Code: [Select]
//#define NOP           0xFF   
in RF24.cpp I replaced
Code: [Select]
*buf++ = _SPI.transfer(NOP);
Code: [Select]
*buf++ = _SPI.transfer(0xff);

in RF24_config.h

I added

Code: [Select]

    #elif defined (ESP_H)
    #include <pgmspace.h>
    #define PRIPSTR "%s"

just after line 135

Those changes allow the library to compile with no warnings.

I used the lastest ESP32 arduino core downloaded from the github repo as well as the latest version of the RF24 library from github.

I am trying to run the getting started sketch from the library with a few modif:

Code: [Select]
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20

#include <SPI.h>
#include "RF24.h"

/****************** User Config ***************************/
/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 0;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(5,18); //CE, CSN

byte addresses[][6] = {"1Node","2Node"};

// Used to control whether this node is sending or receiving
bool role = 0;

void setup() {
  Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
  if (radio.begin()) { Serial.println("OK!"); }
  else{ Serial.println("too bad!"); }
  // Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
  // Open a writing and reading pipe on each radio, with opposite addresses
  // Start the radio listening for data
                void loop(){}

I have tried playing with different SPI parameters with no success. I lowered the frequency to 2Mbs and try to set the SPI in mode 0, MSBFIRST with no success.

On the hardware side I use:
- a nrf24 adapter (the one with the power regulator and cap)
- a basic module

I tried swapping the cable, module, adapter with no success.

I power the dev board through USB and with an external beefy regulated power supply. I have a large cap (470uF) between (GND and 3.3V).

The connection are as follow:
IRQ-> unconnected

My guess is there is a problem with the SPI communication protocol. The radio.begin() always fails....

 I am running out of idea and I am fairly new with ESP32 (although I have some experience using nRF24 with atmega), Any help would be greatly appreciated!
Title: Re: need help porting TMRh20's RF24 library to ESP32
Post by: pert on Dec 10, 2017, 03:38 pm
Code: [Select]

    #elif defined (ESP_H)

I'm sure that works but I think the intent of the code would be more obvious and maybe less fragile if you used the ESP32 macro instead of the include guard macro. I would consider the former to be more of a public API and the latter to not be guaranteed stable.
Title: Re: need help porting TMRh20's RF24 library to ESP32
Post by: olivier_arduino on Dec 10, 2017, 09:15 pm
Yes indeed, I was not sure what to use. I ll try with ESP32 instead of ESP_h.
Title: Re: need help porting TMRh20's RF24 library to ESP32
Post by: olivier_arduino on Dec 11, 2017, 02:41 pm
ok, I just did not wire the SPI properly, how embarrassing...

Please have a look at the issue thread here if you are trying to work with nrf24l01 and ESP32 with arduino core: