Bonjour,
Je débute avec Arduino, j'aimerais pouvoir être aiguillé sur ce projet:
Je cherche à contrôler des prises électriques Chacon Ref avec ma carte arduino uno/Kit de transmission 433MHz + shield ethernet.
J'ai réussi à réceptionner les codes ON/OFF de ma télécommande avec un exemple de la librairie HomeEasy.
Et avec ce code je peux allumer et éteindre une lampe.
/*
* HE300 Automatic Protocol Transmitter 'Simulator'
*
* This demo code emits a homeeasy automatic protocol ON message
* then 3 seconds later, an off message
*
* You dont need to learn the Arduino into the socket, because it can
* pretend to be a transmitter you already have.
*
* Use the Automatic protocol reciever code above to find out
* your transmitter address 8-)
*
* *Only* tested with one HE300 transmitter (HE Address 272946) with its
* slider switch set to 1 which appears to be 0 in fact.
* Seems to work with a switch socket (HE302S) and can turn it on and off
* without the ardunio being learned into the socket.
*
* Martyn Henderson 02/10/2009 http://martgadget.blogspot.com
*
* Cheers to Barnaby and Peter, because without the code above
* that shows the receiver output this wouldnt have been possible!
*
* If you make something cool using HomeEasy and Arduino, please
* post back here with a link to your code so we can all enjoy.
*/
bool bit2[26]={}; // 26 bit global to store the HE device address.
int txPin = 2; // 433mhz transmitter on pin2
void setup()
{
pinMode(txPin, OUTPUT); // transmitter pin.
Serial.begin(9600); // console port
Serial.println("go");
itob(11833462,26); // convert our device code..
transmit(true); // send ON
delay(10); // wait (socket ignores us it appears unless we do this)
transmit(true); // send ON again
delay(3000); // wait 3 sec
transmit(false); // and off again.
delay(10);
transmit(false);
Serial.println("stop"); // done.
}
void loop()
{
// we dont use the arduino loop, this is a one-shot transmit in this example.
}
void transmit(int blnOn)
{
int i;
// Do the latch sequence..
digitalWrite(txPin, HIGH);
delayMicroseconds(275); // bit of radio shouting before we start.
digitalWrite(txPin, LOW);
delayMicroseconds(9900); // low for 9900 for latch 1
digitalWrite(txPin, HIGH); // high again
delayMicroseconds(275); // wait a moment 275
digitalWrite(txPin, LOW); // low again for 2675 - latch 2.
delayMicroseconds(2675);
// End on a high
digitalWrite(txPin, HIGH);
// Send HE Device Address..
// e.g. 1000010101000110010 272946 in binary.
for(i=0; i<26;i++)
{
sendPair(bit2[i]);
}
// Send 26th bit - group 1/0
sendPair(false);
// Send 27th bit - on/off 1/0
sendPair(blnOn);
// last 4 bits - recipient -- button 1 on the HE300 set to
// slider position I in this example:
sendPair(false);
sendPair(false);
sendPair(false);
sendPair(false);
digitalWrite(txPin, HIGH); // high again (shut up)
delayMicroseconds(275); // wait a moment
digitalWrite(txPin, LOW); // low again for 2675 - latch 2.
}
void sendBit(boolean b) {
if (b) {
digitalWrite(txPin, HIGH);
delayMicroseconds(310); //275 orinally, but tweaked.
digitalWrite(txPin, LOW);
delayMicroseconds(1340); //1225 orinally, but tweaked.
}
else {
digitalWrite(txPin, HIGH);
delayMicroseconds(310); //275 orinally, but tweaked.
digitalWrite(txPin, LOW);
delayMicroseconds(310); //275 orinally, but tweaked.
}
}
void sendPair(boolean b) {
// Send the Manchester Encoded data 01 or 10, never 11 or 00
if(b)
{
sendBit(true);
sendBit(false);
}
else
{
sendBit(false);
sendBit(true);
}
}
void itob(unsigned long integer, int length)
{ //needs bit2[length]
// Convert long device code into binary (stores in global bit2 array.)
for (int i=0; i<length; i++){
if ((integer / power2(length-1-i))==1){
integer-=power2(length-1-i);
bit2[i]=1;
}
else bit2[i]=0;
}
}
unsigned long power2(int power){ //gives 2 to the (power)
unsigned long integer=1;
for (int i=0; i<power; i++){
integer*=2;
}
return integer;
}
Maintenant, je voudrais pouvoir envoyer les codes 0N/OFF depuis une page web ou une application Android. Mais je n'arrive pas à comprendre comment faire...
Actuellement, pour éteindre ou allumer la lampe 2 par exemple, je change dans le programme la partie des 4 derniers digits en mettant 0010 FFTF. Ca marche mais comment faire pour piloter 6 boutons sans devoir changer le code à chaque fois?
Comment envoyer la commande par URL? ou encore mieux depuis une application Android directement? J'ai téléchargé l'apps DomoticHome et Arduino Control Pro mais je n'arrive pas à configurer les boutons.
J'ai regardé d'autres projets similaires mais soit cette partie n'est pas traitée soit je ne comprends pas...
Si quelqu'un pouvait m'orienter dans mes recherches?
Merci