Shop OBEX P1 Docs P2 Docs Learn Events
Memsic 2125 Dual Axis Accelerometer — Parallax Forums

Memsic 2125 Dual Axis Accelerometer

noobmunchernoobmuncher Posts: 124
edited 2009-12-21 05:11 in Propeller 1
Hello,

I am just starting with the propeller chip (coming from BS2's) and I am trying to find a object that I can use to show the ouput of the Accelerometer on my screen. I found one program, but it outputs to a TV and that won't work for my purposes.
The link for the one that outputs to video is
obex.parallax.com/objects/140/

Thanks for the help!

Post Edited (noobmuncher) : 12/18/2009 3:54:24 AM GMT

Comments

  • LeonLeon Posts: 7,620
    edited 2009-12-16 03:46
    It's very easy to incorporate a different object for that. What do you want the output on?

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-16 05:48
    I would just like to output onto my computer screen, i have't done this before but if I can do it through the equivilent of a debug window or something that would be great.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-16 07:18
    noobmuncher,

    Try this... I don't have a Memsic 2125 at the moment, so I couldn't test this code for sure, but it should return the RAW x and y values from a Memsic Accelerometer to a serial terminal set for 9600 Baud. Please let me know if this works for you.

    [b]CON[/b]     ''General Constants for Propeller Setup
      [b]_CLKMODE[/b] = [b]XTAL1[/b] + [b]PLL16X[/b]
      [b]_XINFREQ[/b] = 5_000_000
    
      MMx = 0
      MMy = 1
    
    [b]OBJ[/b]     ''Setup Object references that make this demo work
        Ser         : "FullDuplexSerial"
        MM2125      : "memsic2125"
    
    [b]PUB[/b] Main_Program | a,b
    
        Ser.start(31, 30, 0, 9600)      '' Initialize serial communication to the PC
    
        MM2125.start(MMx, MMy)                '' Initialize Mx2125
    
        [b]repeat[/b]
          a := MM2125.Mx            
          b := MM2125.My
    
          ser.dec(a)
          ser.tx(9)
          ser.dec(b)
          ser.tx(13)
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 12/16/2009 7:07:28 PM GMT
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2009-12-16 17:52
    Beau, I wired up my M2125 on my Stingray's breadboard and tested your code. It works fine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-16 19:05
    Roy Eltham,

    Thanks! - I appreciate that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-17 00:45
    I haven't been able to test this yet (been stuck in the library studying for exams), but I am sure it will work fine and will test it later tonight. Thanks!
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-17 00:47
    Sorry I just realized something and I realize this is a noob question, but since I am new to the propeller bare with me please ha ha.
    Which pins am I inputting the accelerometer too? Is it 13 and 9?
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-17 02:31
    noobmuncher,

    Pins 0 and 1

      MMx = 0
      MMy = 1
    
    



    The 9 and 13 are for the debug .... 9 indicates a TAB Space, while a 13 indicates a Return

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-17 02:33
    oh okay great thank you very much
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-17 03:27
    How could i modify this in order to output degrees on each axis?
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-17 06:39
    noobmuncher,

    Since it takes at least two vectors to determine a degree, you can't really display a deg for each axis.

    Only by combining the x and y axis can you determine a degree.

    The memsic2125 object does this for you by using a routine to convert the Cartesian X and Y coordinates into Polar coordinates ro and theta.

    In order to get these values so that they are 'human readable' there are a few conversions that you need to apply to the raw values.

    [b]CON[/b]     ''General Constants for Propeller Setup
      [b]_CLKMODE[/b] = [b]XTAL1[/b] + [b]PLL16X[/b]
      [b]_XINFREQ[/b] = 5_000_000
    
      MMx = 1
      MMy = 0
    
    [b]OBJ[/b]     ''Setup Object references that make this demo work
        Ser         : "FullDuplexSerial"
        MM2125      : "memsic2125"
    
    [b]PUB[/b] Main_Program | a,b,c,d,clk_scale
    
        Ser.start(31, 30, 0, 9600)  '' Initialize serial communication to the PC
        MM2125.start(MMx, MMy)      '' Initialize Mx2125
        [b]waitcnt[/b](clkfreq/10 + [b]cnt[/b])   'wait for things to settle 
        MM2125.setlevel             'assume at startup that the memsic2125 is level
                                    'Note: This line is important for determining a deg
    
        clk_scale := clkfreq / 500_000                      'set clk_scale based on system clock
                                         
    
        [b]repeat[/b]
          a := MM2125.Mx            'get RAW x value            
          b := MM2125.My            'get RAW y value
    
          c := MM2125.ro            'Get raw value for acceleration
          c := c / clk_scale        'convert raw acceleration value to mg's
          
          d := MM2125.theta         'Get raw 32-bit deg
          d := d >> 24              'scale 32-bit value to an 8-bit Binary Radian
          d := (d * 45)/32          'Convert Binary radians into Degrees
    
           
    
          ser.dec(a)                'Display RAW x value
          ser.tx(9)
          ser.dec(b)                'Display RAW y value
          ser.tx(9)
          ser.tx(9)      
          ser.dec(c)                'Display Acceleration value in mg's
          ser.tx(9)      
          ser.dec(d)                'Display Deg
          ser.tx(13)
    
    {{
    Note: At rest, normal RAW x [b]and[/b] y values should be at about 400_000 [b]if[/b] the Propeller is running at 80MHz.
    
    Since the frequency of the MM2125 is about 100Hz this means that the Period is 10ms... At rest this is a
    50% duty cycle, the signal that we are measuring is only HIGH for 5ms.  At 80MHz (12.5ns) this equates to
    a value of 400_000 representing a 5ms pulse width.  
    }}      
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-17 18:40
    Thank you! All of that is very good to know and the code is appreciated.
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-17 21:25
    Hello,

    So I tested this program and I must say it is pretty cool, but is there any way that it can be outputted in a style similar to the BS2 program MEMSIC2125-Dual.BS2?

    www.parallax.com/Portals/0/Downloads/src/prod/3rd/Memsic2125Demo.zip

    It would just be nice to be able to see

    x axis: (degree)
    y axis: (degree)

    Sorry for being a pain, thanks for the help though [noparse]:)[/noparse]
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-18 16:16
    noobmuncher,

    Ahhh, I see.... Tilt verses rotational Deg.


    Tilt is basically the rotational deg with respect to the horizon (A fixed vector), where the way the Memsic2125 object returns a Deg now is the rotational deg with respect to the X vector and Y vector.

    I'll update the current object, I can see how this would be very useful. I don't know why I didn't think to incorporate that into the Propeller Memsic2125 object before.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-18 17:36
    Would you mind linking to the object just so I don't end up with the wrong one or something, then also I will know when it's updated. Plus this will be good for anyone in the future who is reading this.

    Thanks alot Beau!
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-18 23:48
    noobmuncher,

    Try this code and see if that works for you and I will update the OBEX.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-19 18:22
    What am I doing wrong? When I open this in Propeller tool it just says PK at the top and that's it. It won't let me compile or anything. Is it in an odd format or something?
  • hover1hover1 Posts: 1,929
    edited 2009-12-19 18:50
    @ noob
    Compiles fine here. Maybe download the .zip again. May have gotten corupted.

    @ Beau
    Are you running a 6MHz xtal? I'm going to try it with a 5 and 6.25

    Jim
  • hover1hover1 Posts: 1,929
    edited 2009-12-19 18:59
    I guess I won't be trying it out. I only have Hitachi Tri-Axis modules.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-19 20:36
    hover1,

    Ohh yeah... sorry, yes I am running on a 6MHz crystal. All of my demo boards are tied up at the moment, and I was using an older board with a different crystal....

    Just change the header at the top of the Spin program to match your crystal setup.

    Change this...

    CON ''General Constants for Propeller Setup
    _CLKMODE = XTAL1 + PLL16X
    _XINFREQ = 6_000_000

    ...so that it reads...

    CON ''General Constants for Propeller Setup
    _CLKMODE = XTAL1 + PLL16X
    _XINFREQ = 5_000_000


    ... I will update the OBEX early next week with the default 5MHz setup.


    "I guess I won't be trying it out. I only have Hitachi Tri-Axis modules." - suppose the object for that should be updated as well, so that Tilt can also be displayed in addition to Rotational Deg.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 12/19/2009 8:43:56 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-19 20:39
    noobmuncher,

    The 'PK' indicates that it is a zipped file using the standard "PKzip" format... you need to unzip the file before loading it into the Propeller.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-12-21 01:00
    noobmuncher,

    Here is an example of what I think might be more like what you are looking for...

    http://forums.parallax.com/showthread.php?p=866419

    ...again, I'm not exactly sure why I didn't do something like that right off the bat.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • noobmunchernoobmuncher Posts: 124
    edited 2009-12-21 05:11
    Hello,

    Beau, just tried the code you wrote and it worked great, it was exactly what I needed so thank you very much. I think i will give this graphic one a whirl now too.

    Thanks!
Sign In or Register to comment.