bonjour,
J'ai eu qqs problèmes que j'ai fini par résoudre, je partage le code à toute fin utile.
télécommande: chacon 54760
récepteur: chacon 54798
modules rc: DIY 433MHz Wireless Transmitter + Receiving Module Superregeneration - Free shipping - DealExtreme
J'ai glaner des informations là ou j'ai pu et repris des bouts de codes offerts gracieusements par d'autres arduineur. Merci à eux.
premier code pour rechercher les signaux émis par la télécommande:
unsigned int tStart = 0;
unsigned int tl[128], th[128];
unsigned int i = 0, j = 0;
unsigned int tMin=64000, tMax=0, tMoy=0;
unsigned int t0Min=64000, t0Max=0, t1Min=64000, t1Max=0;
unsigned long before = 0;
void setup() {
pinMode(2, INPUT);
Serial.begin(9600);
}
void loop() {
tStart = pulseIn(2, LOW, 64000);
before = micros();
//starting filter
if (tStart > 2550 && tStart < 2900) {
for (i=0; i<128; i++) {
//time signal is low
tl[i] = pulseIn(2, LOW, 64000);
//time signal is high
th[i] = micros() - before - tl[i];
before = micros();
//no Serial.print here. No time for that
}
if (i == 128) {
Serial.println(tStart);
for (i=0; i<128; i++) {
if(tl[i] < tMin) tMin = tl[i];
if(tl[i] > tMax) tMax = tl[i];
}
tMoy = (tMax + tMin) / 2;
for (i=0; i<128; i++) {
if(tl[i] < tMoy) {
if(tl[i] < t0Min) t0Min = tl[i];
if(tl[i] > t0Max) t0Max = tl[i];
} else {
if(tl[i] < t1Min) t1Min = tl[i];
if(tl[i] > t1Max) t1Max = tl[i];
}
}
for (i=0; i<128; i+=2) {
for(j=0; j<2; j++){
Serial.print(th[i+j]);
Serial.print(", ");
Serial.print(tl[i+j]);
Serial.print(" : ");
}
Serial.println();
}
Serial.println();
Serial.print(t0Min);
Serial.print(", ");
Serial.println(t0Max);
Serial.print(t1Min);
Serial.print(", ");
Serial.println(t1Max);
Serial.println();
Serial.println();
tMin=64000, tMax=0;
delay(1000);
}
}
}
2eme code pour afficher le code de la télécommande, j'ai ajusté les signaux avec les résultats du précédent script:
const unsigned int RECEPT_PIN = 2; //Pin de votre recepteur 433
void setup() {
pinMode(RECEPT_PIN, INPUT);
Serial.begin(9600);
}
void loop() {
unsigned long sender = 0;
if ((sender = listenSignalDIO()) != 0) {
Serial.println(sender);
}
}
//listenSignalDIO() by bapt1080
unsigned long listenSignalDIO() {
int i = 0; //compteur boucle
unsigned long t = 0; //recepteur du delai entre 2 fronts descendant
byte prevBit = 0; //avant dernier "bit" 433 reçue
byte bit = 0; //dernier "bit" 433 reçue
unsigned long sender = 0; //code DIO au format unsigned long
t = pulseIn(RECEPT_PIN, LOW, 1000000);
if (t > 2550 && t < 2900) //déchiffrage au deuxieme cadenas du signal DIO
while (i < 64){
t = pulseIn(RECEPT_PIN, LOW, 1000000); //reception des bits
if (t > 260 && t < 450) { //si environ 310 + ou - 30 c'est un bit à 0
bit = 0;
} else if (t > 1250 && t < 1500) { //si environ 1300 + ou - 50 c'est un bit à 1
bit = 1;
} else { //sinon la série est érronnée, on sort de la fonction
Serial.print("break: ");
Serial.println(t);
break;
}
if (i % 2 == 1) { // on ne traite que les deuxièmes bits (codage manchester)
if ((prevBit ^ bit) == 0) //si faux = codage manchester KO, on sort
break;
//on stocke chaque bit dans l'unsigned long
sender <<= 1;
sender |= prevBit;
}
//on enregistre le bit précédent
prevBit = bit;
++i;
}
if (i == 64) // si on a 64 bit (i=64) on a un code DIO détecté
return sender;
return 0; //sinon pas de code DIO
}
3eme code pour le pilotage de la prise:
//see below detail of the protocol.
byte rcPin = 8;
unsigned long shiftedCode;
const unsigned int THIGH = 220, TSHORT = 350, TLONG=1400;
int val;
void setup()
{
Serial.begin(9600);
pinMode(rcPin, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
val = Serial.read();
Serial.println("transmitting...");
for (int i = 0; i < 5; i++) { // 20 cycles pour init. d'une prise
//on: 1067894928, off: 1067894912 button 1
//on: 1067894929, off: 1067894913 button 2
//on: 1067894930, off: 1067894914 button 3
//on: 1067894931, off: 1067894915
if(val == '1') {
Serial.println("on");
shiftedCode = 1067894931;
} else {
Serial.println("off");
shiftedCode = 1067894915;
}
//Sequence de verrou anoncant le départ du signal au recepeteur
digitalWrite(rcPin, HIGH);
delayMicroseconds(THIGH);
digitalWrite(rcPin, LOW);
delayMicroseconds(2675);
for (int i = 0; i < 32; i++) {
if (shiftedCode & 0x80000000L) {
digitalWrite(rcPin, HIGH);
delayMicroseconds(THIGH);
digitalWrite(rcPin, LOW);
delayMicroseconds(TLONG);
digitalWrite(rcPin, HIGH);
delayMicroseconds(THIGH);
digitalWrite(rcPin, LOW);
delayMicroseconds(TSHORT);
} else {
digitalWrite(rcPin, HIGH);
delayMicroseconds(THIGH);
digitalWrite(rcPin, LOW);
delayMicroseconds(TSHORT);
digitalWrite(rcPin, HIGH);
delayMicroseconds(THIGH);
digitalWrite(rcPin, LOW);
delayMicroseconds(TLONG);
}
shiftedCode <<= 1;
}
digitalWrite(rcPin, HIGH);
delayMicroseconds(THIGH);
digitalWrite(rcPin, LOW);
delayMicroseconds(10600);
digitalWrite(rcPin, HIGH);
delayMicroseconds(THIGH);
}
Serial.println("done");
}
}
//http://homeeasyhacking.wikia.com/wiki
//
//Device Addressing Edit
//
//To send a dimming level a special modified bit is placed
//at bit 27 (See Specification)
//
//Encoding Edit
//
//Manchester coding is used:
//Data 0 = Manchester 01 Data 1 = Manchester 10
//A Manchester 0 is a High for 275uS and Low for 275uS
//A Manchester 1 is a High for 275uS and Low for 1225uS
//So.......
//0 = High 275uS, Low 275uS, High 275uS, Low 1225uS
//1 = High 275uS, Low 1225uS, High 275uS, Low 275uS
//A preamble is sent before each command which is High 275uS, Low 2675uS
//
//When sending a dim level a special bit is placed in bit 27
//Dim bit 27 = High 275uS, Low 275uS, High 275uS, Low 275uS.
//This seems a bit odd, and goes against the manchester coding
//specification !
//
//XXXXXXXXXXXXXXXXXXXXXXXXXXX01100 (32 bits)
// bit 26, on / off
// bit 27-31, button number
le code n'est pas très documenté mais se lit facilement (je pense, il faut mettre un peu le nez dedans).
Encore merci à tous ceux qui ont contribué à déchiffrer ce protocole.