I'm posting the code here because it might have some bits and pieces which will be useful to others - I'm not submitting it for inclusion in a future release.
The code is basically a home automation controller using some cheap remote control sockets I got from a supermarket a few years ago. Requires a PIC, a RTC (I've used the MCP7940N but a DS1307 would work) and an FM transmitter module on PORTD.1 .
The code is pasted below, the MCP7940N library file is attached at the bottom and there's an epic demonstration video. Merry Christmas!
;ChipSettings#chip 16F914,8#config CP=OFF, MCLRE=OFF, PWRTE=ON, WDT=OFF, OSC=INTRC_OSC_NOCLKOUT;Includefiles(Libraries)#include <MCP7940N.h>;Defines(Constants)#define LCD_IO 8#define LCD_RW PORTD.6#define LCD_RS PORTD.7#define LCD_Enable PORTD.5#define LCD_DATA_PORT PORTA#define I2C_MODE Master#define I2C_DISABLE_INTERRUPTS ON#define I2C_DATA PORTC.7#define I2C_CLOCK PORTC.6;Defines(Constants)#define TX_Period = 74 'Half length of the clock cycle in 10 microseconds. This must be an even number.#define TX_Repeat = 94 'Delay between resending signal in miliseconds;VariablesDimhrAsbyte'HourDimmnAsbyte'MinuteDimscAsbyte'SecondsDimamAsbyte'AM/PMDimlightsasByte'Current status of the lightslights=255'Set the timeMCP7940_SetTime19,14,30'Initial clock setting. RTC will remember time as long as it has power.MCP7940_Enable255'Enable the RTCCLSDoForeverLocate0,0Print" "Locate0,0DisplayTimeLocate1,0Print"Lights "Iflights=0thenPrint"OFF"ElsePrint"ON "EndIfWait500msCheckTimeLoopENDSubCheckTime'Polls the time and decides whether an event has occurred'In this case, set a variable to 255 at 16:00:00 and to 0 at 22:00:00Iflights=0Then'lights are off'Turn on when it gets to 4 PMIfhr=16thenlights=255CLSPrint"Turning on..."CMD_ON1EndIfElse'lights are on'Turn on when it gets to 10 PMIfhr=22thenCLSPrint"Turning off..."lights=0CMD_OFF1EndIfEndIfEndSubSubDisplayTime'MCP7940_ReadClock hr, mn, sc, am, day, dd, mm, yyMCP7940_ReadTimehr,mn,sc,amPrinthrLocate0,2Print":"Locate0,3PrintmnLocate0,5Print":"Locate0,6PrintscLocate0,10Ifam=0ThenPrint"AM"ElsePrint"PM"EndIfEndSubSubCMD_ON1()SetPORTC.2OnForj=1to5'send signal 5 timesFori=1to24'read 24 values from the system data tableReadTableSYSTEM,i,codesendpulse(code)NextFori=1to18'read first 7 values from the command data tableReadTableON_1,i,codesendpulse(code)NextWaitTX_RepeatmsNextSetPORTC.2OffEndSubSubCMD_OFF1()SetPORTC.2OnForj=1to5'send signal 5 timesFori=1to24'read 24 values from the system data tableReadTableSYSTEM,i,codesendpulse(code)NextFori=1to18'read first 7 values from the command data tableReadTableOFF_1,i,codesendpulse(code)NextWaitTX_RepeatmsNextSetPORTC.2OffEndSubSubSendPulse(Induration)'toggle the pulse for a set number of cyclesiflat=1thenlat=0setPORTD.1=Offelselat=1setPORTD.1=OnendifwaitTX_Period*(duration+1)10usEndSubTableSYSTEM010011010010101010101010EndTableTableON_1101010110010101101EndTableTableOFF_1101010101010101010EndTable
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I would say it is useful particularly how you have tied two of my pet topics together. Time and I2C Bus interfacing (I never seem to be able to get that to work without a struggle!) and those cheapie Remote Control Power outlets.
Could I bother you for a schematic please? I find I can follow things more easily from a drawing. Thank you for sharing your project.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Another Question. How are you managing to analysis the Data Out from the receiver in Audacity? Are you taking it in as an audio Signal? or are you using a digital oscilloscope?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'll knock up a schematic sometime soon and post it on here. There's nothing too complicated with the layout/components.
The RF signal is read as an audio signal using a 'souund card oscilloscope' (a couple of resistors and a 3.5mm jack). The left/right channel is connected to an RF receiver and the 'ground' is connected to 0V. More details here: http://rayshobby.net/?p=3381
A lot of the project is a bodge in one way or another. The main examples are:
The RF signal seems to be Manchester Code but I struggled to decode it properly so stored it as a long-pulse:short-pulse sequence (1 and 2 instead of 0 and 1).
The RTC includes an alarm which will set a pin high which can be used for interrupts but I couldn't get interrupts to work properly or the alarm to trigger properly. Instead I poll the RTC for the time every 500 ms and see if it matches the condition.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Peter,
Yes I think you are right, most of the coding in these things is Manchester, or at least a flavour of it. I have played around with Keelog RF600 Encoder/Decoders a lot which uses the same coding.
To be honest, I buy those RF Kits from boot sales for thre’pence and five Woodbines or of FleaBay take them home, whip the guts out and bin them, then put my own RC Kit into the plastic enclosures – Great Fun, making something useful and reliable from Chinese crap…
Thanks for the info on the Audacity wrinkle, can’t wait to try it out. As to the schematic, it doesn’t have to all singing and dancing, I’ve become quite used to deciphering stuff scribbled on a wet beer mat or a fag packet…
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If it's not clear, the crystal/capacitor layout is as per the datasheet for the MCP7940N. Use 100k pullups on the I2C line (82k worked too).
The RF transmitter is by quasar. It also works with a smaller, nicer one I got off eBay. I can't remember if it's AM or FM.
Good luck experimenting. It takes a bit of trial and error to get it working.
I've finally got a PIC to do something useful!
I'm posting the code here because it might have some bits and pieces which will be useful to others - I'm not submitting it for inclusion in a future release.
The code is basically a home automation controller using some cheap remote control sockets I got from a supermarket a few years ago. Requires a PIC, a RTC (I've used the MCP7940N but a DS1307 would work) and an FM transmitter module on PORTD.1 .
The code is pasted below, the MCP7940N library file is attached at the bottom and there's an epic demonstration video. Merry Christmas!
Here's the MCP7940N.h that is needed for the above code.
Nice job. Thanks for sharing.
Yes, I would say it is useful particularly how you have tied two of my pet topics together. Time and I2C Bus interfacing (I never seem to be able to get that to work without a struggle!) and those cheapie Remote Control Power outlets.
Could I bother you for a schematic please? I find I can follow things more easily from a drawing. Thank you for sharing your project.
Another Question. How are you managing to analysis the Data Out from the receiver in Audacity? Are you taking it in as an audio Signal? or are you using a digital oscilloscope?
Keith,
I'll knock up a schematic sometime soon and post it on here. There's nothing too complicated with the layout/components.
The RF signal is read as an audio signal using a 'souund card oscilloscope' (a couple of resistors and a 3.5mm jack). The left/right channel is connected to an RF receiver and the 'ground' is connected to 0V. More details here: http://rayshobby.net/?p=3381
A lot of the project is a bodge in one way or another. The main examples are:
Peter,
Yes I think you are right, most of the coding in these things is Manchester, or at least a flavour of it. I have played around with Keelog RF600 Encoder/Decoders a lot which uses the same coding.
To be honest, I buy those RF Kits from boot sales for thre’pence and five Woodbines or of FleaBay take them home, whip the guts out and bin them, then put my own RC Kit into the plastic enclosures – Great Fun, making something useful and reliable from Chinese crap…
Thanks for the info on the Audacity wrinkle, can’t wait to try it out. As to the schematic, it doesn’t have to all singing and dancing, I’ve become quite used to deciphering stuff scribbled on a wet beer mat or a fag packet…
Rough schematic attached.
If it's not clear, the crystal/capacitor layout is as per the datasheet for the MCP7940N. Use 100k pullups on the I2C line (82k worked too).
The RF transmitter is by quasar. It also works with a smaller, nicer one I got off eBay. I can't remember if it's AM or FM.
Good luck experimenting. It takes a bit of trial and error to get it working.
@Peter.
I have finally got some sample MSP7940N delivered. I have updated your .h file to cover the full set of functionality for the device.
Do you have some time for some quick tests?
Quick Command Reference: