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)