Shop OBEX P1 Docs P2 Docs Learn Events
IR buddy — Parallax Forums

IR buddy

yzcheyzche Posts: 35
edited 2004-08-24 06:34 in BASIC Stamp
I am using IR buddy from http://www.parallax.com/detail.asp?product_id=28016

I use following command to send info 12345678
SEROUT·· IRbSIO,·· IRb96, [noparse][[/noparse]$44, 38,1,2,3,4,5,6,7,8, STR buffer\8]

following is the command to receive the info
SEROUT IRbSIO, IRb96,[noparse][[/noparse]$64]
SERIN·· IRbSIO, IRb96,[noparse][[/noparse] STR buffer\8]
for counter =·0 to 7
debug dec buffer(counter), cr
next

However, when it is receive by another IR buddy
the result is 11345678

any idea why?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-23 20:03
    Change your transmit line to:

    SEROUT IRbSIO, IRb96, [noparse][[/noparse]$44, 38, 1, 2, 3, 4, 5, 6, 7, 8] 
    

    and give it another try.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • yzcheyzche Posts: 35
    edited 2004-08-23 20:10
    SEROUT IRbSIO, IRb96, [noparse][[/noparse]$44, 38, 1, 2, 3, 4, 5, 6, 7, 8]

    It did not work.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-23 20:11
    Hmmm... that's a mystery. Have you tried some of the standard demos? Do they work? I haven't used the IRBUDDY in quite a long time, but didn't have much trouble with it when I did.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • yzcheyzche Posts: 35
    edited 2004-08-23 20:42
    You·mean·demos that came with IR buddy? I try one of them. It required 4 LED for receiver and one LED for transmitter. file name was "IRB Slave.BS2" and "IRB Master.BS2". I ran the program and LED light up so I guess it work. But I don't know if LED lighted up the way they suppose to.

    following are code for my program
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'sent.BS2
    buffer VAR Byte
    IRbSIO········· PIN···· 14····················· ' IR Buddy serial I/O
    IRb96 CON 84+$8000
    main :
    GOSUB ir_buddy_reset
    SEROUT·· IRbSIO,·· IRb96, [noparse][[/noparse]$44, 38, 1, 2, 3, 4, 5, 6, 7, 8]
    DEBUG "data sent", CR
    PAUSE 500
    GOTO main

    IR_Buddy_Reset:
    · LOW IRbSIO··································· ' signal reset
    · PAUSE 5
    · INPUT IRbSIO································· ' release reset signal
    · PAUSE 50····································· ' allow time for reset actions
    · RETURN

    ' {$STAMP BS2}' {$PBASIC 2.5}'receive.bs2buffer VAR ByteIRbSIO PIN 15 ' IR Buddy serial I/OIRb96 CON 84+$8000c VAR Bytemain :GOSUB IR_Buddy_ResetSEROUT IRbSIO, IRb96,[noparse][[/noparse]$64]buffer(0)=0SERIN IRbSIO, IRb96, [noparse][[/noparse] STR buffer\8]DEBUG "data receive", CRFOR c = 0 TO 7 DEBUG DEC buffer(c)NEXTDEBUG CRtx_wait: IF(INS.LOWBIT(IRbSIO)=0) THEN tx_wait GOTO main IR_Buddy_Reset: LOW IRbSIO ' signal reset PAUSE 5 INPUT IRbSIO ' release reset signal PAUSE 50 ' allow time for reset actions RETURN
  • yzcheyzche Posts: 35
    edited 2004-08-23 20:45
    for some reason, buffer(1) is always 1
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-08-23 21:18
    Yzche -

    The variable named "buffer" needs to be 8 BYTES long, as indicated in the demo programs supplied by Parallax. Therein is the first problem.

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-23 22:21
    Good catch, Bruce, you hit it on the head. The variable called c in the receiver program is overwriting buffer(1). The definitions should be:

    buffer VAR Byte(8) 
    c      VAR Nib
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • yzcheyzche Posts: 35
    edited 2004-08-24 03:04
    following lines is from IRB Master.BS2

    buffer········· VAR···· Byte··················· ' tx-rx buffer (8 bytes)·

    cmd············ VAR···· Byte
    data1·········· VAR···· Byte
    data2·········· VAR···· Byte
    data3·········· VAR···· Byte
    data4·········· VAR···· Byte
    data5·········· VAR···· Byte
    chkSum········· VAR···· Byte

    I don't see any array from the code.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-24 06:34
    The BASIC Stamp RAM space can be treated like an implicit array -- which was happening in your program. The problem you were having is that the compiler assigned the variable called 'c' to the next location after 'buffer', so 'c' and buffer(1) occupied the same physical address. By using an explicit declaration for your array, the variable called 'c' would not be in conflict with any part of the buffer array.

    As to the demo code above, since the BASIC Stamp treats RAM as an array you can get do this:

    data1 = $FF 
    DEBUG IHEX2 buffer(2)
    


    and you'll get $FF.·· Just to be explicit, here is how the [noparse][[/noparse]implicit] array is organized:

    buffer(0) = buffer
    buffer(1) = cmd
    buffer(2) = data1
    buffer(3) = data2
    buffer(4) = data3
    buffer(5) = data4
    buffer(6) = data5
    buffer(7) = chkSum

    When using the implicit array nature of the BASIC Stamp, you must be very careful of the order of assignments, and make sure that you keep like-sized variables grouped to gether so that you're mindful of the assignment order. The compiler places words first, then bytes, then nibs, finally bits.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 8/24/2004 6:38:13 AM GMT
Sign In or Register to comment.