I make this sketch, it is working, code may be cleaner but it's working...
Available on github : https://github.com/Gis70/MySensors/tree/master/ParkingTempHum_sensor
I make this sketch, it is working, code may be cleaner but it's working...
Available on github : https://github.com/Gis70/MySensors/tree/master/ParkingTempHum_sensor
This is my change and it is working, thank you for your help.
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Simple binary switch example
* Connect button or door/window reed switch between
* digitial I/O pin 3 (BUTTON_PIN below) and GND.
* http://www.mysensors.org/build/binary
*/
// Enable debug prints to serial monitor
//#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
#define MY_RF24_PA_LEVEL RF24_PA_LOW
#define MY_NODE_ID 8
#include <SPI.h>
#include <MySensors.h>
#include <Vcc.h>
#define CHILD_ID_MAIL 0
#define CHILD_ID_MAIL2 1
#define CHILD_ID_VOLT 2 // Child id for battery reading
#define BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch
#define BUTTON2_PIN 3 // Arduino Digital I/O pin for button/reed switch
#define SLEEP_TIME 1 * 60 * 1000UL
int oldValueC1=-1;
int oldValueC2=-1;
boolean gwSend = true;
const float VccMin = 3; // Minimum expected Vcc level, in Volts.
const float VccMax = 4; // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc
float batteryV = 0;
int batteryPcnt = 0;
Vcc vcc(VccCorrection);
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msgMail(CHILD_ID_MAIL,V_TRIPPED);
MyMessage msgMail2(CHILD_ID_MAIL2,V_TRIPPED);
MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
void setup()
{
// Setup the button
pinMode(BUTTON_PIN, INPUT);
pinMode(BUTTON2_PIN, INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);
digitalWrite(BUTTON2_PIN,HIGH);
#ifdef MY_DEBUG
Serial.begin(115200);
#endif
}
void presentation() {
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
sendSketchInfo("BAL", "1.0");
present(CHILD_ID_MAIL, S_DOOR);
present(CHILD_ID_MAIL2, S_DOOR);
present(CHILD_ID_VOLT, S_MULTIMETER);
}
// Check if digital input has changed and send in new value
void loop()
{
wait(100);
// Get the update value
uint8_t volet = digitalRead(BUTTON_PIN);
uint8_t porte = digitalRead(BUTTON2_PIN);
#ifdef MY_DEBUG
Serial.println(volet);
Serial.println(porte);
#endif
if (volet != oldValueC1) {
// Send in the new value
gwSend = true;
#ifdef MY_DEBUG
Serial.println(volet);
#endif
oldValueC1 = volet;
}
if (porte != oldValueC2) {
// Send in the new value
gwSend = true;
#ifdef MY_DEBUG
Serial.println(porte);
#endif
oldValueC2 = porte;
}
batteryV = vcc.Read_Volts();
batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
send(msgVolt.set(batteryV, 2));
sendBatteryLevel(batteryPcnt);
#ifdef MY_DEBUG
//delay(2000);
Serial.println(batteryPcnt);
#endif
if (gwSend == true) {
send(msgMail.set(volet==LOW ? 1 : 0));
send(msgMail2.set(porte==LOW ? 1 : 0));
send(msgVolt.set(batteryV, 2));
sendBatteryLevel(batteryPcnt);
gwSend = false;
}
else {
}
sleep(0, FALLING, 1, FALLING, SLEEP_TIME);
}
This is my change and it is working, thank you for your help.
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Simple binary switch example
* Connect button or door/window reed switch between
* digitial I/O pin 3 (BUTTON_PIN below) and GND.
* http://www.mysensors.org/build/binary
*/
// Enable debug prints to serial monitor
//#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
#define MY_RF24_PA_LEVEL RF24_PA_LOW
#define MY_NODE_ID 8
#include <SPI.h>
#include <MySensors.h>
#include <Vcc.h>
#define CHILD_ID_MAIL 0
#define CHILD_ID_MAIL2 1
#define CHILD_ID_VOLT 2 // Child id for battery reading
#define BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch
#define BUTTON2_PIN 3 // Arduino Digital I/O pin for button/reed switch
#define SLEEP_TIME 1 * 60 * 1000UL
int oldValueC1=-1;
int oldValueC2=-1;
boolean gwSend = true;
const float VccMin = 3; // Minimum expected Vcc level, in Volts.
const float VccMax = 4; // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc
float batteryV = 0;
int batteryPcnt = 0;
Vcc vcc(VccCorrection);
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msgMail(CHILD_ID_MAIL,V_TRIPPED);
MyMessage msgMail2(CHILD_ID_MAIL2,V_TRIPPED);
MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
void setup()
{
// Setup the button
pinMode(BUTTON_PIN, INPUT);
pinMode(BUTTON2_PIN, INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);
digitalWrite(BUTTON2_PIN,HIGH);
#ifdef MY_DEBUG
Serial.begin(115200);
#endif
}
void presentation() {
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
sendSketchInfo("BAL", "1.0");
present(CHILD_ID_MAIL, S_DOOR);
present(CHILD_ID_MAIL2, S_DOOR);
present(CHILD_ID_VOLT, S_MULTIMETER);
}
// Check if digital input has changed and send in new value
void loop()
{
wait(100);
// Get the update value
uint8_t volet = digitalRead(BUTTON_PIN);
uint8_t porte = digitalRead(BUTTON2_PIN);
#ifdef MY_DEBUG
Serial.println(volet);
Serial.println(porte);
#endif
if (volet != oldValueC1) {
// Send in the new value
gwSend = true;
#ifdef MY_DEBUG
Serial.println(volet);
#endif
oldValueC1 = volet;
}
if (porte != oldValueC2) {
// Send in the new value
gwSend = true;
#ifdef MY_DEBUG
Serial.println(porte);
#endif
oldValueC2 = porte;
}
batteryV = vcc.Read_Volts();
batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
send(msgVolt.set(batteryV, 2));
sendBatteryLevel(batteryPcnt);
#ifdef MY_DEBUG
//delay(2000);
Serial.println(batteryPcnt);
#endif
if (gwSend == true) {
send(msgMail.set(volet==LOW ? 1 : 0));
send(msgMail2.set(porte==LOW ? 1 : 0));
send(msgVolt.set(batteryV, 2));
sendBatteryLevel(batteryPcnt);
gwSend = false;
}
else {
}
sleep(0, FALLING, 1, FALLING, SLEEP_TIME);
}
Thank you both for your answer.
To resume what i want to do, i want to watch when mail is arrived in my outdoor mailbox, i will do that with 2 "door sensor".
@Nca78 if i well understood that you say, interrupt was catched and wake up arduino but value1 (the status of the "door sensor") wasn't updated and so my code doesn't do anything and it fall asleep again. Is that correct ?
I know, i just have one interrupt else i'm using 2, but it was for test with one firstly.
I will try to do in another way as you say.
thanks
Hi everybody,
I spent several time trying to detect interrupt on arduino mini pro 3.3v 8mhz with Atmega328 with button but without success. I tryed to downgrade compiler in 1.6.9 but it doesn't work neither.
If i remove sleep function it's working, but i need sleep because it a battery node for the mailbox...
Each time i press the button, i can read that in the log in the serial monitor :
2369 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
2375 MCO:SLP:TPD
2377 MCO:SLP:WUP=0
2379 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
2383 MCO:SLP:TPD
2385 MCO:SLP:WUP=0
2387 MCO:SLP:MS=0,SMS=0,I1=0,M1=1,I2=255,M2=255
2394 MCO:SLP:TPD
But nothing else.
Could someone helping me ?
Thx,
Ghislain
This is my code :
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Simple binary switch example
* Connect button or door/window reed switch between
* digitial I/O pin 3 (BUTTON_PIN below) and GND.
* http://www.mysensors.org/build/binary
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
#define MY_RF24_PA_LEVEL RF24_PA_LOW
#define MY_NODE_ID 8
#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>
#include <Vcc.h>
#define CHILD_ID_MAIL 0
#define CHILD_ID_MAIL2 1
#define CHILD_ID_VOLT 2 // Child id for battery reading
#define BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch
#define BUTTON2_PIN 3 // Arduino Digital I/O pin for button/reed switch
#define SLEEP_TIME 1 * 60 * 1000UL
// Variables' declaration
const static uint32_t COUNTER = 60; // en secondes
unsigned long sendTime = 0;
unsigned long time = 0;
Bounce debouncer = Bounce();
Bounce debouncer2 = Bounce();
int oldValueC1=-1;
int oldValueC2=-1;
boolean gwSend = true;
const float VccMin = 3; // Minimum expected Vcc level, in Volts.
const float VccMax = 4; // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0/1.0; // Measured Vcc by multimeter divided by reported Vcc
float batteryV = 0;
int batteryPcnt = 0;
Vcc vcc(VccCorrection);
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msgMail(CHILD_ID_MAIL,V_TRIPPED);
MyMessage msgMail2(CHILD_ID_MAIL2,V_TRIPPED);
MyMessage msgVolt(CHILD_ID_VOLT, V_VOLTAGE);
void setup()
{
// Setup the button
pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
// Activate internal pull-up
//digitalWrite(BUTTON_PIN,HIGH);
//digitalWrite(BUTTON2_PIN,HIGH);
// After setting up the button, setup debouncer
debouncer.attach(DIGITAL_INPUT_SENSOR);
debouncer2.attach(BUTTON2_PIN);
debouncer.interval(5);
debouncer2.interval(5);
#ifdef MY_DEBUG
Serial.begin(115200);
#endif
batteryV = vcc.Read_Volts();
batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
}
void presentation() {
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
sendSketchInfo("BAL", "1.0");
present(CHILD_ID_MAIL, S_DOOR);
present(CHILD_ID_MAIL2, S_DOOR);
present(CHILD_ID_VOLT, S_MULTIMETER);
}
// Check if digital input has changed and send in new value
void loop()
{
debouncer.update();
debouncer2.update();
// Get the update value
uint8_t value1 = debouncer.read();
uint8_t value2 = debouncer2.read();
if (value1 != oldValueC1) {
// Send in the new value
gwSend = true;
#ifdef MY_DEBUG
Serial.println(value1);
#endif
oldValueC1 = value1;
}
if (value2 != oldValueC2) {
// Send in the new value
gwSend = true;
#ifdef MY_DEBUG
Serial.println(value2);
#endif
oldValueC2 = value2;
}
// **** Re-send value every X minutes ****
time = millis()/1000;
// if(time - sendTime >= COUNTER) {
//
// batteryV = vcc.Read_Volts();
// batteryPcnt = vcc.Read_Perc(VccMin, VccMax);
//
//
// #ifdef MY_DEBUG
// delay(2000);
// Serial.println(batteryPcnt);
// #endif
//
// gwSend = true;
// sendTime = time;
// }
if (gwSend == true) {
send(msgMail.set(value1==LOW ? 1 : 0));
send(msgMail2.set(value2==LOW ? 1 : 0));
send(msgVolt.set(batteryV, 2));
sendBatteryLevel(batteryPcnt);
gwSend = false;
}
else {
}
sleep(0, CHANGE, SLEEP_TIME);
} ```
I am and you ? I can give you the sketch which is working for me with library i used.
OK, i've no further idea to help you. But i think your sensor is dead. DId you try older or newer library to compile your project ?
I supply it with 5v, are you sure it's a 3v3 version ?
It worked for a while and now it doesn't ? no problem of power supply ? 3v3 ?
Where did you buy your bmp180 ? you said the 3 you have make the same behavior ? something is wrong with the BMP sensor.
Too bad, can you upload a basic example sketch in the library adafruit to read pressure and temperature, just to be sure there is the same behavior.
Hi, i'm using this sketch and I had to modify it a little bit. But i'm at work and i haven't it.
You defined the altitude to 688 meters in you sketch, are you sure, you said you're at 1014mbars. If you're really at 700m you should be near 930mbars not 1014mbars.