Shop OBEX P1 Docs P2 Docs Learn Events
BS2 to BS2px — Parallax Forums

BS2 to BS2px

HumanoidoHumanoido Posts: 5,770
edited 2009-05-31 18:40 in BASIC Stamp
How to convert the timing code from BS2 to BS2px
in the attached programs?


References
IR Remote for the Boe-Bot Book, Appendix B, page 177, BS2 to BS2 IR Messages
www.parallax.com/Store/Books/EducationalTexts/tabid/181/CategoryID/66/List/0/Level/a/ProductID/149/Default.aspx?SortField=ProductName%2cProductName

IR Remote for the Boe-Bot Book v1.1 (.pdf)
www.parallax.com/Portals/0/Downloads/docs/prod/sic/WebIR-%20v1.1.pdf

IR Remote Book Source Code (.zip)
www.parallax.com/Portals/0/Downloads/src/prod/IRRemoteCode-v1.1.zip

Comments

  • StickySticky Posts: 42
    edited 2009-05-08 11:19
    Hi I'm not an expert but for PULSOUT multiply the BS2 value by 2.5 for the BS2px. The values are given in the help file for PULSOUT.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-08 11:43
    There are no PULSOUT commands in the programs.
  • StickySticky Posts: 42
    edited 2009-05-08 12:02
    Aha, well like I said I'm not an expert but the speed ratio should be about the same, sorry it didn't help.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-09 11:21
    I decided to try the two programs without converting anything-
    using the recommended two Basic Stamp 2 boards
    and a bench power supply to avoid any battery low problems.

    To my surprise, it did not work. The receiver continues to show "Pulse
    out of range, trying again..."

    Since the same message appears each time the transmitting stamp is reset,
    it looks like pulses are sent to the receiver. But the characters do not
    appear on the screen.

    I used a new IR LED from a Boe-Bot kit, and the IR Receiver included with
    the Book "IR Remote for the Boe-Bot" and checked wiring several times.

    Any idea why the original application is not working?

    Post Edited (humanoido) : 5/9/2009 12:53:25 PM GMT
  • ZootZoot Posts: 2,227
    edited 2009-05-09 15:48
    Humanoido -- there are two ways to convert timing:

    - use conditional compilation to set up constants for converting RCTIME, PULSIN, PULSOUT parameters to microseconds (us) -- personally, I think this is best as it brings clarity. Then you'll need to do a tiny bit of work converting the "magic number" RCTIME/PULSIN material in the IR texts to us (for example if a SIRCS IR start is 1.2ms, that's 1200 us).

    - check your Pbasic manual and calculate the ratio to convert (and use) the magic numbers:
    BS2px = .75us units
    BS2 = 2 us units

    2/.75 = 2.66

    I don't have the IR text in front of me, but I think it was values like 300 for .6ms, etc. So you'd multiply 300 * 2.66 to get equivalent RCTIME units for the BS2px. Method one is really better because then your code will be utterly portable, e.g.

    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
          RCadj CON $200 ' use with */
      #CASE BS2SX
          RCadj CON $0CC
      #CASE BS2P, BS2PX
         RCadj CON $0C0
    #ENDSELECT
    
    RCTIME myPin, 1, myResult
    myResult = myResult */ RCadj ' now it's in microseconds, regardless of controller
    IF myResult > 500 THEN
       DEBUG "myResult is > than .5ms"
    ELSE
       DEBUG "myResult is <= .5ms"
    ENDIF
    
    



    As to why the orig. programs are not working on BS2s -- can you post actual code?

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

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • ZootZoot Posts: 2,227
    edited 2009-05-09 23:34
    Hmmm. Seems like you should get something. Of course, you won't get a message on the RX side until after both units are powered up AND you've hit reset on the TX side at least once.

    This part makes no sense, however. But I would still think you'd get a good character on the RX side.

    READ eeChars, character  ' reads the "a"
    IF character < "a" OR character > "z" THEN character = "a"
    character = character + 1  ' now makes it a "b"
    WRITE eeChars, character  ' then writes it where the "a" was
    
    ' -----[noparse][[/noparse] Main Routine ]----------------------------------------------------
    
    irMessage = character - 1  ' now makes it an "a" again, but not because it was read
    GOSUB Transmit_Ir_Byte  ' send it
    
    

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

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • SRLMSRLM Posts: 5,045
    edited 2009-05-10 00:21
    There was a thread recently(<6 months) that dealt with this issue and laid it out from one of the Parallax guys. You may have luck finding it in the Stamps in Class forum.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-10 17:52
    Agreed, it's a very simple circuit, it seems it should work,
    but it does not work. Does anyone have two BS2 boards to
    test the software?

    Post Edited (humanoido) : 5/11/2009 10:04:10 AM GMT
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-11 10:02
    SRLM, thanks for the memory jog about the thread in the
    education forum that explains how to convert from BS2
    to BS2px. This will be very helpful, after I can show the
    code runs with two Basic Stamp 2 boards.

    Here's the link where this fine tutorial by Andy Lindsay, of
    Parallax, is located.

    http://forums.parallax.com/showthread.php?p=769250
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-12 07:07
    The infrared receiver part was bad. After replacing it,
    the BS2 boards and circuits worked fine with the code.

    Post Edited (humanoido) : 5/12/2009 12:54:15 PM GMT
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-12 10:28
    Any idea how to convert this code from BS2 to BS2px?

    StartMax CON 1700
    StartMin CON 1300
    Bin1Max CON 1200
    Bin1Min CON 800
    Bin0Max CON 700
    Bin0Min CON 300
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-12 13:38
    You're already converting the incoming pulse widths from a 0.75us unit to a 2us unit so you don't have to change any of these constants
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-12 15:52
    Thanks sincerely Mike (and everyone that made suggestions, offered
    help and did testing.) This was the final vital information needed to
    make the code work successfully. Thanks to Mike Green, vrossi, SRLM,
    Zoot, and Sticky. Also thanks to Andy Lindsay for the original Stamp 2
    code and book, "IR Remote for the Boe-Bot." This project moves into the
    next phase, developing a universal infrared communications transceiver
    for robots in motion.
  • modemmanmodemman Posts: 41
    edited 2009-05-27 14:48
    humanoido,

    I added Andy Lindsay's code from the "IR Remote for the Boe-Bot" to my robot, and thanks to this thread successfully converted it to a BS2P. I can read the codes from a Sony remote and make the robot do things accordingly. I want to have different "modes" and "tasks". At the most ordinary level, there's a manual mode, where the robot just responds to button presses and moves in the required direction, says something, etc., etc.. It all worked fine, until I added my autonomous roaming code in the mix. Then I noticed that the bot is not looping through it's sensor reading routines. My goal is to make the robot do its thing (mainly check different sensors and act according to program) but also once in a while check for button presses from the remote. For that, I use a check like your IrDetPin = 1 and send the program to a routine like your Get_IR_Byte_Message. If no new button press is detected, the robot should continue roaming and focusing or reading sensors.

    While debugging, I just noticed that my program gets stuck in the "LOOP UNTIL irPulse < StartMax AND irPulse > StartMin" loop (I'm making reference to your code for clarity, my code is adapted from below). What is happening is that the IR sensor detects an IR signal, sends the program to the code checking routine, which waits for the signal to be proper (a Sony start code, in my case), but that is not happening, so it loops.

    What do you think is the most elegant and effective way to get out of the loop, yet not lose IR sensitivity - In other words, I can probably make a timed loop, like "check for the start pulse for such amount of time then get out if you don't see it", but I'm trying not to waste time with waits and pauses?

    Thanks.

    PS. This is the basic code that's the inspiration for getting the button press (I got rid of the BS2 part and adapted to my variables and such). It's from a Parallax doc "Infrared Remote AppKit (#29122)" - It's the "Wait for start pulse..." part that I get stuck in...

    ' 
    
    ' -----[noparse][[/noparse] Constants ]------------------------------------------------------- 
     
    ' Pulse duration constants for SONY remote. 
     
    #SELECT $stamp 
      #CASE BS2, BS2E, BS2PE                     ' PULSE durations 
        ThresholdStart CON 1000                  ' Message rest vs. data rest 
        ThresholdPulse CON 500                   ' Binary 1 vs. 0 for PULSIN 
        ThresholdEdge  CON 300                   ' Binary 1 vs. 0 for RCTIME 
      #CASE BS2P, BS2SX 
        ThresholdStart CON 2400                  ' Binary 1 vs. start pulse 
        ThresholdPulse CON 500  * 5 / 2          ' Binary 1 vs. 0 for PULSIN 
      #CASE #ELSE 
        #ERROR This BASIC Stamp NOT supported. 
    #ENDSELECT 
    
    -----[noparse][[/noparse] Main code stuff removed - calls Get_Ir_Remote_Code]------------
    
    -----[noparse][[/noparse] Subroutine - Get_Ir_Remote_Code ]--------------------------------- 
     
    ' SONY TV IR remote subroutine loads the remote code into the 
    ' remoteCode variable. 
     
    Get_Ir_Remote_Code: 
     
      remoteCode = 0 
     
      #SELECT $stamp 
        #CASE BS2, BS2E, BS2PE 
          DO                                     ' Wait for end of resting state. 
            RCTIME IrDet, 1, irPulse 
          LOOP UNTIL irPulse > ThresholdStart  
          PULSIN IrDet, 0, irPulse               ' Get data pulses. 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT0 = 1 
          RCTIME IrDet, 0, irPulse 
          IF irPulse > ThresholdEdge  THEN remoteCode.BIT1 = 1 
          RCTIME IrDet, 0, irPulse 
          IF irPulse > ThresholdEdge  THEN remoteCode.BIT2 = 1 
          RCTIME IrDet, 0, irPulse 
          IF irPulse > ThresholdEdge  THEN remoteCode.BIT3 = 1 
          RCTIME IrDet, 0, irPulse 
          IF irPulse > ThresholdEdge  THEN remoteCode.BIT4 = 1 
          RCTIME IrDet, 0, irPulse 
          IF irPulse > ThresholdEdge  THEN remoteCode.BIT5 = 1 
          RCTIME IrDet, 0, irPulse 
          IF irPulse > ThresholdEdge  THEN remoteCode.BIT6 = 1 
        #CASE BS2SX, BS2P 
          DO                                     ' Wait for start pulse. 
            PULSIN IrDet, 0, irPulse 
          LOOP UNTIL irPulse > ThresholdStart
          PULSIN IrDet, 0, irPulse               ' Get data pulses. 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT0 = 1 
          PULSIN IrDet, 0, irPulse 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT1 = 1 
          PULSIN IrDet, 0, irPulse 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT2 = 1 
          PULSIN IrDet, 0, irPulse 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT3 = 1 
          PULSIN IrDet, 0, irPulse 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT4 = 1 
          PULSIN IrDet, 0, irPulse 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT5 = 1 
          PULSIN IrDet, 0, irPulse 
          IF irPulse > ThresholdPulse THEN remoteCode.BIT6 = 1 
        #CASE #ELSE 
          #ERROR "BASIC Stamp version not supported by this program." 
      #ENDSELECT 
     
      ' Map digit keys to actual values. 
      IF (remoteCode < 10) THEN remoteCode = remoteCode + 1 
      IF (remoteCode = 10) THEN remoteCode = 0 
     
      RETURN
    
    
    

    Post Edited (modemman) : 5/27/2009 2:53:41 PM GMT
  • modemmanmodemman Posts: 41
    edited 2009-05-29 16:38
    Ahhhhhh.... as usual, somewhere on the Parallax site lies the answer, waiting to slap me right on my forehead..... I think the Nuts and Volts column 76 gives answers to all my IR questions and has a modified code that takes advantage of BS2P features/speed www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol3/col/nv76.pdf. It also addresses my timing issues... I didn't digest or implement yet, but I'm getting it (a very good thing). Thank you Jon Williams.
  • PrettybirdPrettybird Posts: 269
    edited 2009-05-31 18:40
    Newbe here but was reciently scrollong through the included software from nut and volts on the parallax CD. They have some imfo on converting different stamp codes March 2001. That may be some help in the future for anyone who is upgrading from a BS2 ic or E to a BS2P.
Sign In or Register to comment.