243 376 läst · 1 010 svar
243k läst
1,0k svar
Bygga egna sensorer - Hemautomation
Kom på att jag glömt återkoppla här, det var jag som råkade ut för knas med LED-detektor till elmätaren, den fungerade bara när det var ljust... En vecka senare tog jag samma sensor och Nano, hämtade hem programvara mm igen för säkerhets skull och efter det fungerade den perfekt. Ingen aning om vad felet var eftersom jag programmerat andra enheter utan problem :x
Hur som helst, nu loggas en mätare via S0 och en med pulsdetektor. Den med detektor är precis som den ska vara numera känslig för omgivande ljus
Hur som helst, nu loggas en mätare via S0 och en med pulsdetektor. Den med detektor är precis som den ska vara numera känslig för omgivande ljus
Hoffan skrev:
Ja.. det är väl bara copy-pastekoding .. typ så här (har inte kollat att det går igenom kompilering). Går att göra mycket snyggare med lite loopar. Men men...
// Simple binary switch example
// Connect button or door/window reed switch between
// digitial I/O pin 3 (BUTTON_PIN below) and GND.
#include <Sensor.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <Bounce2.h>
#define BUTTON_PIN1 3 // Arduino Digital I/O pin for button/reed switch
#define BUTTON_PIN2 4 // Arduino Digital I/O pin for button/reed switch
#define BUTTON_PIN3 5 // Arduino Digital I/O pin for button/reed switch
Sensor gw;
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();
int oldValue1=-1;
int oldValue2=-1;
int oldValue3=-1;
void setup()
{
gw.begin();
pinMode(BUTTON_PIN1,INPUT);
digitalWrite(BUTTON_PIN1,HIGH);
pinMode(BUTTON_PIN2,INPUT);
digitalWrite(BUTTON_PIN2,HIGH);
pinMode(BUTTON_PIN3,INPUT);
digitalWrite(BUTTON_PIN3,HIGH);
// After setting up the button, setup debouncer
debouncer1.attach(BUTTON_PIN1);
debouncer1.interval(5);
debouncer2.attach(BUTTON_PIN2);
debouncer2.interval(5);
debouncer3.attach(BUTTON_PIN3);
debouncer3.interval(5);
// 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 below.
gw.sendSensorPresentation(BUTTON_PIN1, S_MOTION);
gw.sendSensorPresentation(BUTTON_PIN2, S_MOTION);
gw.sendSensorPresentation(BUTTON_PIN3, S_MOTION);
}
// Check if digital input has changed and send in new value
void loop()
{
debouncer1.update();
debouncer2.update();
debouncer3.update();
// Get the update value
int value = debouncer1.read();
if (value != oldValue1) {
// Send in the new value
gw.sendVariable(BUTTON_PIN1, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
oldValue1 = value;
value = debouncer2.read();
if (value != oldValue2) {
// Send in the new value
gw.sendVariable(BUTTON_PIN2, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
oldValue2 = value;
}
value = debouncer3.read();
if (value != oldValue3) {
// Send in the new value
gw.sendVariable(BUTTON_PIN3, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
oldValue3 = value;
}
}
}
hek skrev:
Jo då, den kompilerades utan problem... Men får upp tre stycken sensorer men bara den första som funkar..
Någon som har någon idee varför inclusion start & stop knappen ballar ur i Veran
grobianen skrev:
Vet inte om du tolkade mitt inlägg fel.. Alla sensorer kommer upp i Veran, Men det e bara en av dom som reagerar när jag trycker på knappen... Så dom har ju presenterats redan i veran
Hmm,jo det gjorde jag - sorry. Dock kan jag ändå rekommendera att lägga en liten delay mellan sensor-presentationerna. Det hände mig ofta att Veran bara hittade någon av sensorerna och sen fick man inkludera flera gånger tills alla dök upp. En delay hjälper då...Hoffan skrev:
Du får nog göra som Hek säger och kolla debug-utskrifterna.
Här kommer lite från debuten
Som synes så reagerar inte den på nåt när man väller pine 4 & 5 (pinne 3 funkar perfa)Started sensor.Relay=0, distance=1
Radio id stored in EEPROM was: 3
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=255,mt=0,ty=17,cr=140: 1.3b3 (541cd43)
Ack: receive timeout
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=255,mt=4,ty=7,cr=115: 0
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=0,ty=1,cr=80: 1.3b3 (541cd43)
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=4,mt=0,ty=1,cr=146: 1.3b3 (541cd43)
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=5,mt=0,ty=1,cr=215: 1.3b3 (541cd43)
Ack: receive timeout
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=241: 0
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=4,mt=1,ty=16,cr=84: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=5,mt=1,ty=16,cr=17: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=150: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=241: 0
Ack: receive timeout
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=150: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=241: 0
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=150: 1
Ack: receive timeout
Som synes så reagerar inte den på nåt när man väller pine 4 & 5 (pinne 3 funkar perfa)Started sensor.Relay=0, distance=1
Radio id stored in EEPROM was: 3
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=255,mt=0,ty=17,cr=140: 1.3b3 (541cd43)
Ack: receive timeout
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=255,mt=4,ty=7,cr=115: 0
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=0,ty=1,cr=80: 1.3b3 (541cd43)
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=4,mt=0,ty=1,cr=146: 1.3b3 (541cd43)
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=5,mt=0,ty=1,cr=215: 1.3b3 (541cd43)
Ack: receive timeout
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=241: 0
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=4,mt=1,ty=16,cr=84: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=5,mt=1,ty=16,cr=17: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=150: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=241: 0
Ack: receive timeout
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=150: 1
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=241: 0
Ack: received OK
Relaying message back to gateway.
Tx: fr=3,to=0,la=3,ne=0,ci=3,mt=1,ty=16,cr=150: 1
Ack: receive timeout
Så härgadu^ skrev:
// Example sketch showing how to control physical relays.
#include <Relay.h>
#include <Sensor.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <Bounce2.h>
#define RELAY_1 6 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1
#define RELAY_ON 0
#define RELAY_OFF 1
#define BUTTON_PIN1 3 // Arduino Digital I/O pin for button/reed switch
#define BUTTON_PIN2 4 // Arduino Digital I/O pin for button/reed switch
#define BUTTON_PIN3 5 // Arduino Digital I/O pin for button/reed switch
Sensor gw;
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();
int oldValue1=-1;
int oldValue2=-1;
int oldValue3=-1;
void setup()
{
gw.begin();
pinMode(BUTTON_PIN1,INPUT);
digitalWrite(BUTTON_PIN1,HIGH);
pinMode(BUTTON_PIN2,INPUT);
digitalWrite(BUTTON_PIN2,HIGH);
pinMode(BUTTON_PIN3,INPUT);
digitalWrite(BUTTON_PIN3,HIGH);
// After setting up the button, setup debouncer
debouncer1.attach(BUTTON_PIN1);
debouncer1.interval(5);
debouncer2.attach(BUTTON_PIN2);
debouncer2.interval(5);
debouncer3.attach(BUTTON_PIN3);
debouncer3.interval(5);
// 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 below.
gw.sendSensorPresentation(BUTTON_PIN1, S_MOTION);
gw.sendSensorPresentation(BUTTON_PIN2, S_MOTION);
gw.sendSensorPresentation(BUTTON_PIN3, S_MOTION);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Relay", "1.0");
// Register all sensors to gw (they will be created as child devices)
for (int i=0; i<NUMBER_OF_RELAYS;i++) {
gw.sendSensorPresentation(RELAY_1+i, S_LIGHT);
}
// Fetch relay status
for (int i=0; i<NUMBER_OF_RELAYS;i++) {
// Make sure relays are off when starting up
digitalWrite(RELAY_1+i, RELAY_OFF);
// Then set relay pins in output mode
pinMode(RELAY_1+i, OUTPUT);
// Request/wait for relay status
gw.getStatus(RELAY_1+i, V_LIGHT);
setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw
}
}
/*
* Example on how to asynchronously check for new messages from gw
*/
void loop()
{
debouncer1.update();
debouncer2.update();
debouncer3.update();
// Get the update value
int value = debouncer1.read();
if (value != oldValue1) {
// Send in the new value
gw.sendVariable(BUTTON_PIN1, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
oldValue1 = value;
}
value = debouncer2.read();
if (value != oldValue2) {
// Send in the new value
gw.sendVariable(BUTTON_PIN2, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
oldValue2 = value;
}
value = debouncer3.read();
if (value != oldValue3) {
// Send in the new value
gw.sendVariable(BUTTON_PIN3, V_TRIPPED, value==HIGH ? "1" : "0"); // Change to V_LIGHT if you use S_LIGHT in presentation above
oldValue3 = value;
}
if (gw.messageAvailable()) {
message_s message = gw.getMessage();
setRelayStatus(message);
}
}
void setRelayStatus(message_s message) {
if (message.header.messageType==M_SET_VARIABLE &&
message.header.type==V_LIGHT) {
int incomingRelayStatus = atoi(message.data);
// Change relay state
digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF);
// Write some debug info
Serial.print("Incoming change for relay on pin:");
Serial.print(message.header.childId);
Serial.print(", New status: ");
Serial.println(incomingRelayStatus);
}
}
Skulle bara vilja lösa min problem med att start & Stop Inclusion
inte funkar som det skall eller som jag vill... Oftast så händer inget när jag trycker på Start.
Händer inget heller när jag trycker direkt på min Gateway
inte funkar som det skall eller som jag vill... Oftast så händer inget när jag trycker på Start.
Händer inget heller när jag trycker direkt på min Gateway