Shop OBEX P1 Docs P2 Docs Learn Events
IR Remote control — Parallax Forums

IR Remote control

CenlasoftCenlasoft Posts: 265
edited 2013-08-20 11:47 in Propeller 1
Hello,
I downloaded code IR_Remote_NewCog.spin, by Tom Doyle. I tried to modified to simple put a message on the terminal. I posted the code. Can someone help?
{{

      IR_Remote_NewCog.spin
      Tom Doyle
      2 March 2007

      The IR_Remote.spin object receives and decodes keycodes from a Sony TV remote control.
      The procedure to read and decode is run in a separate cog. This eliminates the big problem
      of the mainline program hanging while waiting for a key to be pressed. When a keycode is
      received it is written into main memory (IRcode) by the cog. See IR_Remote.spin for
      more information.

      An LED attached to pin 20 is flashed on and off in the main program loop to demonstrate
      that is does not hang waiting for someone to press a key on the remote.

      A Parallax LCD display is used to display keycode information.
      
}}
      

CON

  _CLKMODE = XTAL1 + PLL16X        ' 80 Mhz clock
  _XINFREQ = 5_000_000

  IRdetPin  =    0                   ' IR Receiver - Propeller Pin
  BaudRate  = 115200


OBJ

  ir    : "IR_Remote"
  pst   : "Parallax Serial Terminal Plus"
  num   : "simple_numbers"

VAR

  byte IRcode                                             ' keycode from IR Receiver
  
PUB Init | freq, index, cog, lcode

  pst.Start(BaudRate) 
  
    cog := ir.Start(IRdetPin, @IRcode)  ' Propeller pin connected to the IR receiver, address of variable
    if cog > 0
      repeat

        If IRcode <> ir#NoNewCode
        
          lcode := IRcode
          ir.Start(IRdetPin, @IRcode)  ' set up for next code

         case lcode
           ir#chUp  :  pst.str(string("Channel Up"))
           ir#chDn  :  pst.str(string("Channel Down"))
           ir#volUp :  pst.str(string("Volume Up"))
           ir#volDn :  pst.str(string("Volume Down"))
           ir#power :  pst.str(string("Power"))
          other    :   pst.str(string("Other Key Pressed"))

        waitcnt((clkfreq / 1000) * 30 + cnt) 
        pst.dec(lcode)


Thanks,
Curtis

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-19 13:37
    It would easier to help if you included a link to the IR object.
  • CenlasoftCenlasoft Posts: 265
    edited 2013-08-19 13:42
    Sorry for not including link to object. Here it is. Thanks
    http://obex.parallax.com/object/291
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-08-19 14:01
    I don't see any changes you made from the demo code that would keep it from working.

    I assume you're not getting any codes displayed in the terminal? (It's usually a good idea to say what results your getting and what results you expect when asking for help.)

    Are you using a Sony remote? What receiver are you using? How is it wired?
  • ratronicratronic Posts: 1,451
    edited 2013-08-19 14:34
    Curtis I found that the IRremote object starts and will return only one found remote code then lets the cog die. I have modified that object to run all of the time in the background. Try replacing your ir object with this.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-08-19 14:44
    If you're using a Sony remote I have an object that will look for a code using its own cog, so it doesn't latch your process (unless you want it to).

    -- http://obex.parallax.com/object/321
  • cavelambcavelamb Posts: 720
    edited 2013-08-20 05:06
    The only modification I see in the code posted was the line

    pst.dec(lcode)

    So I'm wondering if you are getting anything through Parallax Serial Terminal.

    Maybe review the setup and operation of that?

    Have you set the port number and baud rate?
  • ratronicratronic Posts: 1,451
    edited 2013-08-20 08:38
    I made an example using the irtest object I posted above. The irtest object starts a new a Spin cog and continuously updates the variable you start it with. It is Tom Doyle's object just modified a little.
    CON                                                                                                      
                                                                                                             
      _CLKMODE = XTAL1 + PLL16X        ' 80 Mhz clock                                                        
      _XINFREQ = 5_000_000                                                                                   
                                                                                                             
      IRdetPin  =    0                   ' IR Receiver - Propeller Pin                                       
      BaudRate  = 115200                                                                                     
                                                                                                             
                                                                                                             
    OBJ                                                                                                      
                                                                                                             
      ir    : "irtest"                                                                                       
      pst   : "Parallax Serial Terminal Plus"                                                                
      num   : "simple_numbers"                                                                               
                                                                                                             
    VAR                                                                                                      
                                                                                                             
      byte IRcode                                             ' keycode from IR Receiver                     
                                                                                                             
    PUB Init | freq, index, cog, lcode                                                                       
                                                                                                             
      pst.Start(BaudRate)                                                                                    
      ir.Start(IRdetPin, @IRcode)  ' Propeller pin connected to the IR receiver, address of variable         
                                                                                                             
      repeat                                                                                                 
                                                                                                             
        pst.char(1)                                                                                          
        case IRcode                                                                                          
          ir#chUp  :  pst.str(string("Channel Up"))                                                          
          ir#chDn  :  pst.str(string("Channel Down"))                                                        
          ir#volUp :  pst.str(string("Volume Up"))                                                           
          ir#volDn :  pst.str(string("Volume Down"))                                                         
          ir#power :  pst.str(string("Power"))                                                               
          other    :  pst.str(string("Other Key Pressed"))                                                   
        pst.chars(32, 12)                                                                                    
        pst.chars(13, 2)                                                                                     
                                                                                                             
        pst.dec(IRcode)                                                                                      
        pst.chars(32, 2)                                                                                     
                                                                                                             
        waitcnt((clkfreq / 1000) * 30 + cnt)
    
  • David BDavid B Posts: 592
    edited 2013-08-20 09:19
    It looks like that "IR_remote" code assumes 12 bits only.

    Something to be aware of, which I didn't know myself until last night when I downloaded and ran Jon's code, is that some Sony remotes send both 12 bit codes and 20 bit codes.

    My Sony AM/FM/CD/cassette audio entertainment center has a 25 button remote, and it seems that about 7 of the 25 buttons send 20 bit codes, while the rest only send 12 bit codes.
  • ratronicratronic Posts: 1,451
    edited 2013-08-20 09:39
    Tom Doyle's code ignores all but the 7 bit keycode bits because it is expecting commands from a Sony TV remote. The irtest object expects 12 bit codes. It could probably be modified to except codes from your remote.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-08-20 11:47
    Something to be aware of, which I didn't know myself until last night when I downloaded and ran Jon's code, is that some Sony remotes send both 12 bit codes and 20 bit codes.

    Yep. Combo remotes, when in DVD mode, will still send 12-bit TV codes when numbers (and some other buttons) are pressed -- probably because DVDs don't use numeric input.
Sign In or Register to comment.