Pages: [1]   Go Down
Author Topic: Home wireless sensor nodes connected to a base  (Read 450 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I am trying to create several sensor nodes with wireless communication to the base.

An UNO is used for every node. The UNO is connected to an nRF24L01+, 2 LEDs,a DHT11 sensor to provide thermometer /humidity data and a GAS sensor.

The base is an nano 3.0 which is connected to a DHT11 sensor and an nRF24L01+.

Both of nodes connect successfully and exchange data. The node sends all reading to the base from=>to an array. The base receives the data and displays them to serial.

The problem is that the DHT11 reads and displays successfully when alone (no nRF24 code) so does the nRF24 (no DHT11 code). I can't manage to make them work together. I have tried four DHT11 libraries with no success. The loop hangs.

Any opinions will be strongly appreciated. This is my code for the base (which appears to have the problem):

Code:
#include <dht11.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

dht11 DHT11;

#define DHT11PIN 10

RF24 radio(8,7);
int ledPinA = 5;
int ledPinB = 6;

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

void setup()
{
  //
  // Role
  //
  pinMode(ledPinA,OUTPUT);
  pinMode(ledPinB,OUTPUT);
  digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, LOW);
 

  Serial.begin(9600);
  printf_begin();
  printf("\nHOME v1.0.1\n");
  printf("\n----------------------------------------\n");
  radio.begin();

  radio.setRetries(15,15);

  radio.setPayloadSize(8);
  radio.setDataRate(RF24_250KBPS);

  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);

  radio.startListening();

  radio.printDetails();
 
  Serial.print("\n*****************************\n");
  Serial.print("Requesting data from sensors...\n");
  Serial.print("DHT: ");

 
}
void loop()
{
    digitalWrite(ledPinB,HIGH);   
    Serial.print("*");
    delay(100);

    DHT11.read(DHT11PIN);
    float t = DHT11.temperature;
    float h = DHT11.humidity;

    Serial.print("\n-------------------------------------\n");
    Serial.print("BASE     : ");
    Serial.print("temp-an: ");
    Serial.print((float)t, 2);
    Serial.print("*C");
    Serial.print(" | ");
    Serial.print("hum-an: ");
    Serial.print((float)h, 2);
    Serial.print("%\n");

    if ( radio.available() )
    {
      int16_t data[10];
      bool done = false;
      delay(100);
      digitalWrite(ledPinB,LOW);
      digitalWrite(ledPinA,HIGH);
      while (!done)
      {
        done = radio.read( data, sizeof(data) );
       
        Serial.print("NODE (A) : ");
        Serial.print("temp-dig: ");
        float tempD = (float)data[0]/100;
        Serial.print(tempD);
        Serial.print("*C | ");
        Serial.print("temp-an: ");
        Serial.print(data[1]);
        Serial.print("*C | ");
        Serial.print("humid-an: ");
        Serial.print(data[2]);
        Serial.print("% \n");
        Serial.print("*C | ");
        Serial.print("gas-an: ");
        Serial.print(data[3]);
        Serial.print("% \n");
        delay(100);
        digitalWrite(ledPinA,LOW);
        delay(100);
      }

      radio.stopListening();
      radio.startListening();
    }
}





Logged

Offline Offline
Full Member
***
Karma: 5
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Move your DHT-11 off of pin 10. 

http://arduino.cc/en/Reference/SPI

Quote
All AVR based boards have an SS pin that is useful when they act as a slave controlled by an external master. Since this library supports only master mode, this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative.

That happens to be pin 10 on the Uno
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is nice to know. But actually I made some changes, as moving the sensors reading functions outside the loop and play with different positions of the DHT read function (it appeared to be the problem) and finally it works 100% !

This is my code for reference If someone has the same problem in the future (I've added an LDR sensor and a buzzer too) :

Code:
#include <dht11.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

dht11 DHT11;
#define DHT11PIN 10
RF24 radio(8,7);
int ledPinA = 5;
int ledPinB = 6;
int ldrPin = 0;
int spkrPin = 9;
int LDRValue = 0;
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

void setup()
{
  pinMode(ledPinA,OUTPUT);
  pinMode(ledPinB,OUTPUT);
  pinMode(spkrPin,OUTPUT);
  pinMode(ldrPin, INPUT);
  digitalWrite(ledPinA, LOW);
  digitalWrite(ledPinB, LOW);
  digitalWrite(spkrPin, LOW);
 
  Serial.begin(9600);
  DHT11.read(DHT11PIN);
  delay(1000);
  printf_begin();
  radio.begin();

  radio.setRetries(15,15);
  radio.setPayloadSize(8);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);
  radio.startListening();
  radio.printDetails();
 
  Serial.print("\n*****************************\n");
  Serial.print("* Setup complete.\n");
  Serial.print("* Loop starting\n");
  delay(500);
 
}
void loop()
{
    Serial.print("#");
    digitalWrite(ledPinB,HIGH);
    delay(100);
    digitalWrite(ledPinB,LOW);
    delay(100);
    digitalWrite(ledPinB,HIGH);
    delay(100); 
    digitalWrite(ledPinB,LOW);
    delay(100);
    if ( radio.available() )
    {
      int16_t data[10];
      bool done = false;
      digitalWrite(ledPinA,HIGH);
      delay(100);
      while (!done)
      {
        done = radio.read( data, sizeof(data) );
        float t = getLocalTemp();
        float h = getLocalHumi();
        int l = getLDRvalue();
        int adjustedLightLevel = 100 - map(l, 50, 1000, 0, 100);
        Serial.print("\n");
        Serial.print("\nBASE (A) : ");
        Serial.print("temp[D]: ");
        Serial.print(t);
        Serial.print("*C | ");
        Serial.print("humi[D]: ");
        Serial.print(h);
        Serial.print("% | ");
        Serial.print("phot[A]: ");
        Serial.print(adjustedLightLevel);
        Serial.print("% | ");
        delay(200);
        Serial.print("\nNODE (A) : ");
        Serial.print("temp[A]: ");
        Serial.print((float)data[1],2);
        Serial.print("*C | ");
        Serial.print("humi[A]: ");
        Serial.print((float)data[2],2);
        Serial.print("% | ");
        Serial.print("temp[D]: ");
        float tempD = (float)data[0]/100;
        Serial.print(tempD);
        Serial.print("*C | ");
        Serial.print("gas [A]: ");
        Serial.print(data[3]);
        Serial.print("% \n");
        delay(100);
        digitalWrite(ledPinA,LOW);
        //digitalWrite(spkrPin,HIGH);
        delay(2);
        //digitalWrite(spkrPin,LOW);
        delay(98);
      }
      radio.stopListening();
      radio.startListening();
    }
}

float getLocalTemp(){
    float t = DHT11.temperature;
    return t;
}

float getLocalHumi(){
    float h = DHT11.humidity;
    return h;
}

int getLDRvalue(){
  for(int i=0;i<=25;i++){
    LDRValue = LDRValue + analogRead(ldrPin);
    delay(4);
    }
  LDRValue = LDRValue/25;
  return LDRValue;
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The readings were static, so you were absolutely right! I moved it to Digital 4 and everything worked as it should...

This was a really badass piece of knowledge to know...
Logged

Pages: [1]   Go Up
Jump to: