Blassic I2C Mains Remote Control

Using the Remote Control Unit with the Pic I2C Slave connected to the Midge Router, it is possible to use Blassic to control regular mains devices via the the network.  Here is a sample.

The following program requires an update to the PIC I2C Slave software to set PORT B to output and the Remote Control On/Off lines connected to PORTB 0 and 1.  A 0v Line is also required between the two.  I continue to run the Mains Remote Control unit with its own 12v Battery although, the 12v supply to the router could also be used.

The following Blassic (Basic) program sets up the Router I2C software to talk to the PIC and then inputs “On or Off” from the console.  If the Response is On, PORT B0 is set high for a few seconds.  If it is ‘Off’, PORT B1 is used.

Here is the Program Listing

     10 REM Remote.bas
     11 REM Test The Mains Remote Control Via I2C
     12 REM Input On or Off then Switch the Plug On or Off
     14 REM Needs Update to PIC I2C software to Set Port B as Output
     20 REM
     30 REM I2C Control
     40 I2CAddress=34
     50 I2CData=35
     60 PIC16F876=46 : REM Address of Our Chip
     70 REM Commands
     75 PortB=1
     80 AnalogRead = 4
     90 PortA1Invert = 5 : REM Invert A1
    100 REM Begin
    105 INPUT "On or Off ",a$
    106 IF a$ = "On" THEN OnOff = 1
    107 IF a$ = "Off" THEN OnOff = 2
    110 POKE I2CAddress,PIC16F876 : REM Address the chip
    200 POKE I2CData,PortB : REM we are sending port be some data
    210 POKE I2CData,0 : REM ensure PortB All off
    220 POKE I2CData,PortB
    225 POKE I2CData,OnOff : REM Bit 0 = A1On, Bit 1 = A1Off
    230 GOSUB 800 : REM Delay long enough for the Remote Xmit
    240 POKE I2CData,PortB
    250 POKE I2CData,0 : REM and Stop Pressing Remote Buttons
    300 END
    800 FOR x=0 TO 4000: NEXT : RETURN
Ok

Update:
I was setting PORT B to 03 to turn off the power switch, ( B0 and B1 both HIGH) in error, the above code now only sets PORT B1 HIGH.

I also was getting random result trying to use a Blassic program to control the PIC 16F876a/Mains Remote from inside a shell script. That turned out to be a power problem, I’m only using a low power regulator for the 5v rail. This supplies both the USB Memory Stick, an LCD Display and the PIC Processor. When the USB Memory Stick is accessed, the power dips enough to reset the PIC Processor.

As the LCD Display was not needed for the Power Remote Control, I simply unplugged the display from the bus and the reduced power load allowed the rest of the systems to function.

I will now add a second 78L05 to the router and use that to power the bus.

This entry was posted in Blassic, I/O Bus, I2C, OpenWrt Midge and tagged , , , , . Bookmark the permalink.

Comments are closed.