31
Web platform / Control your remote outlets (433MHz) with the web platform
After playing around with my web platform I thought I can post some code that maybe help somebody. :)
My project with the web platform is to develop new features and implement them in my actual home automation. In my living room I can control some light (12V) with a couple of MosFETs on "old" 18f97j60 ethernet board. Controlling remote outlets currently is done quite dirty. (Bit banging an PT2262 remote IC)
I knew this could be done with only one pin and much cleaner!
You can see my code at the end of this posting.
Calling the function with: send_rf(0b10010011, 0b0100);
To be honest, you need to have at least a little bit understanding how to configure the function call, but I can help you with that. ;) It's quite easy.
RF is defined as an output pin. (of course!)
Works here at my home flawless! My test rig:
To see what exacly is being sent:
The blue capture is from my PIC and the yellow one is from an original remote control! (But different keys were pressed/sent) Just to see the timing ;).
I am using this transmitter module with much power: link but standard modules like this are fine, too. If your transmitter has a RF encoder chip on it, you have to cut the "RFout" wire from it and connect your PIC with the end of the wire that goes to the circuit.
I welcome questions and/or criticism on my code. The 8 bit variable is used so I can directly control it over uart! (on my PIC12F for example)
Oh, and everybody who doesn't know what I am talking about: these thingies are remote outlets
Code: [Select]
#define FOSC 80000000LL
#define FCY (FOSC/2) // MCU is running at FCY MIPS
#include "libpic30.h"
void send_rf(char conf1, char conf2)
{
int i, j;
char conf1a, conf2a;
conf1a = conf1;
conf2a = conf2;
j = 0;
for (j=0; j<5; j++){ // repeat sending 5 times.
//This is needed by the PT2272 receiver (at least 3 times iirc)
conf1 = conf1a; // store data to send
conf2 = conf2a;
for(i=0; i<8; i++){ // parse data from conf1 and send via RF (right to left)
switch (conf1 & 0x01){ // one bit at a time!
case (0): { // send as float
RF=1;
__delay_us(300);
RF=0;
__delay_us(900);
RF=1;
__delay_us(900);
RF=0;
__delay_us(300);
break;
}
case (1): { // send as 0
RF=1;
__delay_us(300);
RF=0;
__delay_us(900);
RF=1;
__delay_us(300);
RF=0;
__delay_us(900);
break;
}
}
conf1>>=1; // shift conf1 right to parse next bit
}
for(i=0; i<4; i++){ // parse data from conf2 and send via RF
// only the lower 4 bits are needed.
switch (conf2 & 0x01){ // one bit at a time!
case (0): { // send as float
RF=1;
__delay_us(300);
RF=0;
__delay_us(900);
RF=1;
__delay_us(900);
RF=0;
__delay_us(300);
break;
}
case (1): { // send as 0
RF=1;
__delay_us(300);
RF=0;
__delay_us(900);
RF=1;
__delay_us(300);
RF=0;
__delay_us(900);
break;
}
}
conf2>>=1; // shift conf1 right to parse next bit
} // done with data, now a sync is needed.
RF=1; // sync
__delay_us(300);
RF=0;
__delay_us(9690); // weird time, I know...
}
}
Have fun with it! Hope it helps.
PS: This is not an april fools. ;)
Best regards.