Shop OBEX P1 Docs P2 Docs Learn Events
memsic data and applescript? — Parallax Forums

memsic data and applescript?

ArchiverArchiver Posts: 46,084
edited 2003-10-20 05:47 in General Discussion
Hey people!

Have a few questions..... I am using the memsic accelerometer for a project. I
am attaching it to willow branches. ( or rather I am hoping to ) The two codes
I
have from memsic are below this message.

What I want to do is one of two things... record the data of the memsic and
have that data act as a switch to turn on functions in a three-d modeling
program using applescript. However, the data is going by so fast in the debug
window, I am not able to see it. How might I slow the data down?

Initially I was hoping to use the memsic to record points in space as it moved
in the environment, but I am not so sure this is possible now and might have
to resort to just using it as a switch of some sort.

if you follow this link to my research part of my website: http://
www.teknoarts.com/html/Diary.html , you will see the code and scematic of the
stamp with accelerometer attached.

The first code is the one I am interested in using and I believe that is
measuring angle incline. The second code is g-force. Does parallax have
the schematic for the memsic to record this data?

So questions are: how to slow data down in the debug window,

any one in here familiar with applescripts as a side passion? I am already a
member of MAcscript builders, but nothing has come from this as of yet....

thanks
john

' ===========================================================
====
' I/O Definitions
'

Dpin CON 0 ' data in from AS5020
Cpin CON 1 ' clock out to AS5020
CSpin CON 2 ' chip select (active low)


'
' Constants
'

MoveTo CON 2 ' move to x/y in DEBUG window
ClrRt CON 11 ' clear DEBUG line to right
DegSym CON 176 ' degrees symbol


'
' Variables
'

position VAR Byte ' angular position from AS5020
degrees VAR Word ' convert to degrees
offset VAR Byte ' position offset


'
' EEPROM Data
'


'
' Initialization
'

Initialize:
HIGH CSpin ' deselect AS5020
LOW Cpin

PAUSE 250 ' let DEBUG open
DEBUG CLS
DEBUG "AS5020 Angular Position Sensor", CR
DEBUG "
"


'
' Program Code
'

Main:
GOSUB Get_Position ' read position from AS5020

' degrees (tenths) = position * 56.25
'
degrees = position */ 14400

DEBUG MoveTo, 0, 3
DEBUG "Position... ", DEC position, ClrRt, CR
DEBUG "Angle...... ", DEC (degrees / 10), ".", DEC1 degrees, degSym, ClrRt

GOTO Main
END


'
' Subroutines
'

Get_Position:
LOW CSpin ' select device
PULSOUT Cpin, 1 ' start measurement
PAUSE 0 ' allow measurement
SHIFTIN Dpin, Cpin, MSBPOST, [noparse][[/noparse]position\6] ' load data
HIGH CSpin ' deselect device
position = position + offset // 64 ' account for offset
RETURN


Set_Offset:
offset = 0 ' clear offset
GOSUB Get_Position ' get current position
offset = 64 - position ' calculate new "0" offset

RETURN
====================================

and the other code:


Xin CON 9 ' X input from Memsic 2125


'
' Constants
'

HiPulse CON 1 ' measure high-going pulse
LoPulse CON 0

MoveTo CON 2 ' move to x/y in DEBUG window
ClrRt CON 11 ' clear DEBUG line to right
DegSym CON 176 ' degrees symbol


'
' Variables
'

xRaw VAR Word ' pulse width from Memsic 2125
xGForce VAR Word ' x axis g force (1000ths)
xTilt VAR Word ' x axis tilt (100ths)

idx VAR Nib ' table index
mult VAR Word ' multiplier - whole part
frac VAR Word ' multiplier - fractional part


'
' EEPROM Data
'


'
' Initialization
'

Setup:
PAUSE 250 ' let DEBUG window open
DEBUG "Memsic 2125 Accelerometer", CR
DEBUG "
"


'
' Program Code
'

Main:
GOSUB Read_X_Tilt ' reads G-force and Tilt

Display:
DEBUG MoveTo, 0, 3
DEBUG "Raw Input... ", DEC (xRaw / 1000), ".", DEC3 xRaw, " ms", ClrRt,
CR

DEBUG "G Force..... ", (xGForce.Bit15 * 13 + " ")
DEBUG DEC (ABS xGForce / 1000), ".", DEC3 (ABS xGForce), " g", ClrRt, CR

DEBUG "X Tilt...... ", (xGForce.Bit15 * 13 + " ")
DEBUG DEC (ABS xTilt / 100), ".", DEC2 (ABS xTilt), DegSym, ClrRt

PAUSE 200
GOTO Main


'
' Subroutines
'

Read_X_Force:
PULSIN Xin, HiPulse, xRaw ' read pulse output
xRaw = xRaw * 2 ' convert to microseconds

' g = ((t1 / 0.01) - 0.5) / 12.5% ' correction from data sheet
'
xGForce = ((xRaw / 10) - 500) * 8 ' convert to 1/1000 g
RETURN


Read_X_Tilt:
GOSUB Read_X_Force

' tilt = g x k
'
' Select tilt conversion factor based on static
' G force. Table data derived from Memsic specs.

LOOKDOWN ABS xGForce, <=[noparse][[/noparse]174, 344, 508, 661, 2000], idx
LOOKUP idx, [noparse][[/noparse]57, 58, 59, 60, 62], mult
LOOKUP idx, [noparse][[/noparse]32768, 10486, 3277, 30802, 22938], frac

' G Force is divided by 10 to prevent roll-over errors at end
' of range. Tilt is returned in 100ths degrees.

xTilt = mult * (ABS xGForce / 10) + (frac ** (ABS xGForce / 10))

Check_SignX:
IF (xGForce.Bit15 = 0) THEN XT_Exit ' if positive, skip
xTilt = -xTilt ' correct for g force sign

XT_Exit:
RETURN

=================================


John S. Lathram lll
Graduate Studies, Art and Technology
The Ohio State University.
146 Hopkins Hall
128 N. Oval Mall
Columbus, Ohio 43210-1318
http://www.teknoarts.com

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-10-20 05:47
    Which Memsic sensor do you have? The one that Parallax sells is, I
    think, the model 2125, which encodes its X and Y accelerations as
    pulse width. You can download quite a bit of code and application
    information from
    http://www.parallax.com/detail.asp?product_id=28017

    The code you have posted on your project site evidently is meant for
    a different model of Memsic sensor, one that uses something like SPI
    protocol. MEMSIC offers several choices of interface, analog, too.
    You have to be sure you are on the right page, interface wise!

    There is no separate circuit for measuring g-force and incline. What
    you measure with it depends on the mechanical arrangements.

    If data rolls out too fast, you will have to sample less often, or
    else implement some kind of low pass filtering to focus in on the
    slower zen of the willow.


    -- Tracy




    >Hey people!
    >
    >Have a few questions..... I am using the memsic accelerometer for a
    >project. I
    >am attaching it to willow branches. ( or rather I am hoping to )
    >The two codes I
    >have from memsic are below this message.
    >
    >What I want to do is one of two things... record the data of the memsic and
    >have that data act as a switch to turn on functions in a three-d modeling
    >program using applescript. However, the data is going by so fast in the debug
    >window, I am not able to see it. How might I slow the data down?
    >
    >Initially I was hoping to use the memsic to record points in space as it moved
    >in the environment, but I am not so sure this is possible now and might have
    >to resort to just using it as a switch of some sort.
    >
    >if you follow this link to my research part of my website: http://
    >www.teknoarts.com/html/Diary.html , you will see the code and scematic of the
    >stamp with accelerometer attached.
    >
    >The first code is the one I am interested in using and I believe that is
    >measuring angle incline. The second code is g-force. Does parallax have
    >the schematic for the memsic to record this data?
    >
    >So questions are: how to slow data down in the debug window,
    >
    >any one in here familiar with applescripts as a side passion? I am already a
    >member of MAcscript builders, but nothing has come from this as of yet....
    >
    >thanks
    >john
    >
    >' ===========================================================
    >====
    >' I/O Definitions
    >'
    >
    >
    >
    >Dpin CON 0 ' data in from AS5020
    >Cpin CON 1 ' clock out to AS5020
    >CSpin CON 2 ' chip select (active low)
    >
    >
    >'
    >
    >
    >' Constants
    >'
    >
    >
    >
    >MoveTo CON 2 ' move to x/y in DEBUG window
    >ClrRt CON 11 ' clear DEBUG line to right
    >DegSym CON 176 ' degrees symbol
    >
    >
    >'
    >
    >
    >' Variables
    >'
    >
    >
    >
    >position VAR Byte ' angular position from AS5020
    >degrees VAR Word ' convert to degrees
    >offset VAR Byte ' position offset
    >
    >
    >'
    >
    >
    >' EEPROM Data
    >'
    >
    >
    >
    >
    >'
    >
    >
    >' Initialization
    >'
    >
    >
    >
    >Initialize:
    > HIGH CSpin ' deselect AS5020
    > LOW Cpin
    >
    > PAUSE 250 ' let DEBUG open
    > DEBUG CLS
    > DEBUG "AS5020 Angular Position Sensor", CR
    > DEBUG "
    "
    >
    >
    >'
    >
    >
    >' Program Code
    >'
    >
    >
    >
    >Main:
    > GOSUB Get_Position ' read position from AS5020
    >
    > ' degrees (tenths) = position * 56.25
    > '
    > degrees = position */ 14400
    >
    > DEBUG MoveTo, 0, 3
    > DEBUG "Position... ", DEC position, ClrRt, CR
    > DEBUG "Angle...... ", DEC (degrees / 10), ".", DEC1 degrees, degSym, ClrRt
    >
    > GOTO Main
    > END
    >
    >
    >'
    >
    >
    >' Subroutines
    >'
    >
    >
    >
    >Get_Position:
    > LOW CSpin ' select device
    > PULSOUT Cpin, 1 ' start measurement
    > PAUSE 0 ' allow measurement
    > SHIFTIN Dpin, Cpin, MSBPOST, [noparse][[/noparse]position\6] ' load data
    > HIGH CSpin ' deselect device
    > position = position + offset // 64 ' account for offset
    > RETURN
    >
    >
    >Set_Offset:
    > offset = 0 ' clear offset
    > GOSUB Get_Position ' get current position
    > offset = 64 - position ' calculate new "0" offset
    >
    > RETURN
    >====================================
    >
    >and the other code:
    >
    >
    >Xin CON 9 ' X input from Memsic 2125
    >
    >
    >'
    >
    >
    >' Constants
    >'
    >
    >
    >
    >HiPulse CON 1 ' measure high-going pulse
    >LoPulse CON 0
    >
    >MoveTo CON 2 ' move to x/y in DEBUG window
    >ClrRt CON 11 ' clear DEBUG line to right
    >DegSym CON 176 ' degrees symbol
    >
    >
    >'
    >
    >
    >' Variables
    >'
    >
    >
    >
    >xRaw VAR Word ' pulse width from Memsic 2125
    >xGForce VAR Word ' x axis g force (1000ths)
    >xTilt VAR Word ' x axis tilt (100ths)
    >
    >idx VAR Nib ' table index
    >mult VAR Word ' multiplier - whole part
    >frac VAR Word ' multiplier - fractional part
    >
    >
    >'
    >
    >
    >' EEPROM Data
    >'
    >
    >
    >
    >
    >'
    >
    >
    >' Initialization
    >'
    >
    >
    >
    >Setup:
    > PAUSE 250 ' let DEBUG window open
    > DEBUG "Memsic 2125 Accelerometer", CR
    > DEBUG "
    "
    >
    >
    >'
    >
    >
    >' Program Code
    >'
    >
    >
    >
    >Main:
    > GOSUB Read_X_Tilt ' reads G-force and Tilt
    >
    >Display:
    > DEBUG MoveTo, 0, 3
    > DEBUG "Raw Input... ", DEC (xRaw / 1000), ".", DEC3 xRaw, " ms", ClrRt,
    >CR
    >
    > DEBUG "G Force..... ", (xGForce.Bit15 * 13 + " ")
    > DEBUG DEC (ABS xGForce / 1000), ".", DEC3 (ABS xGForce), " g", ClrRt, CR
    >
    > DEBUG "X Tilt...... ", (xGForce.Bit15 * 13 + " ")
    > DEBUG DEC (ABS xTilt / 100), ".", DEC2 (ABS xTilt), DegSym, ClrRt
    >
    > PAUSE 200
    > GOTO Main
    >
    >
    >'
    >
    >
    >' Subroutines
    >'
    >
    >
    >
    >Read_X_Force:
    > PULSIN Xin, HiPulse, xRaw ' read pulse output
    > xRaw = xRaw * 2 ' convert to microseconds
    >
    > ' g = ((t1 / 0.01) - 0.5) / 12.5% ' correction from data sheet
    > '
    > xGForce = ((xRaw / 10) - 500) * 8 ' convert to 1/1000 g
    > RETURN
    >
    >
    >Read_X_Tilt:
    > GOSUB Read_X_Force
    >
    > ' tilt = g x k
    > '
    > ' Select tilt conversion factor based on static
    > ' G force. Table data derived from Memsic specs.
    >
    > LOOKDOWN ABS xGForce, <=[noparse][[/noparse]174, 344, 508, 661, 2000], idx
    > LOOKUP idx, [noparse][[/noparse]57, 58, 59, 60, 62], mult
    > LOOKUP idx, [noparse][[/noparse]32768, 10486, 3277, 30802, 22938], frac
    >
    > ' G Force is divided by 10 to prevent roll-over errors at end
    > ' of range. Tilt is returned in 100ths degrees.
    >
    > xTilt = mult * (ABS xGForce / 10) + (frac ** (ABS xGForce / 10))
    >
    >Check_SignX:
    > IF (xGForce.Bit15 = 0) THEN XT_Exit ' if positive, skip
    > xTilt = -xTilt ' correct for g force sign
    >
    >XT_Exit:
    > RETURN
    >
    >=================================
    >
    >
    >John S. Lathram lll
    >Graduate Studies, Art and Technology
    >The Ohio State University.
    >146 Hopkins Hall
    >128 N. Oval Mall
    >Columbus, Ohio 43210-1318
    >http://www.teknoarts.com
    >
    >
    >
    >
    >
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the
    >Subject and Body of the message will be ignored.
    >
    >
    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.