nRF24L01 with BMP280 and LCD 20x4 Can't Receive Data

Hi all,

this is my first question, I hope I choose the topic right.

I arrange this 2 circuits:

  1. Transmitter Circuit: Arduino Uno, nRF24L01+PA+LNA, BMP280

  2. Receiver Circuit: Arduino Uno, nRF24L01+PA+LNA, LCD I2C 20x4

I can see BMP 280 works at the transmitter circuit from the serial monitor.
The receiver circuit should have no problem too... But, the LCD in Receiver circuit can't get the data from BMP280:

Capture d’écran_2023-01-28_12-34-45

This is the transmitter code:

//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bmp; // I2C Interface

//create an RF24 object
RF24 radio(9, 10);  // CE, CSN

//struct MyData {
//  float a;
//  float t;
//  float p;
//};

//MyData data;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 2000;

//const byte address[6] = "00001"; //channel
const byte slaveAddress[5] = {'R','x','A','A','A'};

void setup() {
  
  while (!Serial);
  Serial.begin(9600); 
  Serial.println("nRF24L01 and BMP280 Project: Tx");
  Serial.println("with Arduino UNO R3 by Glanz and Freya");
  Serial.println();
  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }

  /* Default settings from datasheet. */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,    
                  Adafruit_BMP280::SAMPLING_X2,    
                  Adafruit_BMP280::SAMPLING_X16,   
                  Adafruit_BMP280::FILTER_X16,      
                  Adafruit_BMP280::STANDBY_MS_500); 

                  
  //Setup the transmitter
  radio.begin();
  radio.setDataRate(RF24_1MBPS);
  radio.setRetries(3,5);
  //radio.openWritingPipe(address);
  radio.openWritingPipe(slaveAddress);
  radio.setPALevel(RF24_PA_LOW); // set the Power Amplifier level
  // if using a higher level it is recommended to 
  // use a bypass capacitors across GND and 3.3V
  // to have more stable voltage while operating.
  radio.stopListening();
  //radio.setAutoAck(false);
  
}
void loop() {
  currentMillis = millis();
  if (currentMillis - prevMillis >= txIntervalMillis) {
    send();
    prevMillis = millis();
  }
}
int i = 1;
void send() {
  while (i>0) {
  //The "975.7" is the pressure(hPa) at sea level in day in your region
  
  float temperatureValue = bmp.readTemperature();
  float pressureValue = bmp.readPressure()/100;
  float altitudeValue = bmp.readAltitude(975.7); 
  
  if (isnan(temperatureValue) || isnan(altitudeValue) || isnan(pressureValue)){
    Serial.println(F("Failed to read from BMP280 sensor!"));
    return;
  }
  else {
      
  Serial.print(F("#  "));
  Serial.print(i);
  Serial.println();
  
  Serial.print(F("Temperature = "));
  Serial.print(temperatureValue);
  Serial.println(" °C");
  
  Serial.print(F("Pressure = "));
  Serial.print(pressureValue);
  Serial.println(" hPa");

  Serial.print(F("Approx altitude = "));
  Serial.print(altitudeValue); 
  Serial.println(" m");
  Serial.println();

  float dataToSend[3];
  dataToSend[0] = temperatureValue;
  dataToSend[1] = pressureValue;
  dataToSend[2] = altitudeValue;
    
  radio.write(&dataToSend, sizeof(dataToSend));
  }
  i++;
  delay(2000);
  }
}

the Receiver code:

//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

//create an RF24 object
RF24 radio(9, 10);  // CE, CSN

//const byte address[6] = "00001"; //channel
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

float temperatureValue;
float pressureValue;
float altitudeValue;
bool newData = false;

void setup() {
  while (!Serial);
  Serial.begin(9600);
  Serial.println("nRF24L01 and BMP280 Project: Rx");
  Serial.println("with Arduino UNO R3 by Glanz and Freya");

  lcd.init(); 
  lcd.clear(); 
  lcd.backlight(); 
  lcd.clear();
  lcd.print("Glanz");
                
  // Setup the receiver
  radio.begin();
  //radio.setPALevel(RF24_PA_LOW);
  radio.setDataRate(RF24_1MBPS);
  radio.openReadingPipe(1, thisSlaveAddress);
  radio.startListening();
  
  //set the address
  //radio.setAutoAck(false);
  //radio.setDataRate(RF24_250KBPS);
  
}

int i = 1;
void loop(){
  while (i > 0) {
  getData();
  showData();
  i++;
  }
  delay(2000);
}

void getData(){
  if (radio.available()){
    float dataToReceive[3];
    radio.read(&dataToReceive, sizeof(dataToReceive));
    
    temperatureValue = dataToReceive[0];
    pressureValue = dataToReceive[1];
    altitudeValue = dataToReceive[2];
    
    newData = true;
  }
}


void showData(){
  
  if (newData == true){ 
    Serial.print("Data received\t");
    Serial.print(F("#  "));
    Serial.print(i);
    Serial.println();
  
    Serial.print(F("Temperature = "));
    Serial.print(temperatureValue);
    Serial.println(" °C");
    
    Serial.print(F("Pressure = "));
    Serial.print(pressureValue);
    Serial.println(" hPa");
  
    Serial.print(F("Approx altitude = "));
    Serial.print(altitudeValue); 
    Serial.println(" m");
    Serial.println();

    lcd.setCursor(6,0);
    lcd.print("#: "),lcd.print(i),lcd.print(" "),lcd.print(altitudeValue),lcd.print(" m");
    lcd.setCursor(6,1), lcd.print(temperatureValue),lcd.print(" C");
    lcd.setCursor(6,2), lcd.print(pressureValue),lcd.print(" hPa");
    
    newData = false;
  }
  delay(2000);
}

Capture d’écran_2023-01-27_23-15-05

The serial Monitor for Transmitter circuit.

The transmitter circuit:

The receiver circuit:

These modules regularly need a separate 3.3V supply.

Additionally, they don't work well if they are close.

Delay in a receiving sketch will not help anything and should not occur.

2 Likes

Do I need to buy another peripheral as separate 3.3V supply?

Alright I understand to make them far away.

If you don't have one (like two AA batteries for testing), what is the alternative?

1 Like

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