Binary_switch_sleep_sensor sketch does not work
-
Hi all,
As a first step with MySensors I decided to a build binary switch sensor. I found that pull-up on Pin 2&3 does not work. And this is because all void setup() section newer executed (I added a marker Serial.println("Setup section reached "); )
Needles to say that void loop() does not work either.Here is the sketch
#define MY_NODE_ID 123
// Enable debug prints to serial monitor
#define MY_DEBUG// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69#include <SPI.h>
#include <MySensors.h>#define SKETCH_NAME "Binary Sensor"
#define SKETCH_MAJOR_VER "1"
#define SKETCH_MINOR_VER "0"#define PRIMARY_CHILD_ID 3
#define SECONDARY_CHILD_ID 4#define PRIMARY_BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch
#define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch#if (PRIMARY_BUTTON_PIN < 2 || PRIMARY_BUTTON_PIN > 3)
#error PRIMARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
#endif
#if (SECONDARY_BUTTON_PIN < 2 || SECONDARY_BUTTON_PIN > 3)
#error SECONDARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
#endif
#if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
#error PRIMARY_BUTTON_PIN and BUTTON_PIN2 cannot be the same
#endif
#if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
#error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
#endif// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);void setup()
{
Serial.println("Setup section reached ");
// Setup the buttons
pinMode(PRIMARY_BUTTON_PIN, INPUT);
pinMode(SECONDARY_BUTTON_PIN, INPUT);// Activate internal pull-ups
digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
}void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);// Register binary input sensor to sensor_node (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.
present(PRIMARY_CHILD_ID, S_DOOR);
present(SECONDARY_CHILD_ID, S_DOOR);
}// Loop will iterate on changes on the BUTTON_PINs
void loop()
{
uint8_t value;
static uint8_t sentValue=2;
static uint8_t sentValue2=2;// Short delay to allow buttons to properly settle
sleep(5);value = digitalRead(PRIMARY_BUTTON_PIN);
Serial.print("Value pin2= ");
Serial.println (value);if (value != sentValue) {
// Value has changed from last transmission, send the updated value
send(msg.set(value==HIGH ? 1 : 0));
sentValue = value;
}value = digitalRead(SECONDARY_BUTTON_PIN);
if (value != sentValue2) {
// Value has changed from last transmission, send the updated value
send(msg2.set(value==HIGH ? 1 : 0));
sentValue2 = value;
}// Sleep until something happens with the sensor
sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
}
This is the copy from Serial monitor. You can see that there is no print "Setup section reached", meaning that is not reached and program stuck somewhere in the #define section
Starting sensor (RNNNA-, 2.0.0)
TSM:INIT
TSM:RADIO:OK
TSP:ASSIGNID:OK (ID=123)
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
!TSM:FPAR:FAIL
!TSM:FAILURE
TSM:PDT
TSM:INIT
TSM:RADIO:OK
TSP:ASSIGNID:OK (ID=123)
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
!TSM:FPAR:FAIL
!TSM:FAILURE
TSM:PDT
TSM:INIT
TSM:RADIO:OK
TSP:ASSIGNID:OK (ID=123)
I have Arduino IDE 1.6.9. and updated MySensors library (2.0). The board I tested are arduino UNO and Nano, both behave the same.
Any suggestions?
-
Hi all,
As a first step with MySensors I decided to a build binary switch sensor. I found that pull-up on Pin 2&3 does not work. And this is because all void setup() section newer executed (I added a marker Serial.println("Setup section reached "); )
Needles to say that void loop() does not work either.Here is the sketch
#define MY_NODE_ID 123
// Enable debug prints to serial monitor
#define MY_DEBUG// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69#include <SPI.h>
#include <MySensors.h>#define SKETCH_NAME "Binary Sensor"
#define SKETCH_MAJOR_VER "1"
#define SKETCH_MINOR_VER "0"#define PRIMARY_CHILD_ID 3
#define SECONDARY_CHILD_ID 4#define PRIMARY_BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch
#define SECONDARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch#if (PRIMARY_BUTTON_PIN < 2 || PRIMARY_BUTTON_PIN > 3)
#error PRIMARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
#endif
#if (SECONDARY_BUTTON_PIN < 2 || SECONDARY_BUTTON_PIN > 3)
#error SECONDARY_BUTTON_PIN must be either 2 or 3 for interrupts to work
#endif
#if (PRIMARY_BUTTON_PIN == SECONDARY_BUTTON_PIN)
#error PRIMARY_BUTTON_PIN and BUTTON_PIN2 cannot be the same
#endif
#if (PRIMARY_CHILD_ID == SECONDARY_CHILD_ID)
#error PRIMARY_CHILD_ID and SECONDARY_CHILD_ID cannot be the same
#endif// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);void setup()
{
Serial.println("Setup section reached ");
// Setup the buttons
pinMode(PRIMARY_BUTTON_PIN, INPUT);
pinMode(SECONDARY_BUTTON_PIN, INPUT);// Activate internal pull-ups
digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
digitalWrite(SECONDARY_BUTTON_PIN, HIGH);
}void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);// Register binary input sensor to sensor_node (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.
present(PRIMARY_CHILD_ID, S_DOOR);
present(SECONDARY_CHILD_ID, S_DOOR);
}// Loop will iterate on changes on the BUTTON_PINs
void loop()
{
uint8_t value;
static uint8_t sentValue=2;
static uint8_t sentValue2=2;// Short delay to allow buttons to properly settle
sleep(5);value = digitalRead(PRIMARY_BUTTON_PIN);
Serial.print("Value pin2= ");
Serial.println (value);if (value != sentValue) {
// Value has changed from last transmission, send the updated value
send(msg.set(value==HIGH ? 1 : 0));
sentValue = value;
}value = digitalRead(SECONDARY_BUTTON_PIN);
if (value != sentValue2) {
// Value has changed from last transmission, send the updated value
send(msg2.set(value==HIGH ? 1 : 0));
sentValue2 = value;
}// Sleep until something happens with the sensor
sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, 0);
}
This is the copy from Serial monitor. You can see that there is no print "Setup section reached", meaning that is not reached and program stuck somewhere in the #define section
Starting sensor (RNNNA-, 2.0.0)
TSM:INIT
TSM:RADIO:OK
TSP:ASSIGNID:OK (ID=123)
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
!TSM:FPAR:FAIL
!TSM:FAILURE
TSM:PDT
TSM:INIT
TSM:RADIO:OK
TSP:ASSIGNID:OK (ID=123)
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSM:FPAR
TSP:MSG:SEND 123-123-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
!TSM:FPAR:FAIL
!TSM:FAILURE
TSM:PDT
TSM:INIT
TSM:RADIO:OK
TSP:ASSIGNID:OK (ID=123)
I have Arduino IDE 1.6.9. and updated MySensors library (2.0). The board I tested are arduino UNO and Nano, both behave the same.
Any suggestions?
-
Thanks @mfalkvidd. I don't have a gateway and home automation controller. My idea is to run a code on a gateway arduino and use MySensor libraries to transport sensors data to the GW. Will it work without a home automation controller?
-
It will work, and as long as the project just need little functionality it should be manageable. Managing a lot of functionality will be a pain though, since you won't have as nice development and debug tools available (compared to using a real controller on linux or windows machine).
You will need to hard-code node IDs for all nodes (except the gateway which always has ID 0) though, just as you have already done with #define MY_NODE_ID 123. I mention it because a lot of people have tried to get auto ID from a gateway, but that won't work since the ID assignment is done by the controller.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login