Home Easy
From Frack - Hackerspace Friesland
Jump to navigationJump to searchProject: {{{Naam}}} | |
---|---|
Status | lopend |
Betrokkenen | Martijn
Martijn (Martijn) Rol: deelnemer Deskundig met: Digitale Fabricatie, Elektronica, Hydroponics, Robotica, Software, Solderen, Stappenmotor Werkt aan: Geen projecten :( |
Kennisgebied(en) | Home Easy
|
Projectoverzicht – Project toevoegen |
Home Easy protocol/zenders/ontvangers home automation
berichtopbouw
de berichtopbouw zoals het er nu uitziet is als volgt: puls pauze (extra lang) puls pauze (kort/lang afhankelijk van bitwaarde, 0 = kort, 1 = lang) ... puls
in totaal lijken de berichten 57 bits lang te zijn. De handzender zend de bovenstaande reeks minimaal 5 keer uit, waarbij mijn (arduino) ontvanger de eerste pas maar gedeeltelijk meepikt (i.v.m. autogain)
code uitlezen
de volgende code geeft via de seriele poort de ontvangen code weer:
int rxPin = 13; void setup() { pinMode(rxPin, INPUT); Serial.begin(9600); } int t; char i; void loop() { while((t < 9480 || t > 10350)) t = pulseIn(rxPin, LOW, 1000000); Serial.println(' '); Serial.print('>'); for (i = 0; i < 57; i++) { t = pulseIn(rxPin, LOW, 1000000); if ((t > 1000 && t < 1360)) Serial.print('1'); if ((t > 200 && t < 365)) Serial.print('0'); } }
timinggrenzen
korte pauze = 30 - 470 us lange pauze = 540 - 2050 us pulsbreedte = 20 - 560 us extra lange pauze = minimaal 2100 us
testcode:
int rxPin = 9; int txPin = 8; void setup() { pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); Serial.begin(9600); } int t; char code[57] = {1,1,0,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,0,1,1,0,0,1,0,1,1,1,0,1,0,1,1,0,1,0,1,1,1,0,0,1,0,0,1,0,1,1}; char cod2[57] = {1,1,0,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,0,1,1,0,0,1,0,1,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,1}; char i, j = 5; void loop() { for (j=0;j<5;j++) { digitalWrite(txPin, HIGH); delayMicroseconds(250); digitalWrite(txPin, LOW); delayMicroseconds(10000); for (i=0;i<57;i++) { digitalWrite(txPin, HIGH); delayMicroseconds(250); digitalWrite(txPin, LOW); if (code[i] == 0) delayMicroseconds(200); else delayMicroseconds(1000); } digitalWrite(txPin, HIGH); delayMicroseconds(250); digitalWrite(txPin, LOW); delayMicroseconds(10000); } delayMicroseconds(1000000); for (j=0;j<5;j++) { digitalWrite(txPin, HIGH); delayMicroseconds(250); digitalWrite(txPin, LOW); delayMicroseconds(10000); for (i=0;i<57;i++) { digitalWrite(txPin, HIGH); delayMicroseconds(250); digitalWrite(txPin, LOW); if (cod2[i] == 0) delayMicroseconds(200); else delayMicroseconds(1000); } digitalWrite(txPin, HIGH); delayMicroseconds(250); digitalWrite(txPin, LOW); delayMicroseconds(10000); } delayMicroseconds(1000000); }
interrupt based TX functie
#include "TimerOne.h" int rxPin = 9; int txPin = 8; void setup() { pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); Serial.begin(9600); Timer1.initialize(1000); Timer1.attachInterrupt(timercallback); } int t; char code[57] = {1,1,0,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,0,1,1,0,0,1,0,1,1,1,0,1,0,1,1,0,1,0,1,1,1,0,0,1,0,0,1,0,1,1}; char cod2[57] = {1,1,0,0,0,1,1,1,1,0,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0,1,0,0,1,1,0,0,1,0,1,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,0,1,0,1,1}; char *cod; volatile char statemachine = 0; char heBitcount; char heSendcount; void timercallback() { switch (statemachine) { case 1: heSendcount = 0; case 2: digitalWrite(txPin, HIGH); Timer1.setPeriod(250); statemachine = 3; heBitcount = 0; break; case 3: digitalWrite(txPin, LOW); Timer1.setPeriod(10000); statemachine = 4; break; case 4: digitalWrite(txPin, HIGH); Timer1.setPeriod(250); if (heBitcount < 57) statemachine = 5; else statemachine = 6; break; case 5: digitalWrite(txPin, LOW); if (cod[heBitcount] == 0) Timer1.setPeriod(200); else Timer1.setPeriod(1000); heBitcount++; statemachine = 4; break; case 6: digitalWrite(txPin, LOW); heSendcount++; Timer1.setPeriod(1000); if (heSendcount < 3) statemachine = 2; else statemachine = 0; break; } } void loop() { cod = code; statemachine = 1; while (statemachine != 0); delay(1000); cod = cod2; statemachine = 1; while (statemachine != 0); delay(1000); }