Byte array to Word variables
w4gon
Posts: 4
Hi,
I currently have a SERIN command taking in 17 bytes and putting them into a byte array. Right now I'm inputting the data via Hyperterminal, but later the data will be coming from an inclinometer. The incoming data looks like this: x=+03.30,y=-07.41. These are degree measurements on the x and y axis. And here is the BS2 code I'm using to fill the array:
serStr VAR Byte(18)
serStr(17)=0
SERIN PC, Baud, [STR serStr\17]
My question is how to process these raw bytes and put them into Word variables? Right now I really only need the x axis degree reading. I'm guessing the decimal might be a problem for the BS2 as well.
I'm working with the Basic Stamp Homework Board (BS2).
Any help greatly appreciated.
Joel
I currently have a SERIN command taking in 17 bytes and putting them into a byte array. Right now I'm inputting the data via Hyperterminal, but later the data will be coming from an inclinometer. The incoming data looks like this: x=+03.30,y=-07.41. These are degree measurements on the x and y axis. And here is the BS2 code I'm using to fill the array:
serStr VAR Byte(18)
serStr(17)=0
SERIN PC, Baud, [STR serStr\17]
My question is how to process these raw bytes and put them into Word variables? Right now I really only need the x axis degree reading. I'm guessing the decimal might be a problem for the BS2 as well.
I'm working with the Basic Stamp Homework Board (BS2).
Any help greatly appreciated.
Joel
Comments
I can give you a hint. Pull up the basic stamp Help (F1), and do a search for 'Memory" and then select "Memory Organization". The table for "BASIC Stamp 2 Series RAM Organization" should give you the answer that you are looking for.
What is the baud rate? If it is low (say 2400 or lower), then may be possible to parse the data directly into word variables, using DEC modifiers instead of STR.
However at higher baud rates, you'll stick with the STR array, and then pick out the numerical ascii values, subtract 48 to convert from ascii to number, and add them up with proper weighting. something like this for the x axis...
The baud rate is 9600: SERIN PC, 84, [STR serStr\17]
Your example code is precisely what I was looking for.
My goal is to take the degree reading from the inclinometer, place it in a word variable and then turn this reading into a percent. Thank you for helping me get half way there. Quick question on the second half of my project. Can the BS2 do Tangents: percent = Tan(degree)x100? If so I might need to open another thread.
Thanks again!
Joel
As to TAN(angle) * 100.
The Stamp has SIN(angle) and COS(angle). You can find them described in the manual.
So you may be able to do tan = SIN/COS.
The angle on the Stamp has to be expressed in units of brads, where there are 246 brads around a circle in analogy with 360 degrees or 2 pi radians. If you already have degrees, then
brads = degrees ** 46603 ' 256/360
Both SIN and COS will be 16 bit signed values, but nowhere near 16 bits of resolution, which is closer to 8 bits around the full circle.
I think you mean 256 brads in a circle.
Thanks all for your help.
Joel
Cheers
Joel