Hi,
My first arduino project
Arduino MKR1400
BME280
Analog pressure sensor
powered by a 6.6Ah Li-ion
I am having some inconsistent sensor readings from the bme280.
The BME280 example code is working, so i think something in my code is not right(probably alot)
only the bme280 is connected at the moment.
this is some lines from the serial monitor:
00:56:26.596 → Temperature = nan °C
00:56:26.596 → Pressure = nan hPa
00:56:26.596 → Humidity = 100.00 %
-
00:56:35.093 → Temperature = -144.96 °C
00:56:35.093 → Pressure = 114683.02 hPa
00:56:35.093 → Humidity = nan %
Any help is appreciated
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL********"
#define BLYNK_DEVICE_NAME "Trykksensor 1"
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#include <MKRGSM.h>
#include <BlynkSimpleMKRGSM.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
float pressure; //To store the barometric pressure (Pa)
float temperature; //To store the temperature (oC)
float humidity;
GSMClient client;
GPRS gprs;
GSM gsmAccess;
BlynkTimer timer;
char auth[] = "********************";
char pin[] = "";
char apn[] = "vpn.telia.no";
char user[] = "";
char pass[] = "";
void sendAnalog()
{
// int sensorData = analogRead(A1); //reading the sensor on A1
float sensorData =(float)analogRead(A1)/1024.00*6.00;
Blynk.virtualWrite(V5,sensorData); //sending to Blynk
Serial.println(sensorData);
Serial.println();
}
void ReadSensors(){
pressure = bme.readPressure();
temperature = bme.readTemperature();
humidity = bme.readHumidity ();
Blynk.virtualWrite(V1, pressure/100);
Blynk.virtualWrite(V2, temperature);
Blynk.virtualWrite(V6, humidity);
}
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure());
Serial.println(" hPa");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, gsmAccess, gprs, client, pin, apn, user, pass);
timer.setInterval(2000L, sendAnalog);
timer.setInterval(1003L, printValues);
timer.setInterval(1007L, ReadSensors);
Serial.println(F("BME280 test"));
unsigned status;
// default settings
status = bme.begin();
// You can also pass in a Wire library object like &Wire2
// status = bme.begin(0x76, &Wire2)
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println("-- Default Test --");
Serial.println();
}
void loop()
{
//this start the blynk utilities and make run the iteration with the app
Blynk.run();
timer.run();
}