November 23, 2024, 05:51:09 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Prop-1 RC4 controll with IR remote

Started by jgrant, October 31, 2011, 01:10:25 AM

Previous topic - Next topic

jgrant

Hi all, I just figured I would post a quick write up on how to decode IR remote signals with a Prop-1 since I didn't have much
luck on finding anything online. I wrote a few programs to switch relays with the RC4 controller using the Sony IR
protocol.  I wrote one to switch one RC4, one that switches 2 RC4's, then I decided to go big and wrote this one that will switch 28 RC4's and 112 relays all with a tv remote.

This program uses the famous Sony protocol and in order to get a Prop-1 to decode it we have to do things a bit different than we do using faster controllers.   The problem you run in to is the bs1 executes 2000 Instructions per second which equates to 1 instruction every 0.5 ms, so when you try to read the 2.4 ms sync bit you have 0.6 ms to execute the if then and pulsin statements so it ends up skipping several code pulses before the pulsin command reads its first pulse.  So what do you do, rather than using the 2.4 ms sync pulse you have to use the 20 - 30 ms low pulse between the codes to determine when to start reading pulses. This way you have the 2.4 ms pulse plus the .6 ms to run the if then and pulsin command and the first pulsin catches the first pulse.  So with the short pulses being 0.6 ms long and the bs1 executing one instruction every 0.5 ms it is just barely fast enough to read the signal but it does read it (Prop-1's ROCK).

There is one glitch with this program though, it uses the serin command to read the RC4's relay status so it knows if it needs to turn the relay off or turn it on and if you enter a 3 digit code that does not have a RC4 attached it will simply sit and wait for information that will never come requiring you to reset the controller.  Other than that the program works great, enjoy.




' =========================================================================
'   File...... Clark Grizwold Christmas light controller.bs1
'   Purpose... use a Prop-1 to toggle 112 relays on 28 RC4 controllers with a IR remote
'   Author.... Joe Grant
'   Created... 10-25-2011
'   {$STAMP BS1}
'   {$PBASIC 1.0}

' =========================================================================

' -----[ Program Description ]---------------------------------------------
'   captures signal from a IR remote using Sony protocol
'   user enters a 3 digit code from the remote
'   the first digit is the pin number 1 to 7 the RC4 is connected to
'   the second digit is the address 1 to 4 of the RC4 controller
'   the third digit is the relay number 1 to 4 the user wishes to toggle
'   IR reciever is connected to  pin0
'   RC4 controllers are daisy chained 4 per pin on pins 1 thru 7
'--------------------------------------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------


' -----[ Constants ]------------------------------------------------------

SYMBOL baud      = OT2400

' -----[ Variables ]-------------------------------------------------------

SYMBOL pulse01 = W1
SYMBOL pulse0  = B2
SYMBOL pulse1  = B3
SYMBOL pulse2  = B4
SYMBOL pulse3  = B5
SYMBOL pulse4  = B6
SYMBOL pulse5  = B7
SYMBOL code    = B8
SYMBOL counter = B9

' -----[ Program Code ]----------------------------------------------------

main:
counter = 0
  sync:
    PULSIN 0, 1, pulse01 '------------------------------' sync with IR signal
    IF pulse01 < 100 THEN sync '------------------------'
    PULSIN 0, 0, pulse0 '-------------------------------'
    PULSIN 0, 0, pulse1                                 '
    PULSIN 0, 0, pulse2                                 ' read first 6 pulses of IR signal
    PULSIN 0, 0, pulse3                                 '
    PULSIN 0, 0, pulse4                                 '
    PULSIN 0, 0, pulse5 '-------------------------------'
    pulse0 = pulse0 / 100 '-----------------------------'
    pulse1 = pulse1 / 100 * 2 + pulse0                  '
    pulse2 = pulse2 / 100 * 4 + pulse1                  ' decode IR signal
    pulse3 = pulse3 / 100 * 8 + pulse2                  '
    pulse4 = pulse4 / 100 * 16 + pulse3                 '
    pulse5 = pulse5 / 100 * 32 + pulse4 '---------------'
    LOOKUP counter, (6, 3, 3), pulse0 '-----------------' check to see if buttons pressed
    IF pulse5 > pulse0 THEN main '----------------------'       are in range, if not then reset counter
    LOOKUP counter, (0, 4, 4), pulse1 '-----------------' store button pressed into code variable
    code = code * pulse1 + pulse5 '---------------------'
    counter = counter + 1 '-----------------------------' increment the number of buttons pressed
    PAUSE 150 '-----------------------------------------' keep from reading multiple button presses
    IF counter < 3 THEN sync '--------------------------' get next button press
    pulse0 = code & $03 '-------------------------------' decode the relay number
    pulse1 = code / 4 & $03 '---------------------------' decode the RC4 address
    pulse2 = code / 16 + 1 '----------------------------' decode the pin number
    SEROUT pulse2, baud, ("!RC4", pulse1, "G") '--------' get current RC4 state
    SERIN pulse2, baud, code '--------------------------'
    LOOKUP pulse0, (1, 2, 4, 8 ), pulse0'-------------' convert relay value to relay code
    code = code ^ pulse0 '------------------------------' toggle relay
    SEROUT pulse2, baud, ("!RC4", pulse1, "S", code) '--'
GOTO main




bsnut

October 31, 2011, 02:48:46 AM #1 Last Edit: November 01, 2011, 06:27:49 AM by bsnut
Not a bad program that you did. You just gave other prop builders a cool idea for Halloween or Christmas and you have given me one as well.

William Stefan
The Basic Stamp Nut

JonnyMac

Nicely done! I would have never even thought to try SIRCS decoding (something I've done a lot of) with a Prop-1.  Kudos to you and thanks for sharing.
Jon McPhalen
EFX-TEK Hollywood Office