Making connection but not displaying data (Nrf24l01)

Hello guys I am trying to make a simple "wireless weather station" that could be expanded upon later on. (Photoresistor, Rain Level Gauge, RTC)

Here we go.

On my LCD screen after turning on both modules I am making a connection (I believe) as it displays the "now receiving"(if receive.available) but the data underneath is "0.00C 0.00%". I have tested the dht11 sensor separately and it DOES work, just doesn't want to display the data when being sent via Nrf24l01.

(Fritzing image in progress)(wasn't sure if necessary will upload when done)

2x Arduino Uno (later switching too nano for transmitter)
1x LCD 16x2 (without i2c)
1x DHT11
2x Nrf24L01 (without antenna)
2x Nrf24L01 Breakout Board

Later including:

DS3231 RTC Module.
20x2 LCD (more room)

Transmitter Code:

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

#define DHTPIN 5                // do not connect to pin 0 or pin 1
#define DHTTYPE DHT11           // Define DHT11 module
DHT dht(DHTPIN, DHTTYPE);

RF24 transmit (2,3);                            //create RF24 object called transmit
byte address [5] = {'R','x','A','A','A'};                     //set address to 00001

struct package
  {
    float temperature = 0;
    float humidity = 0;
    float light = 0; 
  };

typedef struct package Package;
Package data;


void setup(void) {
dht.begin();
  transmit.begin();
  transmit.openWritingPipe(address);            //open writing pipe to address 00001
  transmit.setPALevel(RF24_PA_MAX);             //set RF power output to maximum
  transmit.setDataRate(RF24_250KBPS);           //set datarate to 250kbps
  transmit.setChannel(100);                     //set frequency to channel 100
  transmit.stopListening();
  }

void loop(void)
{
data.temperature = dht.readTemperature();
  data.humidity = dht.readHumidity();
  transmit.write(&data,sizeof(data));
  delay(1000);
}

Receiver Code:

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

#include <LiquidCrystal.h>

const int rs = 10, en = 8, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


RF24 receive (2,3);                         
byte address [5] = {'R','x','A','A','A'};                



struct package
  {
    float temperature = 0;
    float humidity = 0;
    //float light = 0;
  };

typedef struct package Package;
Package data;

void setup(void) {
Serial.begin(9600);
receive.begin();
receive.openReadingPipe(0, address);
receive.setPALevel(RF24_PA_MAX);        
receive.setDataRate(RF24_250KBPS);      
receive.setChannel(100);  
receive.startListening();
lcd.begin(16, 2);

}

void loop(void)
{
if (receive.available())                //check when received data available
  {
    
    receive.read(&data, sizeof(data));
    lcd.setCursor(0,0);
    lcd.print("Now Receiving");
    lcd.setCursor(0,1);
    lcd.print(data.temperature);
    lcd.print("C ");
    lcd.print(data.humidity);
    lcd.print("%");
    //lcd.print(data.light);
  }
else
{

lcd.setCursor(0, 0);
lcd.print("Radio Unavailable");
lcd.clear();
}
}

I think you are using code from my Simple nRF24L01+ Tutorial

If so, have you been able to get any of my examples to work without modifying them at all? If not, that should be the first step.

...R

Robin2:
I think you are using code from my Simple nRF24L01+ Tutorial

If so, have you been able to get any of my examples to work without modifying them at all? If not, that should be the first step.

...R

That was honestly a wiring error but I've developed a new problem so I will delete this post? or add my wiring diagram and add an update to the OP?
I've have had all my Nrf24L01's talking back and forth with the hello to you etc. as soon as i got them to check :slight_smile: so its not the modules themselves I believe?

My problem NOW is its displaying the "radio unavailable" but every second you can see a ghost image of data trying to get through? and the contrast has gone wierd :confused:

It's not very clever to print "no packet" each time through loop when there is no packet available.

How many times will loop be executed on the receiver per second?
How do you expect to see one reception in that flood of junk messages?

BTW printing a message and clearing the display directly afterwards is also not too clever.

Whandall:
It's not very clever to print "no packet" each time through loop when there is no packet available.

How many times will loop be executed on the receiver per second?
How do you expect to see one reception in that flood of junk messages?

BTW printing a message and clearing the display directly afterwards is also not too clever.

What's with the hostility?

The solution may be in the answers of them questions, but I don't know. Hence why I am here.

I'm sorry for not being smart and for asking a forum of well educated and informed people of the same subject(in which I'm having trouble) for help?

Would it be possible for you (or someone who can) to help me instead of making me feel belittled?

"It's not very clever to" and "is also not too clever" I don't feel is necessary for someone who is just trying to learn and get help on their issues. "I wouldn't advise" or even "Isn't how it should be done" at least shows some attempt to "teach" without the unnecessary abuse.

And if I've got it wrong and you are just trying to help then I apologize for the defensive response. I only want help not more problems. Is that not what this forum is for?

HummingBird09:
Would it be possible for you (or someone who can) to help me instead of making me feel belittled?

There was neither hostility nor an attempt to belittle you in @Whandall's Reply #3.

What their is is a simple technical question that you have not answered - namely

How many times will loop be executed on the receiver per second?

And IMHO the purpose of that question was to get you to realize that the loop() probably repeats hundreds of times per second. Which is why you get a flood of unhelpful messages with just the ghost of useful stuff in between them.

Have you tried my examples without altering their code at all?

...R

A variant of the receiver, compiled but untested.

#include <RF24.h>
#include <DHT.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(10, 8, 4, 5, 6, 7);
RF24 receive (2, 3);
byte address [5] = {'R', 'x', 'A', 'A', 'A'};

struct Package {
  float temperature = 0;
  float humidity = 0;
} data;

void setup(void) {
  receive.begin();
  receive.openReadingPipe(0, address);
  receive.setPALevel(RF24_PA_MAX);
  receive.setDataRate(RF24_250KBPS);
  receive.setChannel(100);
  receive.startListening();
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print(F("Starting"));
}

void loop(void) {
  static uint32_t lastReceptionOrMessage;
  if (receive.available()) {
    lastReceptionOrMessage = millis();
    receive.read(&data, sizeof(data));
    lcd.setCursor(0, 0);
    lcd.print(F("Now Receiving"));
    lcd.setCursor(0, 1);
    lcd.print(data.temperature);
    lcd.print(F("C "));
    lcd.print(data.humidity);
    lcd.print(F("%"));
  } else {
    if (millis() - lastReceptionOrMessage >= 2000) {
      lastReceptionOrMessage = millis();
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(F("Radio Unavailable"));
    }
  }
}

Robin2:
the purpose of that question was to get you to realize that the loop() probably repeats hundreds of times per second. Which is why you get a flood of unhelpful messages with just the ghost of useful stuff in between them.

Thank you for your response I appreciate it, I do agree as it did make me question the problem and see it from that side as to say. I knew something wasn't right and honestly was in the dark.

Robin2:
Have you tried my examples without altering their code at all?

...R

Yes, I have made that my mandatory test when I buy new Nrf Modules :slight_smile:

Whandall:
A variant of the receiver, compiled but untested.

#include <RF24.h>

#include <DHT.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(10, 8, 4, 5, 6, 7);
RF24 receive (2, 3);
byte address [5] = {'R', 'x', 'A', 'A', 'A'};

struct Package {
  float temperature = 0;
  float humidity = 0;
} data;

void setup(void) {
  receive.begin();
  receive.openReadingPipe(0, address);
  receive.setPALevel(RF24_PA_MAX);
  receive.setDataRate(RF24_250KBPS);
  receive.setChannel(100);
  receive.startListening();
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print(F("Starting"));
}

void loop(void) {
  static uint32_t lastReceptionOrMessage;
  if (receive.available()) {
    lastReceptionOrMessage = millis();
    receive.read(&data, sizeof(data));
    lcd.setCursor(0, 0);
    lcd.print(F("Now Receiving"));
    lcd.setCursor(0, 1);
    lcd.print(data.temperature);
    lcd.print(F("C "));
    lcd.print(data.humidity);
    lcd.print(F("%"));
  } else {
    if (millis() - lastReceptionOrMessage >= 2000) {
      lastReceptionOrMessage = millis();
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(F("Radio Unavailable"));
    }
  }
}

Sorry if i took the context/tone of the last response completely wrong, I really appreciate the help!

That sketch completely sorted out my issues thank you :slight_smile:

Without trying to annoy anyone could it be explained to me in a sense?

The lastReceptionOrMessage I can understand, as if the lastReceptionOrMessage 'counter' reaches 2000 then LCD displays Unavailable. (In other words It's not trying to display everything thats being chucked at it?)

Honestly I was confused by the "F" before every display text.

 lcd.print(F("Starting"));

What happens to the text or is it treated differently when F is called beforehand?

HummingBird09:
Yes, I have made that my mandatory test when I buy new Nrf Modules :slight_smile:

The purpose of referring to my examples was so you could see how they don't print a message to say nothing has arrived.

The purpose of the F macro as in

lcd.print(F("Starting"));

is so that the text of the message is stored in program memory and does not use up the limited Arduino SRAM. Obviously that only makes sense for pieces of text that will never change.

...R

Robin2:
The purpose of referring to my examples was so you could see how they don't print a message to say nothing has arrived.

The purpose of the F macro as in

lcd.print(F("Starting"));

is so that the text of the message is stored in program memory and does not use up the limited Arduino SRAM. Obviously that only makes sense for pieces of text that will never change.

...R

Ahh I see I thought you were referring to “hello and hello back to you” my mistake, thank you for the helpful info too I understand how my problems were created and how you guys helped solve them, even if it was simple to you guys it’s helped me massively.

Ps. Would I be right in saying: I could add another sensor (or 2) to expand the data sent, comfortably?

HummingBird09:
Ps. Would I be right in saying: I could add another sensor (or 2) to expand the data sent, comfortably?

You can expand the packet structure up to 32 bytes.
With the default settings a 32 byte packet will be sent anyway,
so you will not notice any timing differences.

Whandall:
You can expand the packet structure up to 32 bytes.
With the default settings a 32 byte packet will be sent anyway,
so you will not notice any timing differences.

Thank you,
I'm having a display issue I can't recall encountering before :confused:
I thought it would display "20C" for example but they're being displayed "20.00C".

i.e. they both have a decimal with 2 digits after that aren't affected by the data (so to say).

is there anyway of getting rid of that? or is it to do with how the data package is sent/received?

I'm (annoyingly) also having an issue with my photo-resistor readings too but I don't want to open a new post (as it's one project) then alternatively I don't want to pester you guys on this post.

If it's not an issue assisting me on this I have a couple questions (under code):

#include <LiquidCrystal.h>
#include <Wire.h>
#include "DS3231.h"

int photocellPin = 1;     // the cell and 10K pulldown are connected to a1
int photocellReading;     // the analog reading from the analog resistor divider



RTClib RTC;

const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup () {
    
    Serial.begin(57600);
    Wire.begin();
     // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  
}

void loop () {
   photocellReading = analogRead(photocellPin);  
   DateTime now = RTC.now();
 
    
    lcd.setCursor(0, 0);
    lcd.print(now.day(), DEC);
    lcd.print('/');
    lcd.print(now.month(), DEC);
    lcd.print('/');
    lcd.print(now.year(), DEC);
    lcd.print(' ');
    lcd.setCursor(0, 1);
    lcd.print(now.hour(), DEC);
    lcd.print(':');
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    lcd.print(now.second(), DEC);
    
    
    lcd.setCursor(13, 0);
    if (photocellReading < 10) {
    lcd.print("Dar");
  } else if (photocellReading < 200) {
    lcd.print("Dim");
  } else if (photocellReading < 500) {
    lcd.print("Lht");
  } else if (photocellReading < 800) {
    lcd.print("Bht");
  } else {
    lcd.print("VBt");
  }

 lcd.setCursor(9, 1);
 
    
    delay(1000);
    
   
}

I'm trying to inject this code I used in my Wired Prototype of this project where the RTC (DS3231)
is displaying the date and time and my photo-resistor is displaying how bright it is via info from an "if" statement.

With the photocell reading now being sent through Nrf24l01 and being displayed within an if statement how(and where) could I add the if statement I've set up below for it to display the text results instead of number data?

The RTC Module will be on the receiver end, so how could I have it display it's data with out being effected whether devices can connect or not?

HummingBird09:
I'm having a display issue I can't recall encountering before :confused:
I thought it would display "20C" for example but they're being displayed "20.00C".

The program in Reply #12 does not print 20C or 20.00C so it is rather difficult to help.

My wild guess is that you are printing a float variable. If so the documentation for the Serial.print() function explains how to control the number of digits after the decimal point.

...R

HummingBird09:
I thought it would display "20C" for example but they're being displayed "20.00C".

i.e. they both have a decimal with 2 digits after that aren't affected by the data (so to say).

is there anyway of getting rid of that? or is it to do with how the data package is sent/received?

 lcd.print(data.temperature);

has an implicit formatting of 2 decimal digits. If you want to have it rounded to full degrees use

 lcd.print(data.temperature, 0);

Transmitter code with light

#include <RF24.h>
#include <DHT.h>

const byte photocellPin = A1;

DHT dht(5, DHT11);
RF24 transmit (2, 3);
byte address [5] = {'R', 'x', 'A', 'A', 'A'};

struct Package {
  float temperature;
  float humidity;
  uint16_t light;
} data;

void setup(void) {
  dht.begin();
  transmit.begin();
  transmit.openWritingPipe(address);
  transmit.setPALevel(RF24_PA_MAX);
  transmit.setDataRate(RF24_250KBPS);
  transmit.setChannel(100);
}

void loop(void) {
  data.temperature = dht.readTemperature();
  data.humidity = dht.readHumidity();
  data.light = analogRead(photocellPin);
  transmit.write(&data, sizeof(data));
  delay(1000);
}

I did try it like that but it's being displayed as the number, where would i put the if statement from reply #12 to convert the number into "dim" etc. I wasn't sure if it would be converted before being sent or after. and if it WAS after, how would I implement the if statement into the if receive.available statement?

I also changed light in the transmitter sketch to uint16_t.

#include <RF24.h>
#include <DHT.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(10, 8, 4, 5, 6, 7);
RF24 receive (2, 3);
byte address [5] = {'R', 'x', 'A', 'A', 'A'};

struct Package {
  float temperature;
  float humidity;
  uint16_t light;
} data;

void setup(void) {
  receive.begin();
  receive.openReadingPipe(0, address);
  receive.setPALevel(RF24_PA_MAX);
  receive.setDataRate(RF24_250KBPS);
  receive.setChannel(100);
  receive.startListening();
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print(F("Starting"));
}

void loop(void) {
  static uint32_t lastReceptionOrMessage;
  if (receive.available()) {
    lastReceptionOrMessage = millis();
    receive.read(&data, sizeof(data));
    lcd.setCursor(0, 0);
    lcd.print(F("Now Receiving"));
    lcd.setCursor(0, 1);
    lcd.print(data.temperature);
    lcd.print(F("C "));
    lcd.print(data.humidity);
    lcd.print(F("%"));
    lcd.setCursor(13, 0);
    if (data.light < 10) {
      lcd.print(F("Dar"));
    } else if (data.light < 200) {
      lcd.print(F("Dim"));
    } else if (data.light < 500) {
      lcd.print(F("Lht"));
    } else if (data.light < 800) {
      lcd.print(F("Bht"));
    } else {
      lcd.print(F("VBt"));
    }
  } else {
    if (millis() - lastReceptionOrMessage >= 2000) {
      lastReceptionOrMessage = millis();
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(F("Radio Unavailable"));
    }
  }
}

Whandall:
I also changed light in the transmitter sketch to uint16_t.

Thank you you've both been a great help!

I've got another question to do with this project didn't know whether to open a new topic and close this down?

(How easy and efficient?)
I'd like to be able to put the current transmitter(now a nano) in a loop where it sleeps for 1-2 minutes, wakes up, and seeks a connection to the receiver, if no connection sleep and repeat.

I'm sure that they'd both have to be transceivers in order for them to know they're connected.

I have no first hands experience with sleeping and power saving.

Using a Nano to build low power devices is not a good choice.
Study Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors.

I would suggest staring a new thread for the sleep stuff,
you could link to this thread in your opening post.

HummingBird09:
I'd like to be able to put the current transmitter(now a nano) in a loop where it sleeps for 1-2 minutes,
wakes up, and seeks a connection to the receiver, if no connection sleep and repeat.

You could count 150 watchdog naps (8 second max), then do your sending.
There is no connection between modules, the most you can get is a packet exchange.
What should happen if it gets an acknowledgement for its packet?

HummingBird09:
I'm sure that they'd both have to be transceivers in order for them to know they're connected.

NRF24L01 chips are transceivers.
I would keep the receiving node powered up all the time and sit there just waiting for the transmitter(s).