Shop OBEX P1 Docs P2 Docs Learn Events
Where would I find some code on handling IR Remote Control? — Parallax Forums

Where would I find some code on handling IR Remote Control?

Mark HubersMark Hubers Posts: 19
edited 2008-12-19 01:44 in General Discussion
Is there·any code out there or how-to for dealing with IR?· I am looking to record some remote control code and be able to play it back.· I was thinking of using a 555 in helping with generating the 38.5kHz that is needed to transmitt to off load the SX.· Then using the Parallax Infrared Receiver to detect the IR code.· ·Is there any good starting porint for me on doing this with the SX?·

Regards,
Mark

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-12-11 23:33
    I've attached a program that will read and decode the Sony IRCS protocol. The device/key code is displayed on a 2x16 parallel LCD (4-bit mode).
  • BeanBean Posts: 8,129
    edited 2008-12-11 23:52
    This should help too http://www.parallax.com/Portals/0/Downloads/docs/prod/sic/WebIR-%20v1.1.pdf

    You can purchase the book here http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/List/1/catpageindex/2/ProductID/149/Default.aspx?txtSearch=ir+boe-bot&SortField=ProductName%2cProductName

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • william chanwilliam chan Posts: 1,326
    edited 2008-12-12 05:47
    In my opinion, a typical remote control may send up to 400 marks and spaces per button pressed.

    If you use 16bits to measure each sample ( to sample it's duration), it would use up 800 bytes to record an IR pulse train.

    It seems the SX is lacking the ram space for the application of record and playback, unless you can implement external ram.

    The SX at 8Mhz or higher can generate the 38Khz signal without a 555, but you need to use assembly.

    Good Luck.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • Mark HubersMark Hubers Posts: 19
    edited 2008-12-12 20:20
    So much to learn when you never work at the micro level before! But what fun it is to learn it! I need a pointer on how one would get around a problem of transmiting 38 to 40 kHz IR signals that last fractions of milliseconds? I see that the FREQOUT command only let you get down to 1ms. I was thinking of using SHIFTIN and using it more like a FREQOUT command but it seem that will not work. I know the SX is fast and do not need to use a 555 to do the job of creating the 38khz and make coding easy in SXB by just sending high-lows to the 555. Am I on the right track by thinking of going this route?


    Sorry for my bad engish as it due to being hard-of-hearing and I only talk as how i hear things. Thanks for not giving me a hard time for it. [noparse]:)[/noparse]
  • BeanBean Posts: 8,129
    edited 2008-12-12 21:21
    Mark,
    You can use PAUSEUS to pause for microseconds, or you can use an interrupt. Each has it's good points and bad points.

    For 40KHz you would do in a loop (note that "LED = ~LED" will toggle the LED):

    LED = ~LED
    PAUSEUS 12.5

    Using an interrupt you would do:

    INTERRUPT 80_000 NOPRESERVE
    LED = ~LED
    RETURNINT

    If you use the interrupt you would make the LED pin an INPUT to turn off the 40KHz, and make it an OUTPUT to turn on the 40KHz.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-12-12 22:46
    The program I've attached contains the IR transmit subroutine from a bigger project I'm involved in (time lapse photography controller). As Bean suggests, one way to modulate the IR LED is by toggling the LED with the interrupt and that's what I do in my program. In my case the cathode gets the modulation signal and the anode "gates" the LED; this lets the TX_SIRCS subroutine write a bit value to the anode -- it makes things really easy.

    Most references I've found suggest that in SIRCS a device/keycode (12-bit) signal is transmitted three times, each within a 45 millisecond frame. Another element of the ISR is the frame timer.

    This may be a little advanced of your present knowledge, but I think you'll find it worth studying. Good luck and have fun.

    Post Edited (JonnyMac) : 12/12/2008 10:51:44 PM GMT
  • ZootZoot Posts: 2,227
    edited 2008-12-19 01:44
    One add to this discussion -- if you want to record/playback received sequences, it won't take much RAM, but you will need to parse the input so that you only store "new" button presses, not repeats by the IR remote. Say you want to store up to 16 consecutive IR remote button presses (16 is a nice figure because the data will fit in a single RAM bank). Not shown here is logic for a timeout and having the app decide that a full sequence has been received (i.e., if 100ms has gone by w/o a new button pressed on the remote, then consider the sequence "closed").

    
    IRseq VAR Byte(16) ' 16 button presses
    
    IRdat VAR Byte(16)
    ' -- IR tx and rx counters, frames, pulsewidths, bits here PLUS these two:
    IRseqLast VAR IRdat(14)  ' the "last" byte received by IR
    IRseqCnt VAR IRdat(15)  ' how many bytes received
    
    ' Interrupt
    
    ' Main
    
    ' pseudo code....
    
    IF newIRrx = 1 THEN ' flag from ISR
      IF IRrxByte <> IRseqLast THEN ' is it a "new" button press?
         IF IRseqCnt < 15 THEN ' stored array full?
            IRseq(IRseqCnt) = IRrxByte
            IRseqLast = IRrxByte
            INC IRseqCnt
         ENDIF
      ENDIF
    ENDIF
    
    ' now once sequence is closed, you have a count of how many bytes in the sequence, and have them in order
    ' if you want to match SIRCS, you can loop through each byte in the sequence array and transmit it 3x or whatever
    ' for playback, then reset the cnt to 0, set a flag to allow new RX, etc.
    
    ' etc
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.