Shop OBEX P1 Docs P2 Docs Learn Events
Bluesmirf reading hex value with propeller — Parallax Forums

Bluesmirf reading hex value with propeller

RyoshimaRyoshima Posts: 34
edited 2011-12-01 18:30 in Propeller 1
This does involve a wireless topic but it's more of a propeller issue. When sending an ASCII command to a bluesmirf ('L'), the bluesmirf returns as an example:

RSSI=ff,fa

(the bluesmirf returns the whole line, RSSI= and all, above every time)

where both are hexadecimal values and the ff would be the current RSSI value and fa would be the lowest RSSI value that has been encountered.

Is there a way for me to just grab the bold ff portion?

Thanks
«1

Comments

  • ratronicratronic Posts: 1,451
    edited 2011-11-16 19:21
    Ryoshima if it always spits out the samething then perhaps you could do something like this
    Pub main | i
      repeat until io.rx == "R"   
      repeat i from 0 to 2        
        io.rx                     
      if io.rx == "="             
        A := io.rx
    
    Then A will equal the spot where ff is above.
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-16 19:40
    thanks for the reply ratronic, yes the same thing is being sent over and over, but the bold ff portion is always changing, the values can range from 00 to ff in hex. I only want to grab whatever current value is in that changing portion. Your code looks like its checking to see if the io.rx is some value, but the value that is being returned is:

    RSSI=**,##

    where ** is the changing hex value and the value I desire to capture.
    I have used the propeller board for a while but haven't had to be to in depth with the coding, can you please elaborate on how your code works line by line?

    Thank you!!
  • ratronicratronic Posts: 1,451
    edited 2011-11-16 19:51
    The snippet I posted will return the value of the character sent in that position right after the "=". As far as to it's value it will be a byte (0-255, $0-$ff) and then A will equal whatever was sent in that position.

    Edit: if you want to display the numeric value of A then use the .DEC(), .BIN(), .HEX() methods of your display device.
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-16 20:08
    Awesome, thank you so much!
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-16 21:37
    ratronic, sorry to post another question, but how do I assign a receive line? The code I have is:
    OBJ
    io      :       "FullDuplexSerial.spin"
    Pub getRSSI : A | i
      repeat until io.rx == "R"   
      repeat i from 0 to 2        
        io.rx                     
      if io.rx == "="             
        A := io.rx
    

    I assume you have to assign io.rx to a pin, but when I look into FULLSERIALDUPLEX, the rx function isn't setup to have an assigned pin.
  • ratronicratronic Posts: 1,451
    edited 2011-11-16 21:48
    Ryoshima to start the fullduplexserial object
    Con                                                          
                                                             
      _CLKMODE = XTAL1 + PLL16X                              
      _XINFREQ = 5_000_000   
    Var
      long a
    Obj 
       io : "fullduplexserial"
    Pub main
    
      io.start(rxpin, txpin, mode, baudrate)
    

    See the .start method of the fullduplexserial object for the meanings.

    Edit: Also the clock needs to be set up.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-11-16 22:06
    Ryoshima wrote: »
    This does involve a wireless topic but it's more of a propeller issue. When sending an ASCII command to a bluesmirf ('L'), the bluesmirf returns as an example:

    RSSI=ff,fa

    (the bluesmirf returns the whole line, RSSI= and all, above every time)

    where both are hexadecimal values and the ff would be the current RSSI value and fa would be the lowest RSSI value that has been encountered.

    Is there a way for me to just grab the bold ff portion?

    Thanks

    I am green at coding this on the prop (this is toddlers play in perl), but if it is a constant length string (is this something that one of the serial IO objects could handle?), I would input it into an array and read back the contents of the two bytes prior the null terminator to get the ascii representation of the hex value. Realize that if you want the actual binary value represented by the two bytes, you will have to add a routine to convert ascii to binary/hex for a true 8 bit single byte value. Bytes are as easy as any other length in spin, a bit more difficult in PASM as it works on 32 bit words.
  • ratronicratronic Posts: 1,451
    edited 2011-11-16 22:13
    Frank there are multiple ways to get at it, I was just throwing out an idea to build upon. I've used the Propeller since it came out and I'm still feeling green about it!
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-11-16 22:26
    ratronic wrote: »
    Frank there are multiple ways to get at it, I was just throwing out an idea to build upon. I've used the Propeller since it came out and I'm still feeling green about it!

    Yeah, I noted after I hit send that you referenced the fullduplex serial object. I have used that extensively in debugging my ADC capture object. It appears to be able to send a string, but most of the examples and the object look like the receive is limited to bytes as the examples usually build in a string handler for using it as an input.

    Frank

    @ratronic.
    (Not to lazy to try it and code it, just wanted to throw the possibility out there. Finishing wiring up an SOIC op-amp into a .5 wide home-made dip header. My next A/D will be using the TI ADS7229. I expect it will tax the Prop chips speed if I can push it near its rated 1MSPS speed w/ 12 bit serial output. MCP3201 capture object @100ksps already posted.)
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-16 23:20
    EDIT: Had problem connecting bluesmirfs, fixed it. Solution is below.
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-17 02:34
    fixed the bluesmirf connection problem
    OBJ
    io      :       "FullDuplexSerial.spin"
    pst     :       "Parallax Serial terminal" 
    Pub getRSSI | i, A
    pst.StartRxTx(0,1,0,9600)
    pst.str(string("$$$"))
    repeat 1000000
    pst.NewLine
    pst.Char("C")
    pst.NewLine
    repeat 1000000
    pst.str(string("$$$"))
    repeat 1000000
    pst.NewLine
    pst.Char("L")
    pst.NewLine
    

    Though this isn't working
    CON
            _CLKMODE = XTAL1 + PLL16X
            _XINFREQ = 5_000_000
    OBJ
    io      :       "FullDuplexSerial.spin"
    pst     :       "Parallax Serial terminal" 
    Pub getRSSI | i, A
    pst.StartRxTx(0,1,0,9600)
    pst.str(string("$$$"))
    repeat 1000000
    pst.NewLine
    pst.Char("C")
    pst.NewLine
    repeat 1000000
    pst.str(string("$$$"))
    repeat 1000000
    pst.NewLine
    pst.Char("L")
    pst.NewLine
      repeat
        repeat until io.rx == "R"   
        repeat i from 0 to 2        
          io.rx                     
        if io.rx == "="             
          A := io.rx
        pst.clear
        pst.str(string("The Signal Strength is: "))
        pst.Hex(A,2)
        waitcnt(clkfreq/10 + cnt)
    
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-17 02:42
    You have to start the io object as well, e.g.
    io.start(31, 30, %0000, 115200)
    
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-17 07:41
    Tried this too, still nothing. I found this arduino code where this person was taking out returned data from the bluesmirf, does the propeller do anything similar to this?
     [B]while[/B][B]([/B]Serial[B].[/B][COLOR=#008080]available[/COLOR][B]()[/B] [B]<[/B] [COLOR=#009999]3[/COLOR][B]);[/B]
        str[B][[/B][COLOR=#009999]0[/COLOR][B]][/B] [B]=[/B] [B]([/B][COLOR=#445588][B]char[/B][/COLOR][B])[/B]Serial[B].[/B][COLOR=#008080]read[/COLOR][B]();[/B]
        str[B][[/B][COLOR=#009999]1[/COLOR][B]][/B] [B]=[/B] [B]([/B][COLOR=#445588][B]char[/B][/COLOR][B])[/B]Serial[B].[/B][COLOR=#008080]read[/COLOR][B]();[/B]
        str[B][[/B][COLOR=#009999]2[/COLOR][B]][/B] [B]=[/B] [B]([/B][COLOR=#445588][B]char[/B][/COLOR][B])[/B]Serial[B].[/B][COLOR=#008080]read[/COLOR][B]();[/B]  
        [B]if[/B][B]([/B]str[B][[/B][COLOR=#009999]0[/COLOR][B]][/B] [B]==[/B] [COLOR=#DD1144]'A'[/COLOR] [B]&&[/B] str[B][[/B][COLOR=#009999]1[/COLOR][B]][/B] [B]==[/B] [COLOR=#DD1144]'O'[/COLOR] [B]&&[/B] str[B][[/B][COLOR=#009999]2[/COLOR][B]][/B] [B]==[/B] [COLOR=#DD1144]'K'[/COLOR][B])
    

    source: [/B]https://github.com/produceconsumerobot/MindSetArduino/blob/master/CleanProgramBlueSMiRF/CleanProgramBlueSMiRF.pde

    P.S. I haven't been to sleep yet


  • ratronicratronic Posts: 1,451
    edited 2011-11-17 09:55
    Ryoshima you probably want to use waitcnt for a delay instead of multiple repeats. In post #12 you didn't start the io object. I don't have a bluesmirf device to try but maybe this will get you a little farther.
    CON
            _CLKMODE = XTAL1 + PLL16X
            _XINFREQ = 5_000_000
        
    OBJ
    io      :       "FullDuplexSerial.spin"
    pst     :       "Parallax Serial terminal" 
    Pub getRSSI | i, A
      pst.StartRxTx(31,30,0,9600)  'this starts the serial terminal for debug display
      waitcnt(clkfreq*3 + cnt)     'delay 3 seconds so you can open the parallax serial terminal
      io.start(0, 1, 0, 9600)      'this starts the serial port for your bluesmirf
      io.str(string("$$$"))        'this sends string
      
      repeat 1000000               'use waitcnt for delay
      io.tx(13)                    'transmit CHR/LF
      io.tx("C")                   'transmit "C"
      io.tx(13)                    'transmit CHR/LF
      repeat 1000000               'use waitcnt for delay
      io.str(string("$$$"))        'send string
      repeat 1000000               'use waitcnt for delay
      io.tx(13)                    'transmit CHR/LF 
      io.tx("L")                   'transmit "L"   
      io.tx(13)                    'transmit CHR/LF  
      repeat                                          'repeat continued
        repeat until io.rx == "R"                     'wait here until "R" received
        repeat i from 0 to 2                          'receive 3 more characters "SSI"
          io.rx                                       '
        if io.rx == "="                               'if the fifth character is "="
          A := io.rx                                  ' then assign A to sixth character
        pst.tx(1)                                     'home the display cursor
        pst.str(string("The Signal Strength is: "))   'print string to display
        pst.Hex(A,2)                                  'print value of A in 2 digit hex#
        waitcnt(clkfreq/10 + cnt)                     'delay 1/10 of a second
    

    Edit get some sleep!
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-21 13:07
    Still nothing, Im trying to display this on the serial terminal so that the only thing printed out are the hexadecimal values
  • ratronicratronic Posts: 1,451
    edited 2011-11-21 14:22
    I haven't looked at the datasheet for your device, the code I posted is only from things you originally put here. Maybe some one that's used bluesmirf can comment.
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-21 15:47
    Ryoshima wrote: »
    Still nothing, Im trying to display this on the serial terminal so that the only thing printed out are the hexadecimal values
    Provided your serial links work, can you try this simple loop? It will dump the response to the L command in hexadecimal mode to the serial terminal.
    repeat
      pst.hex(io.rx, 2)
      pst.char(32)
    
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-30 18:03
    Sorry I've been really busy with school. I got the program ratronic posted to work, but for full signal strength it gives me a '66' and not an 'ff'. When I make changes with the antenna direction, I get values from the USB to serial connection that vary greatly, but when I use the program I only get a '66' or '65', even though I use the same procedure.
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-30 18:15
    Ryoshima wrote: »
    I got the program ratronic posted to work, but for full signal strength it gives me a '66' and not an 'ff'.
    66 is the hex representation of the lower case f, which suggests that the 'ff' you're expecting to see is sent as $66, $66 (it would have suprised me if if the data sent mixed ASCII and raw binary). That's why I asked you for a raw data dump to figure out the encoding.

    Can you check what the byte after the first $66 is?
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-30 18:18
    ok sorry, how do I go about getting your raw data dump?
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-30 18:26
    After the last io.tx(13) in ratronic's example (the one after sending L) just insert the repeat loop (instead of the one shown in his example), e.g.
    io.tx("L")                   'transmit "L"   
      io.tx(13)                    'transmit CHR/LF  
      repeat                       'repeat continued
        pst.hex(io.rx, 2)
        pst.char(32)
    
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-30 18:32
    Here is what I pulled out
    43 4D 44 0D 0A 3F 0D 0A 52 53 53 49 20 4F 4E 0D 0A 52 53 53 49 3D 66 66 2C66 66 0D 0A 52 53 53 49 3D 66 66 2C 66 66 0D 0A 52 53 53 49 3D 66 66 2C 66
    66 0D 0A 52 53 53 49 3D 66 66 2C 66 66 0D 0A 52 53 53 49 3D 66 66 2C 66 66
    0D 0A 52 53 53 49 3D 66 66 2C 66 66 0D 0A 52 53 53 49 3D 66 65 2C 66 65 0D
    0A 52 53 53 49 3D 66 65 2C 66 65 0D 0A 52 53 53 49 3D 66 65 2C 66 65 0D 0A
    52 53 53 49 3D 66 65 2C 66 65 0D 0A 52 53 53 49 3D 66 65 2C 66 65 0D 0A 52
    53 53 49 3D 66 65 2C 66 65 0D 0A 52 53 53 49 3D 66 66 2C 66 65 0D 0A 52 53
    53 49 3D 66 66 2C 66 65 0D 0A 52 53 53 49 3D 66 66 2C 66 65 0D 0A 52 53 53
    49 3D 66 66 2C 66 65 0D 0A 52 53 53 49 3D 66 66 2C 66 65 0D 0A 52 53 53 49
    3D 66 66 2C 66 65 0D 0A 52 53 53 49 3D 66 66 2C 66 65 0D 0A 52 53 53 49 3D
    66 66 2C 66 65 0D 0A 52 53 53 49 3D 66 66 2C 66 65 0D
    
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-30 18:36
    52 53 53 49 3D 66 66 2C 66 66 0D 0A
     R  S  S  I  =  f  f  ,  f  f CR LF
    
    OK, so it's ASCII encoded. What this means for you is that you have to read two bytes and convert it to a single byte.
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-30 18:46
    so is there a case conversion I can run? $66 = f, $65 = e and so on?

    EDIT: I suppose changing those to a usable integer range($66 = 100 ---> $?? = 0)?
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-30 18:56
    Sort of, $30..$39 are normal digits, in this case all you do is value := char - $30. As for letters, assuming they only ever send lower case letters then the range here is $61..$66 and the corresponding value is value := char - $61 + 10. As you get two bytes the final result is value1*16+value2. There is also a huge number of conversion routines to be found in the forum. This topic comes up every now and then.
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-30 19:08
    quick and dirty example:
    PUB null | value
    
      value := convert("4")*16 + convert("A")
    
      dira[16..23]~~
      outa[16..23] := value
    
      waitpne(0, 0, 0)
      
    PRI convert(char)
    
      case char
        "0".."9":           return char - "0"
        "a".."f", "A".."F": return (char | $20) - "a" + 10
        other:              abort
    
    DAT
    
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-30 20:35
    what is the value of $20 for?

    EDIT: its a space, but why still?
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-30 20:41
    A lower case "a" is $61, capital "A" is $41. The $20 ("A" xor "a") makes sure that we only deal with lower case letters (otherwise the minus "a" wouldn't work).
  • RyoshimaRyoshima Posts: 34
    edited 2011-11-30 20:56
    return (char | $20) - "a" + 10

    if char = "b"

    what would be returned?

    Also, is there a good place I can go to learn about this stuff after we figure out this problem?
  • kuronekokuroneko Posts: 3,623
    edited 2011-11-30 21:01
    Ryoshima wrote: »
    return (char | $20) - "a" + 10

    if char = "b"

    what would be returned?
    Lower case "b" is $62. $62 | $20 is $62 (pipe symbol is binary OR). "a" would be $61 which leaves us with $62 - $61 + 10 = 11. Eleven decimal is "b" hex. That's what we wanted.

    Using capital "C" ($43) as an example. $43 | $20 = $63, $63 - $61 + 10 = 12. Twelve decimal is "c" hex.
Sign In or Register to comment.