Arduino Pro Mini with nRf24L01 Module Programming Query

Hi, I was wondering if someone would be kind enough to give me some advice I am relatively new to Arduino/programming, and am currently working on a small home project, to build up my knowledge to measure temperature on a low power sensor network, using an Arduino Pro mini and nRF24L01 wireless module.

I have written a small program based on the code written by maniacbug, and have managed to get the receiver and transmitter communicating under continual operation. Although to increase the battery life I am looking to put the Arduino and wireless module into sleep on an 8 sec watchdog timer, wake up take a reading then go back to sleep.

I have trialled the watchdog tutorial using a flashing LED on the transmitter node only, with no RF communication and it works correctly. As soon as I attempt to combine the two codes and transmit data over the network to print to serial, the timings appear to be random, some are 8 seconds apart, but others are up to 30 seconds apart. I have looked over the past few days, and am not sure what else to try, and was wondering if I have missed something obvious, and whether anyone has experienced this before?

Any help you could give would be much appreciated my code for the transmitter and receiver are shown below.

Transmitter

#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>

volatile int f_wdt=1;

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

#define CE_PIN   9
#define CSN_PIN 10
#define Sensor_1 A2

const uint64_t pipe = 0xE8E8F0F0E1LL; 

RF24 radio(CE_PIN, CSN_PIN); 

int TempSensor[1];


ISR(WDT_vect)
{
  if(f_wdt == 0)
  {
    f_wdt=1;
  }

}

void enterSleep(void)
{
  wdt_reset();

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   

  sleep_enable();

  sleep_mode();

  sleep_disable(); 

  power_all_enable();
}


void setup()
{
  radio.begin();
 
  radio.openWritingPipe(pipe);

  MCUSR &= ~(1<<WDRF);

  WDTCSR |= (1<<WDCE) | (1<<WDE);

  WDTCSR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds Sleep*/

  WDTCSR |= _BV(WDIE);

}


void loop()
{
  if(f_wdt == 1)
  {
    radio.begin();
    
    radio.openWritingPipe(pipe);

    TempSensor[0]=analogRead(Sensor_1);
   
    radio.write(TempSensor, sizeof(TempSensor) );

    delay(100);

    radio.powerDown();

    f_wdt = 0;

    enterSleep();
  }

}

Receiver

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

#define CE_PIN   9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL; 

RF24 radio(CE_PIN, CSN_PIN); 

int TempSensor[1];  

void setup()   
{
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();

}

void loop(){

  if ( radio.available() )
  {

    bool done = false;
    while (!done) {

      done = radio.read( TempSensor, sizeof(TempSensor) );

  Serial.println(TempSensor[0]);

    }
  }

}

You don't appear to power up the radio on the sender after waking up, instead you run radio.begin() again, perhaps switch that with radio.powerUp()

You might also simply have the radios too far apart, you can try adding the following to setup after radio.begin but before opening the pipe to set the both radios to max power, and lowest speed which will give you much more range

  radio.setRetries(15,15);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_MAX);

Initially with my weather station I tried the same approach but I used the narcoleptic library.

Now I don't bother with sleeping at all as I needed interrupts and it got messy. I stillg et 10 days of runtime even without the sleep from a small 1000mah battery and the panel easily charges the battery to full every day so I never went back to trying sleep

Rather than putting the Arduino to sleep to save power perhaps it would be sufficient to have the Arduino turn the radio part off.

...R

Hello Robin2/WendoNZ,

Many thanks for your help and suggestions on this. I will try both approaches over the weekend and let you know how I get on.

Thanks again

Hi,

Sorry for taking a while to reply to this post I’ve have just picked the project back up, the suggestions by WendoNZ above worked, and the program is now working correctly. I will upload the new program if it is useful to anyone.

The system is working correctly, but there seems to be difference between the current draw on each one. For example system 1 draws 0.21 mA in power down, system 2 1.55 mA and system 3 2.4 mA. The Pro Mini’s are all drawing roughly the same and I think the issue is with the wireless modules after a few tests. Has anyone come across the same issue with the nRF24L01 module or does this fall within acceptable limits for the components? I was just expecting the current requirements of each of the setups to be closer, as the wireless module data sheet quotes a sleep current of 900 nA.

Another thing I did think of, would it be possible to control the wireless module, with a solid state relay. So instead of going into power down, the power is actually cut to the wireless module with the solid state relay connected to an Arduino digital pin. I am no expert in these sorts of things, and have tried a few simple Arduino sketches but nothing that I have tried seems to work. the wireless module doesn't appear to come on after the power is cut correctly even if I use the radio.begin() command.

I was just wondering if this is possible, or will it damage the wireless module? I was wondering if there was an initialisation procedure or similar that I could implement before and after the wireless module is turned off, to overcome this. I was trying to make my nodes as low power as possible and just wanted to improve upon the above results if possible. If they were all close to the 0.21 mA case then I would not consider any further modifications.