Shop OBEX P1 Docs P2 Docs Learn Events
MMA7660 sample code? — Parallax Forums

MMA7660 sample code?

VonSzarvasVonSzarvas Posts: 3,450
edited 2012-05-29 03:42 in Accessories
Anyone got the MMA7660 sensor working with the Propeller ?

Looking for some sample code... can be SPIN, PASM, PropBasic!, or even SX/B or some other B-Stamp format. I would be converting to PropBasic, so will publish the code back here when working unless someone has beaten me to it?

Thanks for any help.

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-05-28 20:52
    Sorry, I have only just come across your post. I have the MMA7660 working under Propforth 4.6 but it should be straightforward to convert to Spin etc.
    hex
    \ MMA7660 Accelerometer code
    \ Using Propforth 4.6
    
    : @I2C    \ ( device -- ) \ Select device
        i2cstart i2cwrite drop ;
    
    : @ACC    \ ( reg -- ) Select Register
        98 @I2C i2cwrite drop ;
    
    : ACC!    \ ( data reg -- ) Write Register
        @ACC i2cwrite drop i2cstop ;
    
    : ACC@       \ ( reg -- dat ) Read Register  
        @ACC 99 @I2C 1 i2cread i2cstop ;
    
    : XYZ@      \ ( -- long ) Read first four registers as a long  
        0 @ACC 99 @I2C 0 i2cread 0 i2cread 0 i2cread 1 i2cread i2cstop
            18 lshift swap 10 lshift + swap 8 lshift + + ;
    
    : !ACC      \ Init the Accelerometer   
        i2cstop 0 7 ACC! 0 5 ACC! 10 6 ACC! 34 8 ACC! e0 9 ACC!  62 8 ACC! 0 A ACC! 41 7 ACC! ;
    
    \ List the accelerometer registers
    : SHOW       0 @ACC 99 @I2C hex 0b 0 do i 0a = i2cread .byte 20 emit loop i2cstop ;
    
  • VonSzarvasVonSzarvas Posts: 3,450
    edited 2012-05-29 03:42
    Thank you Peter.

    Have it solved now.. Very nice to see the readings for shake and orientation working correctly! I will experiment a bit more with making sense of the acceleration data (as I wish to provide a record of movement along a plane, and I think that would also be useful for others), then I will clean up and post the code.

    :)
Sign In or Register to comment.