NRF24 not receiving. Help needed

Hi, I am slightly new here and therefore hoping for some help.

I am trying to build a small weather station. At the one side there is a DHT 22 and a light sensor. At the other side is an oled display. Now I want to transfer the sensor data wireless to the display via 2 NRF24 modules.
The wired communication works fine, now I wanted to add the NRF24, but it seems like I am not receiving data. I was hoping, that someone might have a clue where the problem is.

Here is my Code.
Transmitter:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include "DHT.h"

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

RF24 myRadio(7,8);

const uint64_t pipe=0xE8E8F0F0E1LL;
int input = A0;

struct package // sending out a struct
{
  float humidity;
  float temperature;
  int sensorVal;
  };

typedef struct package Package;
Package data;
  
void setup() { 
 delay(1000);
 Serial.begin(9600);
 myRadio.begin();
 dht.begin();
 myRadio.setChannel(115); // RF24 supports 126 different channels
 myRadio.setPALevel(RF24_PA_MAX); // maximum transmission power
 myRadio.setDataRate(RF24_250KBPS); // transmission data rate
 myRadio.openWritingPipe(pipe);

}

void loop() {
 myRadio.write(&data,sizeof(data));

 data.humidity = dht.readHumidity();
 data.temperature = dht.readTemperature();
 data.sensorVal=analogRead(input);  

 Serial.print("\nPackage write");
 Serial.println(data.humidity);
 Serial.print("\n");
 Serial.println(data.temperature);
 Serial.println(data.sensorVal);
}

receiver

#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#define I2C_ADDRESS 0x3c
SSD1306AsciiWire oled;

RF24 myRadio(7,8);
const uint64_t pipe=0xE8E8F0F0E1LL;

int sensorWert = 0;

struct package 
{
  float humidity;
  float temperature;
  int sensorVal;
  };

typedef struct package Package; 
Package data;

void setup() {
 Serial.begin(9600);
 myRadio.begin();
 myRadio.setChannel(115); 
 myRadio.setPALevel(RF24_PA_MAX);
 myRadio.setDataRate(RF24_250KBPS);
 myRadio.openReadingPipe(1,pipe);
 myRadio.startListening();
 Wire.begin();
 Wire.setClock(400000L);
 oled.begin(&Adafruit128x64, I2C_ADDRESS);  
 delay(1000);
 }

void loop() {
  delay(2000);
  // wait for data
  if (myRadio.available()){
    while(myRadio.available()){
      myRadio.read(&data, sizeof(data));
      }
    }
  oled.setFont(System5x7);
  oled.clear();
  oled.println("humidity:");
  oled.print(data.humidity);
  oled.println("%");
  oled.println("temperature:");
  oled.print(data.temperature);
  oled.println(" degree");
  setValue(data.sensorVal);
 
 Serial.print("\nPackage read");
 Serial.println(data.humidity);
 Serial.print("\n");
 Serial.println(data.temperature);
 Serial.println(data.sensorVal);
}

void setValue(int value)
{
  int calcvalue = map(value,0,1023,0,2);
  
  switch(calcvalue){
    case 0:oled.println(" sunny"); break;
    case 1:oled.println(" cloudy"); break;
    case 2:oled.println(" night");break;
    }
  }

Thanks for the help. :slightly_smiling_face:

Why do you update the structure after sending it and not before?
So the very first packet contains zeros, why?

Delays have no place in a communication program.

You only moderate the sending process by blocking on Serial,
this will send more than the three packets that can wait in the FIFO.

Why do you overwrite all packets available and only process the very last of them?

This can have a lot of different reasons.

To narrow down the problem you should start with a nRF24-Testcode that is well known to work as expected.

take a look into robins nRF24-Tutorial

best regards Stefan

And in Robin2's tutorial there is a program to test the physical (wired) connection between a rf24 module and its attached processor. See reply #30.

The lack of adequate current capability is the number one problem with those modules. Robin2's tutorial has some hints on dealing with that, too.

Please follow the advice given in the link below when posting code , use code tags and post the code here to make it easier to read and copy for examination

thanks groundFungus, it seems like it actually was the bad wiring.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.