Dear all,
I finally get Adafruit BME280 and TSL2561 connected with Electron via the I2C wiring. If I use System.sleep(WKP, RISING, 5 * 60, SLEEP_NETWORK_STANDBY), I notice that sensors only write out correct measurements when 1st time starting the device or resting the device. The sensor can write out correct measurements by using System.sleep(SLEEP_MODE_DEEP, 5 * 60).
I prefer the SLEEP_NETWORK_STANDBY method, because sensors write out dataset frequently.
Any ideas to solve this issue?
Thanks a lot.
Here is my code:
#include "Adafruit_TSL2561_U/Adafruit_TSL2561_U.h"
#include "Adafruit_BME280/Adafruit_Sensor.h"
#include "Adafruit_BME280/Adafruit_BME280.h"
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
FuelGauge fuel; // battery
// dvices on analog pins
#define power_stepup5V D7
const String key = "2IQR9SDN4Y1X9QPR"; // Change this to your Thingspeak api write key
void setup() {
// Set Pin Modes
pinMode(power_stepup5V,OUTPUT);
// Turn on power source
digitalWrite(power_stepup5V,HIGH);
// Wait for stabilize sensors
delay(10000);
if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1) Particle.process();
}
// Setup the sensor auto-gain and integration time (fast, low resolution)
tsl.enableAutoRange(true);
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
}
void loop() {
// Turn on power source
digitalWrite(power_stepup5V,HIGH);
// Wait for stabilize sensors
delay(10000);
// BME280
float Ta = bme.readTemperature();
float Rh = bme.readHumidity();
float Pa = bme.readPressure() / 100.0F;
// TSL2561
float Lx = 0;
sensors_event_t event;
tsl.getEvent(&event);
Lx = event.light;
// LiPo
float Vol = fuel.getVCell();
// Publish data
Particle.publish("thingSpeakWrite_All", "{ \"1\": \"" + String(Ta) + "\"," +
"\"2\": \"" + String(Rh) + "\"," +
"\"3\": \"" + String(Pa) + "\"," +
"\"4\": \"" + String(Lx) + "\"," +
"\"5\": \"" + String(Vol) + "\"," +
"\"k\": \"" + key + "\" }", 60, PRIVATE);
// Give time for the message to reach ThingSpeak
for(uint ms=millis(); millis() - ms < 5000; Particle.process());
// Turn off power source
digitalWrite(power_stepup5V,LOW);
// Sleep for 5 minutes to save battery
System.sleep(WKP, RISING, 1 * 60, SLEEP_NETWORK_STANDBY);
// System.sleep(SLEEP_MODE_DEEP, 5 * 60);
}