Transmitting BMP280 data...

Good morning all, I am relatively new to working with arduinos but find it super interesting so far.
Long story short, i'm trying to send the barometric pressure sensor data from a BMP280 (apart of my GY-91 board) through an NRF24L01 transceiver to another one, where the data can be viewed and then displayed on an LED screen.

I have a working test where I can view the sensor data (temperature, pressure, and altitude) when connected to the transmitter chip that's connected to the GY-91. My issue is sending it to the receiver and having it show up. Any assistance would be greatly appreciated,
here is the test code I am basing my code off of that works:

#include <Wire.h>
#include <SPI.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
  
void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
  
  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure());
    Serial.println(" Pa");

    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}

This is the code I have been making for the transmitter:

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipeOut = 0xE8E8F0F0E1LL;

RF24 radio(9, 10); 

#include <Wire.h>
#include <SPI.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

struct MyData {
byte readTemperature;
byte readPressure;
byte readAltitude;
};

MyData data;

void resetData() {
  data.readTemperature = 0;
  data.readPressure = 0;
  data.readAltitude = 0;
}

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
  
void setup() {
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
  }

  
void loop() {
 
  radio.write(&data, sizeof(MyData));
}

And here is my code for my receiver:

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipeIn = 0xE8E8F0F0E1LL; 

RF24 radio(9, 10); 

#include <Wire.h>
#include <SPI.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C

struct MyData {
byte readTemperature;
byte readPressure;
byte readAltitude;
};

MyData data;
  
void setup() {
Serial.begin(9600); 
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);

radio.openReadingPipe(1,pipeIn);
radio.startListening();

  Serial.println(F("BMP280 test"));
  
  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}

unsigned long lastRecvTime = 0;

void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(MyData));
lastRecvTime = millis(); //here we receive the data
}
}
  
void loop() {
//recvData();
unsigned long now = millis();
//Here we check if we've lost signal, if we did we reset the values 
if ( now - lastRecvTime > 1000 ) {
// Signal lost?
}
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure());
    Serial.println(" Pa");

    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}

If you would like to see the code for my transmitter and receiver that I have working just let me know. I have a working piece of code that transmits joystick values from the transmitter to the receiver (It is for a drone I am building, trying to get the transceivers to send data both ways)

Your transmitter sketch never actually reads the bme data so it will always transmit zeros.

Your receiving sketch never actually tries to receive any data and it just displays data from the sensor, not what it received.

Maybe I'm confused?

My issue is sending it to the receiver and having it show up.

Start with a pair of programs that transmits and receives any sort of data successfully.

Add the code that reads the pressure sensor to the working transmitter code. Make changes as required for length of data packet.

blh64:
Your transmitter sketch never actually reads the bme data so it will always transmit zeros.

Your receiving sketch never actually tries to receive any data and it just displays data from the sensor, not what it received.

Maybe I'm confused?

I am still pretty new to arduinos, what command or how would I go about transmitting the bme data? and what do I need to add to receive it? Both my programs are based off of a transmitting/receiving program that I have used, so I just copied everything that looks important to the test program that reads the BMP280

JamminHyaku:
so I just copied everything that looks important

And that's where you fail: Not understanding the code and expecting someone else to fix it for you..

Danois90:
And that's where you fail: Not understanding the code and expecting someone else to fix it for you..

Im just asking for help, or some guidance. I dont know how to code, ive done lots of research, I have a general understanding. Ive never worked with transmitting signals before and its honestly above my skill level right now, sorry. I dont exactly have years of experience.
Im not asking for all the answers, but if people who actually know what there doing arent on here to help those who dont know exactly what theyre doing than I dont know why you are here other than to send useless messages like this.

Copying code is equal to not wanting to understand it. If you want to understand the code and improve your skills, you should delete whatever is in your sketch and spend some weeks reading examples and learning the C syntax and then try to piece something togheter by your self. It is highly rewarding for your brain to succeed in this! :slight_smile:

There are SOOOOOO friggin' many "newbies" who (ab)use this forum to get work done by excusing them selves as being stupid or whatever in order to have skilled programmers take mercy on them. If you do not want to do the code yourself, try the gigs and collabs section instead.

Sorry if I'm harsch, but I'm just being honest! :slight_smile:

JamminHyaku:
I am still pretty new to arduinos, what command or how would I go about transmitting the bme data? and what do I need to add to receive it? Both my programs are based off of a transmitting/receiving program that I have used, so I just copied everything that looks important to the test program that reads the BMP280

Start with relpy #2 - There are many examples of simple programs that send/receive data. look in the examples that come with the RF24 library.

Get that working. Understand how it works.
Add in the code to read your bme sensor (you already have that) and try sending/receiving that. Get that working.

If you get stuck, post your code attempt and people will help.

blh64:
Start with relpy #2 - There are many examples of simple programs that send/receive data. look in the examples that come with the RF24 library.

Get that working. Understand how it works.
Add in the code to read your bme sensor (you already have that) and try sending/receiving that. Get that working.

If you get stuck, post your code attempt and people will help.

Thank you for your reply! I have gone through a handful of the NRF library examples including the getting started and transfer programs, I think I have a decent understanding of what is happening and why in them.
What I am mostly confused about, is in the first piece of code I posted, the BMP280 example, it serial.prints "bme.readTemperature" along with pressure and altitude.
bme.readTemperature isnt really a defined variable though, so I am unsure how to transmit or receive it between the NRF chips.
I have a transmitting/receiving program where I transmit joystick values (throttle, roll, pitch, yaw), but these are all declared variables where they are defined and then transmitted.
Condensed to just one variable this is my transmitter code that has been working for me, it is the "bme." that is confusing me so much with the pressure sensor values.

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipeOut = 0xE8E8F0F0E1LL;
RF24 radio(9, 10);

struct MyData {
byte throttle;
};

void resetData() {
data.throttle = 0;
}

void setup() {
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipeOut);
resetData();
}

void loop() {
data.throttle = mapJoystickValues( analogRead(A0), 13, 524, 1015, true );

radio.write(&data, sizeof(MyData));
}

do yourself a favor:

Read "How To Use This Forum"

This is what happens when you do not

JamminHyaku:
Thank you for your reply! I have gone through a handful of the NRF library examples including the getting started and transfer programs, I think I have a decent understanding of what is happening and why in them.
What I am mostly confused about, is in the first piece of code I posted, the BMP280 example, it serial.prints "bme.readTemperature" along with pressure and altitude.
bme.readTemperature isnt really a defined variable though, so I am unsure how to transmit or receive it between the NRF chips.
I have a transmitting/receiving program where I transmit joystick values (throttle, roll, pitch, yaw), but these are all declared variables where they are defined and then transmitted.
Condensed to just one variable this is my transmitter code that has been working for me, it is the "bme." that is confusing me so much with the pressure sensor values.

"bme" is an object. It has functions associated with it. One of those functions is readTemperature(). It returns a value. The original code you posted printed that value. You can also assign that value to a variable inside your MyData structure so it will get transmitted.

And please use code tags for your code!

data.readTemperature = bme.readTemperature();
data.readPressure = bme.readPressure();
data.readAltitude = bme.readAltitude(1013.25);

Hopefully, you can see the similarity between your joystick code and this code?

blh64:
"bme" is an object. It has functions associated with it. One of those functions is readTemperature(). It returns a value. The original code you posted printed that value. You can also assign that value to a variable inside your MyData structure so it will get transmitted.

My apologies I forgot to use the code tags, this actually helps a lot in my understand though and thank you! My only question is assigning the value of bme to a variable inside the MyData structure, what I've tried doing is

struct MyData {
byte readTemperature = bme.readTemperature();
}

Although I get errors that "bme" is not declared in this scope, which is to be expected I suppose, though I haven't yet figured out how to declare an object such as bme.
If you are possibly interested in seeing what Ive come up with so far, this is my code;
Transmitter:

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipeOut = 0xE8E8F0F0E1LL;

RF24 radio(9, 10); 

#include <Wire.h>
#include <SPI.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

struct MyData {
byte readTemperature;
byte readPressure;
byte readAltitude;
};

MyData data;

void resetData() {
  data.readTemperature = 0;
  data.readPressure = 0;
  data.readAltitude = 0;
}

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);
  
void setup() {
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
  }

void loop() {
 data.readTemperature = bme.readTemperature();
 data.readPressure = bme.readPressure();
 data.readAltitude = bme.readAltitude(1013.25);
  radio.write(&data, sizeof(MyData));
}

Receiver:

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipeIn = 0xE8E8F0F0E1LL; 

RF24 radio(9, 10); 

#include <Wire.h>
#include <SPI.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C

struct MyData {
byte readTemperature;
byte readPressure;
byte readAltitude;
};

MyData data;

void resetData() {
  data.readTemperature = 0;
  data.readPressure = 0;
  data.readAltitude = 0;
}
  
void setup() {
Serial.begin(9600); 
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);

radio.openReadingPipe(1,pipeIn);
radio.startListening();

  Serial.println(F("BMP280 test"));
  
  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}

unsigned long lastRecvTime = 0;

void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(MyData));
lastRecvTime = millis(); //here we receive the data
}
}
  
void loop() {
recvData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) {
}
    Serial.print("Temperature = ");
    Serial.print(data.readTemperature);
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(data.readPressure);
    Serial.println(" Pa");

    Serial.print("Approx altitude = ");
    Serial.print(data.readAltitude);
    Serial.println(" m");
    
    Serial.println();
    delay(2000);
}

This isnt all copy/paste or referencing other programs but I am using guides to learn and understand, I have spent quite a lot of time researching and testing different options to try and get this to work, but have been having some difficulty with this which is why I decided to ask on here. I don't want people to think i'm just looking to be given the answer or am to lazy to do my own research, it can be confusing stuff to learn as a beginner however so I respect the people who understand these programs the way they do.

You are getting close. When I said to assign inside MyStruct, I meant the variable 'data' which is declared to by that type. You should sprinkle a few debug statements into your code. Also, the receiver code does not need all the BME library stuff, it is just receiving data, not reading the sensor

try this:

transmitter

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipeOut = 0xE8E8F0F0E1LL;

RF24 radio(9, 10);

#include <Wire.h>
#include <SPI.h>
#include "Adafruit_Sensor.h"
#include "Adafruit_BMP280.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10

struct MyData {
  byte readTemperature;
  byte readPressure;
  byte readAltitude;
};

MyData data;

void resetData() {
  data.readTemperature = 0;
  data.readPressure = 0;
  data.readAltitude = 0;
}

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

void setup() {
  Serial.begin(9600);
  while (!Serial);

  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);

  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }
}

void loop() {
  data.readTemperature = bme.readTemperature();
  data.readPressure = bme.readPressure();
  data.readAltitude = bme.readAltitude(1013.25);

  Serial.print( millis() );
  Serial.println( ": Sending data..." );

  Serial.print("Temperature = ");
  Serial.print(data.readTemperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(data.readPressure);
  Serial.println(" Pa");

  Serial.print("Approx altitude = ");
  Serial.print(data.readAltitude);
  Serial.println(" m");
  Serial.println();

  radio.write(&data, sizeof(MyData));
  delay(2000);
}

Receiver

#include "SPI.h"
#include "nRF24L01.h"
#include "RF24.h"
const uint64_t pipeIn = 0xE8E8F0F0E1LL;

RF24 radio(9, 10);

struct MyData {
  byte readTemperature;
  byte readPressure;
  byte readAltitude;
};

MyData data;

void resetData() {
  data.readTemperature = 0;
  data.readPressure = 0;
  data.readAltitude = 0;
}

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);

  radio.openReadingPipe(1, pipeIn);
  radio.startListening();

  Serial.println(F("BMP280 test"));
}

void loop() {

  Serial.println(F("Waiting to receive"));
  resetData();
  while ( !radio.available() ) {
    // do nothing
  }

  radio.read(&data, sizeof(MyData));

  Serial.print("Temperature = ");
  Serial.print(data.readTemperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(data.readPressure);
  Serial.println(" Pa");

  Serial.print("Approx altitude = ");
  Serial.print(data.readAltitude);
  Serial.println(" m");
  Serial.println();
}

blh64:
You are getting close. When I said to assign inside MyStruct, I meant the variable 'data' which is declared to by that type. You should sprinkle a few debug statements into your code. Also, the receiver code does not need all the BME library stuff, it is just receiving data, not reading the sensor

Upon testing the modifications, all I get is "BMP280 test, Waiting to receive"
Although it is a step up from check your wiring haha. I will continue to mess around with this and see if I can get anywhere too
I really do appreciate this assistance too, thank you.

blh64:
You are getting close. When I said to assign inside MyStruct, I meant the variable 'data' which is declared to by that type. You should sprinkle a few debug statements into your code. Also, the receiver code does not need all the BME library stuff, it is just receiving data, not reading the sensor

Ah! After some minor difficulties it appears to be working. I had to change one "bmp" to "bme", and its still got a couple issues, but I can see the results on the receiving end.
The only issues ill need to look into now is when testing the code, on the receiver or transmitter end, it only seems to run for 10-20 seconds and then stops. I'm unsure if it is losing connection or something for some reason, it just seems to stop reading the sensor. It also seems a tad erratic where the pressure jumps between 100-170 Pa, causing the altitude to jump between 55~128m
I am so glad to have something working though!

The variables below are not declared correctly. For example, altitude won't fit into a byte, unless you are within 255 meters of sea level.

struct MyData {
  byte readTemperature;
  byte readPressure;
  byte readAltitude;
};

jremington:
The variables below are not declared correctly. Altitude won't fit into a byte, unless you are within 255 meters of sea level.

This is a very good point I didn't consider.
Could this cause the resulting data to be erratic and spike?
I tested changing them to integers instead, and the altitude now is around -1800m, where as a byte it displayed roughly 55m but would jump to 180.
The degrees celsius also tends to randomly jump from 27 to 111... always to 111. So it would sort of make sense if its a bit limitation issue or something like that possible.

So it is displaying and transmitting the temperature, pressure and altitude. The only issues are every couple cycles the values jump insanely, I feel like this might be a sensor issue that can't be fixed in the code. The other issue is that after ~5 seconds the code just stops printing, I am unsure of why but Ill have to do more research and digging into it in the morning, I believe it should loop and just keep going but it without a doubt just ceases working after maybe 10 cycles.

JamminHyaku:
Ah! After some minor difficulties it appears to be working. I had to change one "bmp" to "bme", and its still got a couple issues, but I can see the results on the receiving end.
The only issues ill need to look into now is when testing the code, on the receiver or transmitter end, it only seems to run for 10-20 seconds and then stops. I'm unsure if it is losing connection or something for some reason, it just seems to stop reading the sensor. It also seems a tad erratic where the pressure jumps between 100-170 Pa, causing the altitude to jump between 55~128m
I am so glad to have something working though!

Are you still trying to send packets as fast as the microcontroler can send them? The last i looked, you had nothing to prevent you from sending data to quickly.

Also, i found with these radios, it is best to set the dynamic payload option.

Also, these radios can overpower each other, if you have then too close to each other, they can seem to stop working. To fix this adjust the PA level.

This might be something really dumb, but for some reason everything has stopped working. Without making any changes to the code or connections, the receiver end only ever shows "Waiting to receive..."

I did a continuity and voltage test on everything, the transceivers are still getting 3V, although for some reason on the receiver there is continuity between the CE pin and the other NRF pins (mosi, miso, etc)
There is no continuity here on the transmitter pins though. Would this be the issue? Where could it be coming from though?

I tried swapping the Atmega328p chip, as well as swapping the transceiver chips, the continuity is still on the receiver side so it is not the NRF chip shorted or anything I don't think. I also tried moving the whole circuit down a section on the breadboard incase for some reason there was a short in the breadboard, but it still will not work. Very frustrating as this same code and setup worked fine yesterday. Any ideas to test or anything would be vastly appreciated.