Shop OBEX P1 Docs P2 Docs Learn Events
Getting TILT angle from ADXL202 — Parallax Forums

Getting TILT angle from ADXL202

blueiceblueice Posts: 12
edited 2005-03-28 01:45 in BASIC Stamp
Hello,
Ive wired my BS2 to an ADXL202 and getting values by using PULSIN..
However,none of the app notes have an example of converting the PWM values to TILT angle..
Can anyone please helpout..
Thankyou
..ice

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->·**ice**
http://www.machinegrid.com : Robots at Work!!
Parallel Port Tutorials,
Autonomous Robots,
PIC16F84a Temperature Controller.

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2005-01-17 17:50
    Did you read the Datasheet?
    I've used the ADXL210, but not for tilt measurements.· We use it as a vibration sensor so our code is slightly different.
    I've just brought up my old datasheet and it's the same sheet for the ADXL202.
    So here it is attached.

    Page 9 tells you about tilt measurements/calculations.
    Basically it requires some math.· ArcSin is what the datasheet requires....this isn't support in the stamp (although ArcTan is)....
    Not sure if you can do some magic with math to get where you want to be!

    Depending on the resolution you want....you might try a lookup table or some trial and error math.
    eg: hold the sensor at a given angle and measure it's input and step it through each angle to see if there's any linearity to it that might make for a constant or easy formula.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • edited 2005-01-17 20:28
    Here is an example (also attached) of calculating tilt angle with the (very similar) Memsic MX2125 Accelerometer Module:

    [color=#008000]' MX2125TiltAngleTest.bs2[/color]
    [color=#008000]' Test accelerometer on Boe-Bot.[/color]
     
    [color=#008000]'{$STAMP BS2}[/color]
    [color=#008000]'{$PBASIC 2.5}[/color]
     
    [color=#000000]x              VAR     Word[/color]
    [color=#000000]y              VAR     Word[/color]
     
    [color=#000000]angle          VAR     Word[/color]
    [color=#000000]magnitude      VAR     Word[/color]
     
    [color=#000000]DO[/color]
     
    [color=#008000]  ' Get tilt pulses.[/color]
    [color=#000000]  PULSIN 6, 1, x[/color]
    [color=#000000]  PULSIN 7, 1, y[/color]
     
    [color=#008000]  ' Scale to -125 to 125 with 0 = level.[/color]
    [color=#000000]  x = (x MIN 1875 MAX 3225) - 1875[/color]
    [color=#000000]  x = x / 5 - 125[/color]
    [color=#000000]  y = (y MIN 1875 MAX 3125) - 1875[/color]
    [color=#000000]  y = y / 5 - 125[/color]
     
    [color=#008000]  ' Calculate magnitude and angle in degrees.[/color]
    [color=#000000]  magnitude = x HYP y[/color]
    [color=#000000]  angle = x ATN y[/color]
    [color=#000000]  angle = angle */ 360[/color]
     
    [color=#008000]  ' Display[/color]
      [color=#0000ff]DEBUG[/color] [color=#800080]HOME[/color][color=#000000], [/color][color=#ff0000]"(x, y) Axis: ("[/color][color=#000000], [/color][color=#000080]SDEC3[/color][color=#000000] x, [/color][color=#ff0000]","[/color][color=#000000], [/color][color=#000080]SDEC3[/color][color=#000000] y, [/color][color=#ff0000]")"[/color][color=#000000], [/color][color=#800080]CLREOL[/color][color=#000000], [/color][color=#800080]CR[/color][color=#000000], [/color][color=#800080]CR[/color][color=#000000],[/color]
                  [color=#ff0000]"Magnitude: "[/color][color=#000000], [/color][color=#000080]DEC4[/color][color=#000000] magnitude, [/color][color=#800080]CR[/color][color=#000000],[/color]
                  [color=#ff0000]"Angle:     "[/color][color=#000000], [/color][color=#000080]DEC3[/color][color=#000000] angle[/color]
    [color=#008000]  ' Del[/color][color=#008000]ay[/color]
      [color=#0000ff]PAUSE[/color][color=#000000] 100[/color]
     
    [color=#0000ff]LOOP[/color]
    
    

    Further Investigation:

    2003 Parallax Product Catalog

    Stamp Applications column·in the November 2004 issue of Nuts & Volts.

    Post Edited (Andy Lindsay (Parallax)) : 1/17/2005 8:47:15 PM GMT
  • blueiceblueice Posts: 12
    edited 2005-01-18 07:45
    Thank you for your responses:
    But i need to measure only one axis not 360degrees[noparse][[/noparse]which uses vales from x and y]

    My values from the PULSIN on yaxis is as follows:

    15600.......90deg
    20300.......0 degree
    25200........-90degree

    now how do i go about calibrating it in degrees?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    **·ice**

    Gerard Sequeira
    Machinegrid.com·:: Robots at Work!!


    Post Edited (blueice) : 1/19/2005 6:08:04 AM GMT
  • steve_bsteve_b Posts: 1,563
    edited 2005-01-18 11:49
    if 20300 is 0deg and 15600 is +90deg....
    then you have 20300-15600 = 4700.· So 4700counts per 90 deg.· So you end up with 52.2 counts per deg.

    Do the same for the other direction!

    that's the easy way....not sure how linear it actually is though!· is 45deg REALLY 17950?· Don't know!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • blueiceblueice Posts: 12
    edited 2005-01-19 06:10
    Steve..
    haaaaaaaaahop.gif
    It actually worked..and its pretty accurate too...a bit give and take....i'll keep this thread posted ..post the code later...
    Thanks...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    **·ice**

    Gerard Sequeira
    Machinegrid.com·:: Robots at Work!!
    ·
  • steve_bsteve_b Posts: 1,563
    edited 2005-01-19 12:07
    very cool!· look forward to seeing the project code!

    Also, they've just started up a 'PROJECTS' forum on this board.· When you are done (or done enough that it's working) then post your project in there....· Include pics, diagrams and code (if you like).·

    I think the idea there is to allow people of similar minds to build it themselves!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • MatthewMatthew Posts: 200
    edited 2005-01-20 06:10
    Blueice,

    How are you attaching this sensor to the board? I have a few of these sensors as well, but I just can't figure out how to solder something that small. I wish they came with pins [noparse]:([/noparse].
  • blueiceblueice Posts: 12
    edited 2005-01-20 08:05
    Hey Matthew..
    actually i have the adxl202Jqc...the adxl202e is even tinier..
    The adxl202jqc is a bit bigger and u can solder them ,though it takes some effort...
    My work place had the PCB ready..so it jst needed soldering...

    but u may even do this...
    u can solder very thin wires directly to the pins and then stick the whole setup o a DIP socket..
    ..
    i'll be posting some pics and documenting the project here and on my website



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    **·ice**

    Gerard Sequeira
    Machinegrid.com·:: Robots at Work!!
    Parallel Port Tutorials,
    Autonomous Robots,
    PIC16F84a Temperature Controller
    ·
  • MatthewMatthew Posts: 200
    edited 2005-01-21 02:43
    Okay, sounds great! Thanks for the tips!
  • blueiceblueice Posts: 12
    edited 2005-03-27 17:25
    Matthew,
    I finally put up a page on how to solder the accelerometer.Ok for testing purposes..
    I put a· few images ,to help get an idea of how i went about it...

    have a look here
    http://www.machinegrid.com/content/view/59/114/

    suggestions welcome..



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    **·ice**

    Gerard Sequeira
    Machinegrid.com·:: Robots at Work!!
    Parallel Port Tutorials,
    Autonomous Robots,
    PIC16F84a Temperature Controller
    ·
  • homesch00lkidhomesch00lkid Posts: 20
    edited 2005-03-28 01:45
    Here's a tutorial on soldering the ADXLs:
    http://www.sparkfun.com/tutorial/ADXL/ADXL-0Tut.htm

    And here you can buy PCBs for them, pay a bit more and they will solder it for you.
    http://www.sparkfun.com/shop/index.php?shop=1&cart=201396&cat=71&amp;

    I'm working with the ADXL 213AE. It's a newer version, but it's the same package. By the way, you can get free ADXLs straight from Analogs Devices on:
    http://www.analog.com/
Sign In or Register to comment.