Shop OBEX P1 Docs P2 Docs Learn Events
help hex numbers.. — Parallax Forums

help hex numbers..

TomRiddleTomRiddle Posts: 9
edited 2008-02-08 07:27 in BASIC Stamp
ok .. i cant find anything helpful..· i'm trying to· read data in hex format with the serin command...·· how can i store all of the hex numbers in one variable?? is it possible??··i'm getting this codes..· $FF $DD $55 .. etc etc...· is it possible to have them all in one variable?? here's part of my code..·

a VAR Byte
b VAR Byte
c VAR Byte
d VAR Byte
m VAR Byte
f VAR Byte
g VAR Byte
h VAR Byte
i VAR Byte

listen:
SERIN 14,16468, [noparse][[/noparse]WAIT($15), a, b, c, d, m, f, g, h, i]

is it possible to instead of saving each and every hex code into one variable.. to have them all in one??·
hope u can help .. 10x

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-06 00:15
    Hi TomRiddle, it's not possible to store your serial data in one variable. What is fairly close and something you may find a better solution is to capture the data to an array.

    My_array VAR Byte(9)

    SERIN 14,16468, [noparse][[/noparse]WAIT($15), STR My_array\9]

    The array would contain one byte in each of it's elements which could be acessed via their index, My_array(0), My_array(1) etc etc

    Jeff T.
  • TomRiddleTomRiddle Posts: 9
    edited 2008-02-06 00:29
    Unsoundcode... 10x for ur quick answer..
    i just tried the code.. but i'm getting some problems..
    when i debug the output ...

    My_array(0) = $D5
    My_array(1) = $AB
    My_array(2) = $4B

    when i should be getting...

    a = $54
    b = $6F
    c = $6D

    any ideas?? 10x
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-06 01:11
    If your input data is in hex format (like "A" "5"), you need to use the HEX formatter in the SERIN statement. See the examples in the Parallax Basic Manual in the chapter on the SERIN statement.
  • TomRiddleTomRiddle Posts: 9
    edited 2008-02-06 01:13
    the input comes in already as hex...· ex..·· FF 55 D5 ... etc etc etc.. works fine when i store every segment on a separate variable... but when i do the array thing.. it messes up the values..
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-06 01:36
    Hi, it's possible that the baud rate is wrong try 84 instead of 16468. Not sure why you would get the correct values with 9 seperate variables but not with the array of bytes. Where is the data coming from and how often is it transmitted. Do you have any control over the string that is transmitted,·can you·try at a lower baud rate for testing maybe 4800.

    Jeff T.
  • TomRiddleTomRiddle Posts: 9
    edited 2008-02-06 01:44
    hi jeff.. well .. the data is comming out of my ipod..·

    a VAR Byte
    b VAR Byte
    c VAR Byte
    d VAR Byte
    m VAR Byte
    f VAR Byte
    g VAR Byte
    h VAR Byte
    i VAR Byte
    SEROUT 15,$4054,2,[noparse][[/noparse]255,85,3,4,0,20,229]
    listen:
    SERIN 14,16468, [noparse][[/noparse]WAIT($15), a, b, c, d, m, f, g, h, i]
    '
    .

    the data comes in .. after the ipod get the command to send the name of the ipod...·· serout...· ..·

    is working fine.. i was just looking for a simpler way..·· bcuz i might be asking for the list of songs.. and that would take a lot of variables LOL

    and no.. i tried with the 84 and i don't get anythign..
  • TomRiddleTomRiddle Posts: 9
    edited 2008-02-06 01:49

    4800* 16572 188 24764 8380
    9600* 16468 8 4 24660 8276
    *The BS2, BS2e and BS2pe may have trouble synchronizing with the incoming serial stream
    at this rate and higher due to the lack of a hardware input buffer. Use only simple variables

    and no formatters to try to solve this problem.

    .. yea.. i found this on the bs2 manual...··· ... i think that's the source of my problems.. grrrr
  • JedJed Posts: 107
    edited 2008-02-07 15:06
    I believe there's an IC chip made specifically for buffering a serial stream. You might look into that. Sorry I don't remember where I saw it or what the item code was.
  • JedJed Posts: 107
    edited 2008-02-07 20:37
    Here's the page:
    www.protean-logic.com/tickit/rsb509B_HTML_Cutsheet.htm

    I'm not sure if you can set the output and input to different baud rates thought.
  • TomRiddleTomRiddle Posts: 9
    edited 2008-02-07 21:02
    :P wow that sure sounds nice...· but i'm still with one concern...· will the bs2 have enought memory to store all the hex string...·??· bcuz if i recieve all of my ipod's information.. (playlists, songs, artists... etc.. ) would it all fit in the bs2 memory???· or is there a workaround like an extra eprom memory or is it posible to use a sd card adapter with the bs2?
  • JedJed Posts: 107
    edited 2008-02-07 21:58
    You can use extra EEPROM chips if you need to, or a flash memory card interface for like sd cards etc... How much space do you need?
  • TomRiddleTomRiddle Posts: 9
    edited 2008-02-08 04:54
    pss i really have no idea...· i'm looking to store just hex strings that i recieve from my ipod..· i really don't know how much space it would take..
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-08 07:24
    Tom -

    I'm still not sure what you mean by "hex strings" as hex is just a _number_ representation in base 16, where the additional NUMBERS A thu F are used. It takes two hex characters to make one byte.

    The PBASIC Stamp has very limited RAM memory, so unless you plan on reading in (say) ten to twenty bytes (20 to 40 "hex strings") at a time, and then transferring them somewhere else (memory stick, EEPROM, etc.), you would be a whole lot better off transferring the data to a PC or something with more RAM.

    I'm sure there are plenty of programs readily available for the PC which will accept data from an Ipod, or any other handheld device. If not, you could use something as simple as the Microsoft Windows utility Hyperterminal to create a file on a PC from th data received from your Ipod.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There is no pleasure in having nothing to do;
    the fun is in having lots to do, and not doing it!
  • TomRiddleTomRiddle Posts: 9
    edited 2008-02-08 07:27
    yes..· i understand.. that's why i might get an eprom or a flash memory card.. and see what's next from there...· 10x a lot guys..·
Sign In or Register to comment.