Motion &WShield fixes

This commit is contained in:
Felix Rusu 2018-05-01 17:51:27 -04:00
parent c7bddb1f78
commit cb74f772fe
2 changed files with 17 additions and 16 deletions

View File

@ -1,10 +1,10 @@
// Sample RFM69 sender/node sketch for the MotionMote // Sample RFM69 sender/node sketch for the MotionMote
// http://lowpowerlab.com/motionmote // https://lowpowerlab.com/guide/motionmote/
// PIR motion sensor connected to D3 (INT1) // PIR motion sensor connected to D3 (INT1)
// When RISE happens on D3, the sketch transmits a "MOTION" msg to receiver Moteino and goes back to sleep // When RISE happens on D3, the sketch transmits a "MOTION" msg to receiver Moteino and goes back to sleep
// In sleep mode, Moteino + PIR motion sensor use about ~60uA // In sleep mode, Moteino + PIR motion sensor use about ~60uA
// With Panasonic PIRs it's possible to use only around ~9uA, see guide link above for details
// IMPORTANT: adjust the settings in the configuration section below !!! // IMPORTANT: adjust the settings in the configuration section below !!!
// ********************************************************************************** // **********************************************************************************
// Copyright Felix Rusu of LowPowerLab.com, 2018 // Copyright Felix Rusu of LowPowerLab.com, 2018
// RFM69 library and sample code by Felix Rusu - lowpowerlab.com/contact // RFM69 library and sample code by Felix Rusu - lowpowerlab.com/contact
@ -41,9 +41,9 @@
//**************************************************************************************************************** //****************************************************************************************************************
//**** IMPORTANT RADIO SETTINGS - YOU MUST CHANGE/CONFIGURE TO MATCH YOUR HARDWARE TRANSCEIVER CONFIGURATION! **** //**** IMPORTANT RADIO SETTINGS - YOU MUST CHANGE/CONFIGURE TO MATCH YOUR HARDWARE TRANSCEIVER CONFIGURATION! ****
//**************************************************************************************************************** //****************************************************************************************************************
#define GATEWAYID 1
#define NODEID 88 //unique for each node on same network #define NODEID 88 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other #define NETWORKID 100 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one): //Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ //#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ //#define FREQUENCY RF69_868MHZ
@ -137,14 +137,13 @@ void setup() {
if (flash.initialize()) flash.sleep(); //if Moteino has FLASH-MEM, make sure it sleeps if (flash.initialize()) flash.sleep(); //if Moteino has FLASH-MEM, make sure it sleeps
#ifdef ENABLE_BME280 #ifdef ENABLE_BME280
Wire.begin(); Wire.begin();
Wire.setClock(400000); //Increase to fast I2C speed! Wire.setClock(400000); //Increase to fast I2C speed!
//initialize weather shield BME280 sensor //initialize weather shield BME280 sensor
bme280.setI2CAddress(0x77); //0x76,0x77 is valid. bme280.setI2CAddress(0x77); //0x76,0x77 is valid.
bme280.beginI2C(); bme280.beginI2C();
bme280.setMode(MODE_SLEEP); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3 bme280.setMode(MODE_FORCED); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3
bme280.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27. bme280.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27.
bme280.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4 bme280.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4
bme280.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24. bme280.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24.
@ -153,6 +152,7 @@ void setup() {
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF(); F = bme280.readTempF();
H = bme280.readFloatHumidity(); H = bme280.readFloatHumidity();
bme280.setMode(MODE_SLEEP);
#endif #endif
} }
@ -181,7 +181,7 @@ void loop() {
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF(); F = bme280.readTempF();
H = bme280.readFloatHumidity(); H = bme280.readFloatHumidity();
bme280.setMode(MODE_SLEEP);
dtostrf(F, 3,2, Fstr); dtostrf(F, 3,2, Fstr);
dtostrf(H, 3,2, Hstr); dtostrf(H, 3,2, Hstr);
dtostrf(P, 3,2, Pstr); dtostrf(P, 3,2, Pstr);
@ -215,16 +215,15 @@ void loop() {
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF(); F = bme280.readTempF();
H = bme280.readFloatHumidity(); H = bme280.readFloatHumidity();
bme280.setMode(MODE_SLEEP);
dtostrf(F, 3,2, Fstr); dtostrf(F, 3,2, Fstr);
dtostrf(H, 3,2, Hstr); dtostrf(H, 3,2, Hstr);
dtostrf(P, 3,2, Pstr); dtostrf(P, 3,2, Pstr);
sprintf(sendBuf, "BAT:%sv F:%s H:%s P:%s", BATstr, Fstr, Hstr, Pstr);
sprintf(sendBuf, "MOTION BAT:%sv F:%s H:%s P:%s", BATstr, Fstr, Hstr, Pstr);
#else #else
sprintf(sendBuf, "BAT:%sv", BATstr); sprintf(sendBuf, "BAT:%sv", BATstr);
#endif #endif
sendLen = strlen(sendBuf); sendLen = strlen(sendBuf);
BLO = time; BLO = time;
radio.sendWithRetry(GATEWAYID, sendBuf, sendLen); radio.sendWithRetry(GATEWAYID, sendBuf, sendLen);
@ -236,7 +235,7 @@ void loop() {
//while motion recently happened sleep for small slots of time to better approximate last motion event //while motion recently happened sleep for small slots of time to better approximate last motion event
//this helps with debouncing a "MOTION" event more accurately for sensors that fire the IRQ very rapidly (ie panasonic sensors) //this helps with debouncing a "MOTION" event more accurately for sensors that fire the IRQ very rapidly (ie panasonic sensors)
if (motionDetected ||motionRecentlyCycles>0) if (motionDetected || motionRecentlyCycles>0)
{ {
if (motionDetected) motionRecentlyCycles=8; if (motionDetected) motionRecentlyCycles=8;
else motionRecentlyCycles--; else motionRecentlyCycles--;
@ -268,4 +267,4 @@ void checkBattery()
batteryVolts = BATT_FORMULA(readings / 10.0); batteryVolts = BATT_FORMULA(readings / 10.0);
dtostrf(batteryVolts, 3,2, BATstr); //update the BATStr which gets sent every BATT_CYCLES or along with the MOTION message dtostrf(batteryVolts, 3,2, BATstr); //update the BATStr which gets sent every BATT_CYCLES or along with the MOTION message
} }
} }

View File

@ -2,7 +2,7 @@
// WeatherShield R2 (BME280 sensor) sameple sketch that works with Moteinos equipped with RFM69W/RFM69HW // WeatherShield R2 (BME280 sensor) sameple sketch that works with Moteinos equipped with RFM69W/RFM69HW
// It sends periodic weather readings (temp, hum, atm pressure) from WeatherShield to the base node Moteino // It sends periodic weather readings (temp, hum, atm pressure) from WeatherShield to the base node Moteino
// For use with MoteinoMEGA you will have to revisit the pin definitions defined below // For use with MoteinoMEGA you will have to revisit the pin definitions defined below
// http://www.LowPowerLab.com/WeatherShield // https://lowpowerlab.com/guide/weathershield/
// Example setup (with R1): http://lowpowerlab.com/blog/2015/07/24/attic-fan-cooling-tests/ // Example setup (with R1): http://lowpowerlab.com/blog/2015/07/24/attic-fan-cooling-tests/
// ********************************************************************************** // **********************************************************************************
// Copyright Felix Rusu 2018, http://www.LowPowerLab.com/contact // Copyright Felix Rusu 2018, http://www.LowPowerLab.com/contact
@ -137,7 +137,7 @@ void setup(void)
//initialize weather shield BME280 sensor //initialize weather shield BME280 sensor
bme280.setI2CAddress(0x77); //0x76,0x77 is valid. bme280.setI2CAddress(0x77); //0x76,0x77 is valid.
bme280.beginI2C(); bme280.beginI2C();
bme280.setMode(MODE_SLEEP); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3 bme280.setMode(MODE_FORCED); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3
bme280.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27. bme280.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27.
bme280.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4 bme280.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4
bme280.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24. bme280.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24.
@ -146,6 +146,7 @@ void setup(void)
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF(); F = bme280.readTempF();
H = bme280.readFloatHumidity(); H = bme280.readFloatHumidity();
bme280.setMode(MODE_SLEEP);
radio.sendWithRetry(GATEWAYID, "START", 6); radio.sendWithRetry(GATEWAYID, "START", 6);
Blink(LED, 100);Blink(LED, 100);Blink(LED, 100); Blink(LED, 100);Blink(LED, 100);Blink(LED, 100);
@ -189,7 +190,8 @@ void loop()
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF(); F = bme280.readTempF();
H = bme280.readFloatHumidity(); H = bme280.readFloatHumidity();
bme280.setMode(MODE_SLEEP);
dtostrf(F, 3,2, Fstr); dtostrf(F, 3,2, Fstr);
dtostrf(H, 3,2, Hstr); dtostrf(H, 3,2, Hstr);
dtostrf(P, 3,2, Pstr); dtostrf(P, 3,2, Pstr);
@ -262,4 +264,4 @@ void Blink(byte PIN, byte DELAY_MS)
delay(DELAY_MS/2); delay(DELAY_MS/2);
digitalWrite(PIN,LOW); digitalWrite(PIN,LOW);
delay(DELAY_MS/2); delay(DELAY_MS/2);
} }