Bonjour à tous,
Je viens tout juste de m'inscrire car je découvre peu à peu l'univers de l'Arduino, et en parcourant ce forum j'ai vu des sujets vraiment utiles et intéressants. Comme vous vous en doutez je rencontre actuellement un petit soucis, tout bête je pense, mais qui me prend la tête depuis 2 jours.
Pour résumer la situation j'essaye actuellement d'allumer une lampe à distance à l'aide de ce dispositif : http://i4.instantgallery.de/s/su/sui/400/a3cc219426884.jpg
J'ai donc branché la partie "prise" du matos et démonté la télécommande. J''ai regardé sur internet et suis tombé sur la librarie RCSwitch, qui facilite grandement l'utilisation de ce genre de dispositif (ça permet de générer des bits très facilement à partir d'un code binaire, décimal etc.).
Egalement on peut récupérer quelques infos concernant l'émission des données. Tout est expliqué là en fait : GitHub - sui77/rc-switch: Arduino lib to operate 433/315Mhz devices like power outlet sockets.
Pour la récupération, aucun soucis ! Je branche le pin 2 de mon Arduino UNO au pin DOUT de cette puce SC5262S : http://doc.chipfind.ru/html/silan/sc5262sir.html qui est incorporée dans la télécommande.
Le problème est que je n'arrive pas à envoyer des données, la lampe ne s'allume jamais et la LED (qui signale lorsqu'il y a émission de données) ne s'allume jamais...
Mon code Arduino pour la réception :
/*
Example for receiving
http://code.google.com/p/rc-switch/
If you want to visualize a telegram copy the raw data and
paste it into http://test.sui.li/oszi/
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
Serial.println("initialisation");
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}
(output :
void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
if (decimal == 0) {
Serial.print("Unknown encoding.");
} else {
char* b = dec2binWzerofill(decimal, length);
Serial.print("Decimal: ");
Serial.print(decimal);
Serial.print(" (");
Serial.print( length );
Serial.print("Bit) Binary: ");
Serial.print( b );
Serial.print(" Tri-State: ");
Serial.print( bin2tristate( b) );
Serial.print(" PulseLength: ");
Serial.print(delay);
Serial.print(" microseconds");
Serial.print(" Protocol: ");
Serial.println(protocol);
}
Serial.print("Raw data: ");
for (int i=0; i<= length*2; i++) {
Serial.print(raw[i]);
Serial.print(",");
}
Serial.println();
Serial.println();
}
static char* bin2tristate(char* bin) {
char returnValue[50];
int pos = 0;
int pos2 = 0;
while (bin[pos]!='\0' && bin[pos+1]!='\0') {
if (bin[pos]=='0' && bin[pos+1]=='0') {
returnValue[pos2] = '0';
} else if (bin[pos]=='1' && bin[pos+1]=='1') {
returnValue[pos2] = '1';
} else if (bin[pos]=='0' && bin[pos+1]=='1') {
returnValue[pos2] = 'F';
} else {
return "not applicable";
}
pos = pos+2;
pos2++;
}
returnValue[pos2] = '\0';
return returnValue;
}
)
Et le code pour l'envoi :
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup () {
Serial.begin(9600);
mySwitch.enableTransmit(10); // pin #10
mySwitch.setRepeatTransmit(20);
delay(700);
// Optional set pulse length.
// mySwitch.setPulseLength(320);
// Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15);
}
void loop () {
// 0FFF -> groupe 1
// 0FFF -> switch
// FF -> ON
// F0 -> OFF
mySwitch.sendTriState("0FFF0FFFFFFF");
// mySwitch.switchOn(1, 1);
delay(1000);
}
Voilà, si quelqu'un a une idée je prends volontiers !!
Merci de m'avoir lu