danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

nRF24L01 new shockburst for arduino

Tue Mar 17, 2015 11:28 am

I'm investigating the nRF24L01 transmitter.

I found some code in python and I was able to modify the code to have the correct behavior for the shockburst acknowledge with payload.
https://github.com/Blavery/lib_nrf24

The correct method was to push the payload before we received the packet. This way it is send back without our intervention.

This way I was able to get around 200 transactions per seconds. Using Two Raspberry PI in python.

I want to use this method on an arduino with sensor. The reason is obvious, it is about power consumption.

On shockburst we should have the arduino , the receiver and the sensor on standby 90% of the times.

This method is still a master/slave but with a timing method.
So the step I see in the loop
1 - Wake up after the determinate time.
2 - Power up the sensor
3 - Wait until sensor ready
4 - Read the sensor.
5 - Wake up transmitter.
6 - Push the sensor and other data,like battery voltage, into the payload buffer. (this is not transmitted. It will be on the automatic ack).
7 - Put Arduino in sleep mode
8 - Interrupt or watchdog wake up
9 - From the Transmitter interrupt telling us that we received something, read the Rcv FIFO and extract the data
10 - Put back the Transmitter in standby mode
11 - Set the next wake timer ( this could be a count of the watch dog)
12 - Put to arduino in sleep mode (On wake return to 1)
This way the arduino should reduce the power consumption by a lot and I could use 2 AA battery for more than a month.

I'm still looking for arduino code using the interrupt pin.

My first sensor will be the DHT22.

Daniel

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Mon Mar 23, 2015 3:31 am

OK I didn't do anything about the power reduction using an arduino, nRF24L01 and the DHT22, but I did have working code to have my DHT22 in wireless mode.

I design the python code to be able to set more modules and it is quite fast.

I made it works like the master/slave system

The Raspberry Pi loops on each sensor and will ask the sensor to give it's data. Like I said I'm using the shockburst method. The RaspberryPi send to a specific sensor the current time and the next times the sensor should send the next data. The Arduino on the other side will power up the DHT22 sensor 5 seconds before the target time ,read the sensor and fill up the transmit fifo buffer. The beauty of the shockburst method is that the arduino just wait for the raspberry Pi to transmit and the fifo buffer will be send automatically to the Pi without any intervention of the arduino.


Presently I just power up/down the DHT22 sensor , but I will eventually put the RF24L01 and the Arduino mode into sleep mode when I don't need them. The purpose is to reduce power consumption to a minimal. This way I could use AA batteries which will last very long.

So right now the python code is working and display the sensor data on the terminal.

I use this github to get the library to run the nRF24L01 on python

https://github.com/Blavery/lib_nrf24

And this is the Python code

Code: Select all

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Example program to send packets to the radio link
#


import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
from lib_nrf24 import NRF24
import time
import spidev
import binascii
import numpy
from struct import *


STRUCT_TYPE_GETDATA=0
STRUCT_TYPE_INIT=1
STRUCT_TYPE_DHT22=2


class DHT22Data:
    time = None
    humidity = 0
    temperature =0
    voltage=0
    valid=False

class RF_Device:
  def __init__(self, deviceAddress, nextTime=60):
    self.deviceAddress=deviceAddress
    self.nextTime=nextTime;
    self.lastConnectionTime= time.time()
    self.nextConnectionTime= self.lastConnectionTime
    self.xdata = [0,0,0]
    self.rdata = ''

  def isTimeOut(self):
    return (time.time() > self.nextConnectionTime)


  def readSensorAddress(self):
     buffer = '{:02X}'.format(self.deviceAddress[0])
     for i in range(1,5,1):
       buffer += ':{:02X}'.format(self.deviceAddress[i])   
     return buffer

  def unpackDHT22Data(self , buffer):
     dht22 =  DHT22Data

     if len(buffer) != 15:
         return None
     try:
        self.rdata = unpack('<sBBBLBHHH',''.join(map(chr,buffer)))
        dht22.time = self.rdata[4]
        dht22.valid = self.rdata[5]!=0
        dht22.voltage = self.rdata[6]/1000.0
        dht22.temperature = self.rdata[7]/10.0
        dht22.humidity = self.rdata[8]
        return dht22
     except:
        return None

  def getData(self):
    if( not self.isTimeOut()):
       return None
    
#    print("timeout={}".format(self.nextTime))
    self.nextConnectionTime += self.nextTime
    #buildpacket
    packet = '*'
    packet += chr(10)  #get packet size
    packet += chr(STRUCT_TYPE_GETDATA)
    packet += chr(0)   #0 mean master
    packet += pack('<L', numpy.uint32(time.time()))  #get current time
    packet += pack('<H', numpy.uint16(self.nextTime *10))  #get next time reading
    
        
 #   print("send : {}".format(list(packet)))

    radio.openWritingPipe(self.deviceAddress)

    radio.write(packet)
    if True:
     if radio.isAckPayloadAvailable():
      in_buffer=[]
      radio.read(in_buffer,radio.getDynamicPayloadSize())
      validFlag= False
      if len(in_buffer)>4:
         # check first four bytes
         if in_buffer[0] == ord('*'):
           if in_buffer[2] == STRUCT_TYPE_INIT:
             #sensor is valid but just boot
             print("Sensor {} - {} - Just boot".format(self.readSensorAddress(),time.ctime()))
             validFlag=True
           if in_buffer[2] == STRUCT_TYPE_DHT22:
             dht22 = self.unpackDHT22Data(in_buffer)
             if dht22 != None:
               if dht22.valid:
                 print("Sensor {} - {}   VCC:{}V T:{}C H:{}%".format(self.readSensorAddress(),time.ctime(dht22.time),dht22.voltage,dht22.temperature,dht22.humidity))
               else:
                 print("Sensor {} - {}  VCC:{}V Unable to read DHT22 sensor".format(self.readSensorAddress(),time.ctime(dht22.time),dht22.voltage))
               validFlag=True

         
#       except:
#         print("Unable to unpack!Bad packet")

      if not validFlag:
            print("Sensor {} - {}  Invalid packet!".format(self.readSensorAddress(),time.ctime()))
     else:
            print("Sensor {} - {}  time out!".format(self.readSensorAddress(),time.ctime()))



masterAddress = [0xe7, 0xe7, 0xe7, 0xe7, 0xe7]

device = [RF_Device([0xc2,0xc2,0xc2,0xc2,0xc3],10)]



radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
time.sleep(1)
radio.setRetries(15,15)
radio.setPayloadSize(32)
radio.setChannel(78)

radio.setDataRate(NRF24.BR_1MBPS)
radio.setPALevel(NRF24.PA_MAX)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()


radio.openWritingPipe(device[0].deviceAddress)
radio.openReadingPipe(1, masterAddress)
radio.printDetails()

time.sleep(1)

try:

 while True:
   for i in  device:
     if(i.isTimeOut()):
      i.getData();
 
   time.sleep(0.01)

except KeyboardInterrupt:
    radio.stopListening();
    radio.powerDown();
    raise
and this is the result display

Code: Select all

pi@Pi2 ~/lib_nrf24 $ sudo python s4.py
/home/pi/lib_nrf24/lib_nrf24.py:377: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  self.GPIO.setup(self.ce_pin, self.GPIO.OUT)
STATUS	 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1	 = 0xc2c2c2c2c3 0xe7e7e7e7e7
RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6 
TX_ADDR		 = 0xc2c2c2c2c3
RX_PW_P0-6	 = 0x20 0x20 0x00 0x00 0x00 0x00 
EN_AA		 = 0x3f 
EN_RXADDR	 = 0x03 
RF_CH		 = 0x4e 
RF_SETUP	 = 0x07 
CONFIG		 = 0x0c 
DYNPD/FEATURE	 = 0x3f 0x06 
Data Rate	 = 1MBPS
Model		 = nRF24l01+
CRC Length	 = 16 bits
PA Power	 = PA_HIGH
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:36:41 2015 - Just boot
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:36:45 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:36:53 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:37:03 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:37:13 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:37:23 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:37:33 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:37:43 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:37:53 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:38:03 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:38:13 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:38:23 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:38:33 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:38:43 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:38:53 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:39:03 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:39:13 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:39:23 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:39:33 2015   VCC:4.957V T:19.3C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:39:43 2015   VCC:4.957V T:19.4C H:16%
Sensor C2:C2:C2:C2:C3 - Sun Mar 22 22:39:53 2015   VCC:4.957V T:19.3C H:16%
For the arduino code I use those code for the nRF24L01 and the DHT22 library
http://maniacbug.wordpress.com/2011/11/ ... rted-rf24/
http://provideyourown.com/2012/secret-a ... y-voltage/
https://github.com/RobTillaart/Arduino.git

And now my Arduino code

Code: Select all

/*
 Copyright (C) 2015 Daniel Perron
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 
 Read DHT22 sensor using a nRF24L01 sensor base on J.Coliz code
 
*/



/*
 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
//2014 - TMRh20 - Updated along with Optimized RF24 Library fork
 */

/**
 * Example for Getting Started with nRF24L01+ radios. 
 *
 * This is an example of how to use the RF24 class to communicate on a basic level.  Write this sketch to two 
 * different nodes.  Put one of the nodes into 'transmit' mode by connecting with the serial monitor and
 * sending a 'T'.  The ping node sends the current time to the pong node, which responds by sending the value
 * back.  The ping node can then see how long the whole cycle took. 
 * Note: For a more efficient call-response scenario see the GettingStarted_CallResponse.ino example.
 * Note: When switching between sketches, the radio may need to be powered down to clear settings that are not "un-set" otherwise
 */


#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
#include "dht.h"


#define DHT_PIN 2
#define DHT_POWER_PIN 3


//DHT22 class
dht DHT;


short  temperature= 32767;
unsigned short  humidity  = 32767;



// Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 9 & 10 
RF24 radio(8,7);

#define UNIT_ID 0xc3


const uint64_t pipes[2] = { 0xc2c2c2c2c3 , 0xe7e7e7e7e7 };              // Radio pipe addresses for the 2 nodes to communicate.


// Set up roles to simplify testing 
boolean role;                                    // The main role variable, holds the current role identifier
boolean role_ping_out = 1, role_pong_back = 0;   // The two different roles.
unsigned long Count=0;

void setup() {

  // Set pin for DHT22 power
  pinMode(DHT_POWER_PIN, OUTPUT);
  digitalWrite(DHT_POWER_PIN, LOW);
  
  Serial.begin(57600);
  printf_begin();
  printf("\n\rRF24/examples/GettingStarted/\n\r");
  printf("*** PRESS 'T' to begin transmitting to the other node\n\r");

  // Setup and configure rf radio
  //radio.setChannel(0x60);
  radio.begin();                          // Start up the radio
  radio.setPayloadSize(32);
  radio.setChannel(0x4e);
  radio.setAutoAck(1);                    // Ensure autoACK is enabled
  radio.setRetries(15,15);   // Max delay between retries & number of retries
  radio.enableDynamicPayloads();
  radio.enableAckPayload();
  //role = role_ping_out;                  // Become the primary transmitter (ping out)
  radio.openWritingPipe(pipes[1]);
   radio.openReadingPipe(1,pipes[0]);
    
  radio.startListening();                 // Start listening
  radio.stopListening();
  radio.printDetails();                   // Dump the configuration of the rf unit for debugging
  radio.startListening();
}


enum cycleMode {ModeInit,ModeListen,ModeWriteData,ModeWait};

cycleMode cycle= ModeInit;


#define STRUCT_TYPE_GETDATA    0
#define STRUCT_TYPE_INIT_DATA  1
#define STRUCT_TYPE_DHT22_DATA 2


typedef struct
{
  char header;
  unsigned char structSize;
  unsigned char structType;
  unsigned char txmUnitId;
  unsigned long currentTime;
  unsigned short nextTimeReading;
  char Spare[22];
}RcvPacketStruct;


typedef struct
{
   char header;
   unsigned char structSize;
   unsigned char structType;
   unsigned char txmUnitId;
   unsigned long  stampTime;
   unsigned char  valid;
   unsigned short voltageA2D;
   unsigned short temperature;
   unsigned short humidity;
}TxmDHT22PacketStruct;


unsigned long currentDelay;
unsigned long targetDelay;

RcvPacketStruct RcvData;
TxmDHT22PacketStruct Txmdata;

unsigned char * pt = (unsigned char *) &RcvData;


unsigned char rcvBuffer[32];


void PrintHex(uint8_t *data, uint8_t length) // prints 16-bit data in hex with leading zeroes
{
       char tmp[32];
       for (int i=0; i<length; i++)
       { 
         sprintf(tmp, "0x%.2X",data[i]); 
         Serial.print(tmp); Serial.print(" ");
       }
}

bool readSensor(void)
{

  // power Sensor UP
  digitalWrite(DHT_POWER_PIN, HIGH);
  // Wait 2 sec
  delay(2000);
  
  // Now let's read the sensor twice
  // since the first one will be bad
  
  DHT.read(DHT_PIN);
  delay(1000);
  int rcode = DHT.read(DHT_PIN);
  
  // power off DHT22
  
  digitalWrite(DHT_POWER_PIN,LOW);
  
  return (rcode == DHTLIB_OK);
}     



//From http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
unsigned short readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
    ADMUX = _BV(MUX5) | _BV(MUX0);
  #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
    ADMUX = _BV(MUX3) | _BV(MUX2);
  #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #endif  
 
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
 
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
 
  long result = (high<<8) | low;
 
  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return (unsigned short) result; // Vcc in millivolts
}


void loop(void){
int loop;
unsigned long deltaTime;  
/****************** Ping Out Role ***************************/
  
  if(cycle==ModeInit)
   {
     Count++;
     Txmdata.header='*';
     Txmdata.structSize= sizeof(TxmDHT22PacketStruct);
     Txmdata.structType=STRUCT_TYPE_INIT_DATA;
     Txmdata.txmUnitId = UNIT_ID;
     Txmdata.stampTime=0;
     Txmdata.valid=0;
     Txmdata.temperature=0;
     Txmdata.humidity=0;
     Txmdata.voltageA2D=0;
     radio.writeAckPayload(1,&Txmdata,sizeof(TxmDHT22PacketStruct));
     cycle=ModeListen;
   }
   
  if(cycle==ModeListen)
   {
      if(radio.available()) 
      {
        int rcv_size= radio.getDynamicPayloadSize();
        radio.read( &RcvData,rcv_size);
        Serial.print("T:" );
        Serial.print(RcvData.currentTime);
        Serial.print(" Next reading in (1/10 sec): ");
        Serial.print(RcvData.nextTimeReading);
        Serial.print("\n");
        PrintHex(pt,rcv_size);
        Serial.print("\n");        
        currentDelay = millis();
        if(RcvData.nextTimeReading > 50)
          {
           targetDelay =  RcvData.nextTimeReading*100 - 5000UL;
           cycle = ModeWait;
          }
          else
           cycle = ModeWriteData;
      }
   }
   
   
   if(cycle== ModeWait)
     {
       
       deltaTime = millis() - currentDelay;
      
       if(deltaTime >= targetDelay)
          cycle = ModeWriteData;
       
     }
   
   
   if(cycle==ModeWriteData)
    {
     Txmdata.valid=1;
     Txmdata.stampTime=RcvData.currentTime;
     Txmdata.header='*';
     Txmdata.structSize= sizeof(TxmDHT22PacketStruct);
     Txmdata.structType=STRUCT_TYPE_DHT22_DATA;
     Txmdata.txmUnitId = UNIT_ID;
     Txmdata.stampTime=RcvData.currentTime + (deltaTime / 1000);
     Txmdata.valid=0;
     Txmdata.temperature=32767;
     Txmdata.humidity=32767;
     Txmdata.voltageA2D=readVcc();

     if(readSensor())
       {
         Txmdata.temperature = (short) floor(DHT.temperature * 10.0);
         Txmdata.humidity = (short) floor(DHT.humidity);
         Txmdata.valid = 1;
       }
     radio.writeAckPayload(1,&Txmdata,sizeof(TxmDHT22PacketStruct));
     cycle=ModeListen;     
    }
      
}

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Tue Mar 24, 2015 3:04 am

I added the sleep mode into the arduino.

I used this library
https://github.com/n0m1/Sleep_n0m1

I'm still have problem with the interrupt from the nRF24L01. On the library it is possible to set the mask for the interrupt but
there is nothing about removing it.

I get around using the time sleep method.

I put the code into github.

https://github.com/danjperron/nRF24L01_With_Sensor.git

Tomorrow I will use an arduino mini instead of the UNO and check the current reduction provided by the sleep mode.

Daniel

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Wed Mar 25, 2015 1:27 am

Ok I build another sensor with an arduino pro mini 5V.

I try using two 2AA battery but the arduino keep rebooting. I thing it is because of the brown out reset.

Then I decide to use 3xAA instead and add a LE33CZ regulator to get 3.3V for the nRF24L01.

To check the current , I put a multimeter between the battery and the arduino mini VCC. I didn't use the raw but I connect the 4.5V directly to the VCC. This way I bypass the build in regulator.
So I got a maximum current of 16 ma and a standby current at 3 ma.

Image

I decide to pop up the resistor for the power led and I reduce the standby current to 2ma.
Image

To figure out the current distribution with time I plugged my oscilloscope with a 1 ohm resistor and let it run for one cycle.

Image


Looks conclusive enough and I should be able to reduce even more the current.

I will order some 3.3V arduino pro mini and check if I could run with only 2 AA battery.

The arduino mini will run until I got a time out. I want to see how long it will last.


Now let's do the DS18B20 sensor on the nRF24L01.

Daniel
Last edited by danjperron on Wed May 03, 2017 3:19 pm, edited 2 times in total.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Wed Mar 25, 2015 1:27 am

Ok update .

I forgot to power off the DHT22 data pin and some current was draining from there.

I changed the routine and I put the DHT22 power and data pins low and now the total current in sleep mode is 1.04 ma.

This is around 90 days on battery.

Daniel

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Thu Mar 26, 2015 2:26 am

After waiting 3 hours on update on my Acer laptop. I was able to run Atmel AVR studio
and change the BROW out Voltage set by the fuse of the Arduino mini using the AVR MKII usb adapter.

Than I was able to run the Arduino pro mini with 2xAA battery and no LE33cz regulator and I got 0.41 ma in sleep mode.
I will see if can shut down more stuff inside the 328P but this is good for my test.
I know that I didn't remove the build-in 5V regulator from the Arduino and this is the possible cause of this high current but this is my test board and I will remove the regulator when I get the arduino mini at 8Mhz and I will see how much the regulator draw current.

I do have 2 sensors working right now.
The DS18B20 Sensor is attached to an Arduino UNO with a standard 9V supply.
The DHT22 sensor is attached to an arduino pro mini 16Mhz, with the brow out fuse set to 1.7V, with 2 AA batteries .

This is a dump from the Log file of my RF24Reader.py script

Code: Select all

pi@Pi2 ~ $ tail RFLog.txt
Sensor C2:C2:C2:C2:C3 - Wed Mar 25 22:18:45 2015 VCC:4.935V - DS18B20 T:20.0 C
Sensor C2:C2:C2:C2:C4 - Wed Mar 25 22:18:45 2015 VCC:2.969V - DHT22   T:19.70 C H:41 %
Sensor C2:C2:C2:C2:C3 - Wed Mar 25 22:18:54 2015 VCC:4.935V - DS18B20 T:19.93 C
Sensor C2:C2:C2:C2:C4 - Wed Mar 25 22:18:54 2015 VCC:2.976V - DHT22   T:19.70 C H:41 %
Sensor C2:C2:C2:C2:C3 - Wed Mar 25 22:19:52 2015 VCC:4.935V - DS18B20 T:19.93 C
Sensor C2:C2:C2:C2:C4 - Wed Mar 25 22:19:52 2015 VCC:2.976V - DHT22   T:19.60 C H:47 %
Sensor C2:C2:C2:C2:C3 - Wed Mar 25 22:20:52 2015 VCC:4.935V - DS18B20 T:19.87 C
Sensor C2:C2:C2:C2:C4 - Wed Mar 25 22:20:52 2015 VCC:2.976V - DHT22   T:19.50 C H:41 %
Sensor C2:C2:C2:C2:C3 - Wed Mar 25 22:21:52 2015 VCC:4.935V - DS18B20 T:19.87 C
Sensor C2:C2:C2:C2:C4 - Wed Mar 25 22:21:52 2015 VCC:2.976V - DHT22   T:19.50 C H:41 %
I ordered some Arduino pro mini at 8Mhz. I know 16Mhz won't run with low voltage.

Daniel

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Sun Mar 29, 2015 11:12 pm

I found out that the DHT22 wasn't working when to voltage goes below 2.7V.

I decide to use 3 batteries AA instead. This way the DHT22 will always have enough voltage.

This cause a problem for the nRF24L01 but I did the same scheme than the DHT22. One pin of the Arduino will be used to provide power through a 3.3V regulator.

I also removed the build-in regulator and the power led resistor.

Now I got 28 µA on sleep mode. I know I can reduce it more if I disable the brew detection on sleep.

I update github and this is the new schematic for the DHT22 in wireless using the nRF24L01

Image

Next thing will be to change the python code to minimize the reception waiting time.

Daniel
Last edited by danjperron on Wed May 03, 2017 3:22 pm, edited 1 time in total.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Mon Apr 06, 2015 2:59 am

Ok I put code for the DS18B20 and the MAX6675.

I also change the python code to pre-read the sensor 5 second after and before the target time stamp. This way I minimize the listen time on the sensor and reduce the power consumption by a lot. The transmitter is just power ON for less than 0.1 second.

Daniel

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Mon Apr 13, 2015 5:13 pm

After a couple of trial on error I got a decent drain consumption on the sensor.

Image

I wasn't able to explain why on every 100 mins the battery voltage had a spike of 100mv down until I started to look at the watch dog sleep function. On every 100 sleeps, the watch dog was calibrating itself up . This mean that the arduino was in fact awake on a full cycle on every 100 of them. The 357 Battery is only 150mah and this was a huge drain ~10ma for one minute.

I intend to have the arduino mostly on sleep mode which is ~28 uA.

I thing that the calibration of the watch dog is important but I will change the code, without changing the library, to do the calibration on 0.5 second in every 720 cycle (half day). This should helps reducing the power consumption.
Last edited by danjperron on Wed May 03, 2017 3:23 pm, edited 1 time in total.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Tue Apr 14, 2015 11:31 am

Ok I fix the DS18B20 code to only recalibrate the watch dog timing on every 720 cycles and also only do it when it waits 800ms for the conversion of the DS18B20 sensor.

And this is way better now

Image


I will do it for the max6675 and the DHT22 code.

Now I will be able to optimize the python code and add MQTT.
Last edited by danjperron on Wed May 03, 2017 3:24 pm, edited 1 time in total.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Mon Apr 20, 2015 1:53 am

I change the Arduino code for DHT22 sensor to deal with the sleep calibration exactly like the DS18B20 sensor.

I start to install the sensor outside.

I temporally put the DS18B20 sensor for the pool at the top of the deck.

Image

I still have ice at the surface but it should be gone tomorrow. The Temperature at 30cm from the surface is now 5 ˚C.

Image
I found out that the nRF24Sensor at the PI needs to be set in vertical position otherwise it wasn't able to communicate with the outside sensors.

Now I start to build a new DHT22 sensor for outside.

First I removed the build-in regulator and the power led resistor to minimize the power consumption. The regulator by itself need 500 µA and the led around the 1ma.

Image

On the nRF24L01 , I added a 1 µF capacitor to limit power fluctuation.
Image

I cut one of my old IDC-10 to db9 rs-232 flat cable. I let 5 cm of flat cable and I added some solder on the tip of the wires.
Be aware that odd and even pin are inverted on the nRF24L01 when you use an IDC connector. (pin1 became pin2 and vice versa).
Image

I soldered the flat cable to the arduino mini. I won't solder pin 1 and 2 for the moment.
Image

I put the LE33cz, the 3.3V regulator, on top of the cpu. The middle pin to ground and the Input to pin 5.
The output is connected to the pin 2 of the nRF24L01. I also connect the ground and another flat cable for the DHT22.
Image

After that I burned the program into the arduino. It was time to assemble everything and check if it works.
Image

With hot glue , I inserted everything into the Hammond box except the DHT22 which will be outside.
Image

And finally, I put the assembled unit under my deck for protection against the the rain and the sun. I also use some gorilla tape and create some kind of gutter to prevent water to go directly into the sensor.
Image

Now I will let the sensor running. I will check how long it will last and survive outside.
I think the battery should last 1 year, but I'll see.

Code: Select all

Sensor C2:C2:C2:C2:C8 D:0.0 O:0.3  - Sun Apr 19 21:46:42 2015 VCC:4.788V - DHT22   T:7.60 C H:29 %
Sensor C2:C2:C2:C2:C6 D:0.0 O:1.4 - Sun Apr 19 21:46:54 2015 VCC:3.948V - DS18B20 T:4.5 C
Sensor C2:C2:C2:C2:C3 D:-0.0 O:1.1 - Sun Apr 19 21:47:06 2015 VCC:3.441V - DS18B20 T:18.56 C
Sensor C2:C2:C2:C2:C4 D:0.0 O:2.0  - Sun Apr 19 21:47:18 2015 VCC:5.161V - DHT22   T:18.60 C H:27 %
Sensor C2:C2:C2:C2:C5 D:-0.0 O:1.9 - Sun Apr 19 21:47:30 2015 VCC:5.185V - MAX6675 T:21.0 C
Sensor C2:C2:C2:C2:C8 D:0.0 O:0.3  - Sun Apr 19 21:47:42 2015 VCC:4.788V - DHT22   T:7.60 C H:29 %
Sensor C2:C2:C2:C2:C6 D:0.0 O:1.4 - Sun Apr 19 21:47:54 2015 VCC:3.948V - DS18B20 T:4.5 C
Sensor C2:C2:C2:C2:C3 D:0.0 O:1.1 - Sun Apr 19 21:48:06 2015 VCC:3.441V - DS18B20 T:18.56 C
Sensor C2:C2:C2:C2:C4 D:0.0 O:2.0  - Sun Apr 19 21:48:18 2015 VCC:5.138V - DHT22   T:18.60 C H:27 %
Sensor C2:C2:C2:C2:C5 D:-0.0 O:1.9 - Sun Apr 19 21:48:30 2015 VCC:5.185V - MAX6675 T:21.0 C
Sensor C2:C2:C2:C2:C8 D:0.0 O:0.3  - Sun Apr 19 21:48:42 2015 VCC:4.788V - DHT22   T:7.60 C H:29 %
Sensor C2:C2:C2:C2:C6 D:0.0 O:1.4 - Sun Apr 19 21:48:54 2015 VCC:3.948V - DS18B20 T:4.5 C
Sensor C2:C2:C2:C2:C3 D:0.1 O:1.1 - Sun Apr 19 21:49:06 2015 VCC:3.441V - DS18B20 T:18.56 C
Sensor C2:C2:C2:C2:C4 D:0.0 O:2.0  - Sun Apr 19 21:49:18 2015 VCC:5.161V - DHT22   T:18.50 C H:27 %
Sensor C2:C2:C2:C2:C5 D:0.1 O:1.9 - Sun Apr 19 21:49:30 2015 VCC:5.185V - MAX6675 T:20.25 C
Sensor C2:C2:C2:C2:C8 D:0.0 O:0.3  - Sun Apr 19 21:49:42 2015 VCC:4.788V - DHT22   T:7.60 C H:29 %
Sensor C2:C2:C2:C2:C6 D:0.0 O:1.4 - Sun Apr 19 21:49:54 2015 VCC:3.948V - DS18B20 T:4.5 C
Sensor C2:C2:C2:C2:C3 D:0.0 O:1.1 - Sun Apr 19 21:50:06 2015 VCC:3.441V - DS18B20 T:18.56 C
Sensor C2:C2:C2:C2:C4 D:-0.1 O:2.0  - Sun Apr 19 21:50:18 2015 VCC:5.161V - DHT22   T:18.50 C H:27 %
The outside DHT22 sensor is C8.
The pool's DS18B20 sensor is C6.

Daniel
Last edited by danjperron on Wed May 03, 2017 3:31 pm, edited 2 times in total.

ArjenWols
Posts: 3
Joined: Thu Sep 19, 2013 8:15 pm

Re: nRF24L01 new shockburst for arduino

Tue May 31, 2016 10:25 pm

What a great and detailed information.
Looking in this type of configuration to register the data in Domoticz.
Anyone any idea how to resolve this??

Thanks for reply in advance.

Arjen

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: nRF24L01 new shockburst for arduino

Wed May 03, 2017 3:39 pm

ArjenWols wrote:What a great and detailed information.
Looking in this type of configuration to register the data in Domoticz.
Anyone any idea how to resolve this??

Thanks for reply in advance.

Arjen
I just update the public dropbox link. Some of my images were not showing.
I'm not using domoticz but MQTT. I'm sure that there is a way to link MQTT to domoticz.
Also I use flask to get information from my MQTT server to my Amazon echo dot and it is working great.

Since I got Echo dot home , I don't need any panel display for my IOT. Everything is by voice! I just ask Alexa.

Daniel

antonprafanto
Posts: 1
Joined: Sun May 07, 2017 12:44 pm

Re: nRF24L01 new shockburst for arduino

Sun May 07, 2017 12:48 pm

Hallo, i come from Indonesia
Alhamdulillah, thank you so much for your tutorial :) :

Return to “Interfacing (DSI, CSI, I2C, etc.)”