I'm quite new here and quite new to electronics but not so much to measures.
I wired a BME280 on an ESP8266 in SPI.
Looking at the temperature data over time I have the feeling that I get a lot of "shitty" measures.
Looking at the upper part of the graph and the form that it describes I'm fine with it... but all those huge variations are wrong.
I'm taking the measure every 30 sec... read them through the code.
// Grab the current state of the sensor
float humidity_data = bme.readHumidity();
float temperature_data = bme.readTemperature();
float pressure_data = bme.readPressure();
We cannot see your code or graphs or know what BME280 module your using.
I have several and they all seem pretty consistent but I do use a rolling average code.
I uploaded also the part of the code that is pulling out temp and others.
The problem is not part of that small excerpt of the code but it may be in the large part you're hiding from us.
Have you looked at the actual values the module returned. Are the spikes just single zero (0) values returned or are that really values between 15 and 20?
Now I added a DS18b20 also to compare... and I still have a lot of "noise" especially if I compare to the DS (not speaking about the temp difference around 1degC)
I can add the full code just didn't want to pollute the post.
// Libraries
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 12 // Define GPIO
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// WiFi parameters
#define WLAN_SSID "SSID"
#define WLAN_PASS "PASS"
// Adafruit IO
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "XYGGTT"
#define AIO_KEY "blablablabala" // Obtained from account info on io.adafruit.com
// assign the ESP8266 pins to arduino pins
#define D1 5
#define D2 4
#define D4 2
#define D3 0
// assign the SPI bus to pins
#define BME_SCK D1
#define BME_MISO D4
#define BME_MOSI D2
#define BME_CS D3
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
// Setup feeds for temperature & humidity
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature");
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/humidity");
Adafruit_MQTT_Publish pressure = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/pressure");
Adafruit_MQTT_Publish temperature2 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature2");
/*************************** Sketch Code ************************************/
void setup() {
// Init sensor
bme.begin();
Serial.begin(9600);
Serial.println(F("Adafruit IO Example"));
// Connect to WiFi access point.
Serial.println(); Serial.println();
delay(10);
Serial.print(F("Connecting to "));
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println();
Serial.println(F("WiFi connected"));
Serial.println(F("IP address: "));
Serial.println(WiFi.localIP());
// connect to adafruit io
connect();
}
void loop() {
// ping adafruit io a few times to make sure we remain connected
if(! mqtt.ping(3)) {
// reconnect to adafruit io
if(! mqtt.connected())
connect();
}
// Grab the current state of the sensor
float humidity_data = bme.readHumidity();
float temperature_data = bme.readTemperature();
float pressure_data = bme.readPressure();
float temperature2_data = sensors.getTempCByIndex(0);
// By default, the temperature report is in Celsius, for Fahrenheit uncomment
// following line.
// temperature_data = temperature_data*(9.0/5.0) + 32.0;
// Publish data
if (! temperature.publish(temperature_data))
Serial.println(F("Failed to publish temperature"));
else
Serial.println(F("Temperature published!"));
Serial.println(temperature_data);
if (! humidity.publish(humidity_data))
Serial.println(F("Failed to publish humidity"));
else
Serial.println(F("Humidity published!"));
if (! pressure.publish(pressure_data))
Serial.println(F("Failed to publish pressure"));
else
Serial.println(F("Pressure published!"));
//DS Reading
sensors.requestTemperatures();
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(temperature2_data);
temperature2.publish(temperature2_data);
// Repeat every 10 seconds
delay(30000);
// ESP.deepSleep(120e6);
}
// connect to adafruit io via MQTT
void connect() {
Serial.print(F("Connecting to Adafruit IO... "));
int8_t ret;
while ((ret = mqtt.connect()) != 0) {
switch (ret) {
case 1: Serial.println(F("Wrong protocol")); break;
case 2: Serial.println(F("ID rejected")); break;
case 3: Serial.println(F("Server unavail")); break;
case 4: Serial.println(F("Bad user/pass")); break;
case 5: Serial.println(F("Not authed")); break;
case 6: Serial.println(F("Failed to subscribe")); break;
default: Serial.println(F("Connection failed")); break;
}
if(ret >= 0)
mqtt.disconnect();
Serial.println(F("Retrying connection..."));
delay(5000);
}
Serial.println(F("Adafruit IO Connected!"));
}
D3 is the same pin as serial RX0 on the ESP8266 (to my knowledge), D1 is TX0. This might interfere. Or are you using another core with different numbering?
Have you tried reading the sensor without the MQTT stuff in the sketch?
20.78 2019-01-24 19:08:51 UTC
20.81 2019-01-24 19:09:22 UTC
20.81 2019-01-24 19:09:52 UTC
20.06 2019-01-24 19:10:23 UTC
20.83 2019-01-24 19:10:53 UTC
20.04 2019-01-24 19:11:24 UTC
17.46 2019-01-24 19:11:54 UTC
20.05 2019-01-24 19:12:25 UTC
20.83 2019-01-24 19:12:55 UTC
20.85 2019-01-24 19:13:26 UTC
20.86 2019-01-24 19:13:57 UTC
20.05 2019-01-24 19:14:27 UTC
20.86 2019-01-24 19:14:58 UTC
20.87 2019-01-24 19:15:28 UTC
20.86 2019-01-24 19:15:59 UTC
20.09 2019-01-24 19:16:29 UTC
20.86 2019-01-24 19:17:00 UTC
20.17 2019-01-24 19:17:30 UTC
20.9 2019-01-24 19:18:01 UTC
20.06 2019-01-24 19:18:31 UTC
20.88 2019-01-24 19:19:02 UTC
20.07 2019-01-24 19:19:32 UTC
20.88 2019-01-24 19:20:03 UTC
20.08 2019-01-24 19:20:34 UTC
20.89 2019-01-24 19:21:04 UTC
20.87 2019-01-24 19:21:35 UTC
20.87 2019-01-24 19:22:05 UTC
20.1 2019-01-24 19:22:36 UTC
20.89 2019-01-24 19:23:06 UTC
20.88 2019-01-24 19:23:37 UTC
20.12 2019-01-24 19:24:07 UTC
20.86 2019-01-24 19:24:38 UTC
20.9 2019-01-24 19:25:08 UTC
20.1 2019-01-24 19:25:39 UTC
20.92 2019-01-24 19:26:10 UTC
20.95 2019-01-24 19:26:40 UTC
20.94 2019-01-24 19:27:11 UTC
20.94 2019-01-24 19:27:41 UTC
20.19 2019-01-24 19:28:12 UTC
20.97 2019-01-24 19:28:42 UTC
20.97 2019-01-24 19:29:13 UTC
20.99 2019-01-24 19:29:43 UTC
21 2019-01-24 19:30:14 UTC
20.21 2019-01-24 19:30:44 UTC
20.88 2019-01-24 19:31:15 UTC
20.2 2019-01-24 19:31:45 UTC
20.98 2019-01-24 19:32:16 UTC
20.99 2019-01-24 19:32:47 UTC
20.96 2019-01-24 19:33:17 UTC
21 2019-01-24 19:33:48 UTC
21 2019-01-24 19:34:18 UTC
20.25 2019-01-24 19:34:49 UTC
21 2019-01-24 19:35:19 UTC
20.2 2019-01-24 19:35:50 UTC
21.02 2019-01-24 19:36:20 UTC
21.01 2019-01-24 19:36:51 UTC
20.19 2019-01-24 19:37:21 UTC
21.01 2019-01-24 19:37:52 UTC
20.24 2019-01-24 19:38:22 UTC
21.01 2019-01-24 19:38:53 UTC
21 2019-01-24 19:39:24 UTC
20.26 2019-01-24 19:39:54 UTC
20.97 2019-01-24 19:40:25 UTC
20.21 2019-01-24 19:40:55 UTC
21 2019-01-24 19:41:26 UTC
21 2019-01-24 19:41:56 UTC
21 2019-01-24 19:42:27 UTC
21 2019-01-24 19:42:57 UTC
21.03 2019-01-24 19:43:28 UTC
20.24 2019-01-24 19:43:59 UTC
21.05 2019-01-24 19:44:29 UTC
21.04 2019-01-24 19:45:00 UTC
20.22 2019-01-24 19:45:30 UTC
20.29 2019-01-24 19:46:01 UTC
21.07 2019-01-24 19:46:31 UTC
21.08 2019-01-24 19:47:02 UTC
21.06 2019-01-24 19:47:32 UTC
21.06 2019-01-24 19:48:03 UTC
21.06 2019-01-24 19:48:33 UTC
21.06 2019-01-24 19:49:04 UTC
21.06 2019-01-24 19:49:34 UTC
21.07 2019-01-24 19:50:05 UTC
20.66 2019-01-24 19:50:36 UTC
20.32 2019-01-24 19:51:06 UTC
9.76 2019-01-24 19:51:37 UTC
21.08 2019-01-24 19:52:07 UTC
21.08 2019-01-24 19:52:38 UTC
21.07 2019-01-24 19:53:08 UTC
21.08 2019-01-24 19:53:39 UTC
21.07 2019-01-24 19:54:09 UTC
20.29 2019-01-24 19:54:40 UTC
21.03 2019-01-24 19:55:10 UTC
21.1 2019-01-24 19:55:41 UTC
20.34 2019-01-24 19:56:11 UTC
21.09 2019-01-24 19:56:42 UTC
21.09 2019-01-24 19:57:13 UTC
20.33 2019-01-24 19:57:43 UTC
21.11 2019-01-24 19:58:14 UTC
21.13 2019-01-24 19:58:44 UTC
21.15 2019-01-24 19:59:15 UTC
21.14 2019-01-24 19:59:45 UTC
21.15 2019-01-24 20:00:16 UTC
21.15 2019-01-24 20:00:46 UTC
21.18 2019-01-24 20:01:17 UTC
21.16 2019-01-24 20:01:47 UTC
21.17 2019-01-24 20:02:18 UTC
21.12 2019-01-24 20:02:48 UTC
20.39 2019-01-24 20:03:19 UTC
21.16 2019-01-24 20:03:50 UTC
20.38 2019-01-24 20:04:20 UTC
20.38 2019-01-24 20:04:51 UTC
21.16 2019-01-24 20:05:21 UTC
21.16 2019-01-24 20:05:52 UTC
20.37 2019-01-24 20:06:22 UTC
20.36 2019-01-24 20:06:53 UTC
20.41 2019-01-24 20:07:23 UTC
21.16 2019-01-24 20:07:54 UTC
21.17 2019-01-24 20:08:24 UTC
21.15 2019-01-24 20:08:55 UTC
21.17 2019-01-24 20:09:26 UTC
21.17 2019-01-24 20:09:56 UTC
21.17 2019-01-24 20:10:27 UTC
21.18 2019-01-24 20:10:57 UTC
21.14 2019-01-24 20:11:28 UTC
21.18 2019-01-24 20:11:58 UTC
20.46 2019-01-24 20:12:29 UTC
21.24 2019-01-24 20:12:59 UTC
21.22 2019-01-24 20:13:30 UTC
20.43 2019-01-24 20:14:00 UTC
Above a sample of my values.
Regarding pins I translated them for the Adafruit Huzzah Feather. I have to double check what you mentioned I'm not an expert so far.
The value here are the same that I get from reading the serial.
Agreed for the pressure. I left it from an example but I'm not using it.
The occasional bogus number could be due to the fact that the Adafruit library appears to read the temp register individually and does not do the "burst read" that is "strongly recommended" in section 4 of the datasheet. The "burst read" is recommended to avoid a "...possible mix-up of bytes belonging to different measurements..."
DaveEvans:
The occasional bogus number could be due to the fact that the Adafruit library appears to read the temp register individually and does not do the "burst read" recommended in section 4 of the datasheet. The "burst read" is recommended to avoid a "...possible mix-up of bytes belonging to different measurements..."
The simplest solution would be to modify your code to discard obvious outliers. But to verify my hypothesis about burst read, you could either find a library that does burst read (there are some around...google bme280 "burst read") or modify the Adafruit library to do it.
With my very little knowledge and all your very valuable input guys I used instead of the Huzzah a NodeMCU 1.0 and... The temp is way more stable even tough seems like 1 to 2 degC off compared to my standard thermometer.
So my simple conclusion would be that Pylon was right with the TX0 and RX0 issue.
Dave when you mentioned burst I guess a moving average could solve that also?
I'll try to document myself more on doing a moving average before sending the value
neiram44:
Dave when you mentioned burst I guess a moving average could solve that also?
You mean... would a moving average eliminate the effect of the occasional bogus value that may be due to the fact that my library does not do the 'burst read' that is highly recommended by the datasheet?
Depends on your moving average sample size, how often the outliers occur, and how far from the average the bogus values are. If the sample size is large, bogus values don't pop up very often, and they're not very far off the average, then they won't affect your average very much. Personally, I'd just discard obvious outliers (and then do averaging, if you want smoother results).
Sorry Dave, my bad writing. English is not my native language so hopefully you are here to rewrite it for me.
Anyway I got read of the "bad" data by changing board.
My question back to your point was more can we emulate the "burst read" by using moving average. But then I RTFM and realize what is called "burst read" sorry.