MMA7361L 3-Axis Accelerometer ±1.5/6g with Voltage Regulator

I just got this cool Accelerometer from Pololu.com… I have been successful in interfacing it with my fez domino…

Driver


 public class Accelerometer
    {
        public enum GSelect:sbyte
        {
            Hi,
            Low
        }

        private static object syncRoot = new object();
        private AnalogIn pinX, pinY, pinZ;
        private GSelect gSel;
        private static Accelerometer objAccMeter = null;

        private Accelerometer()
        {
          
        }

        public static Accelerometer Instance
        {
            get 
            {
                lock (syncRoot)
                {
                    if (objAccMeter == null)
                        throw new NullReferenceException("Object not initialized.");
                    else
                        return objAccMeter;
                }
            }
        }

        public static Accelerometer Initialize(FEZ_Pin.AnalogIn pPinX, FEZ_Pin.AnalogIn pPinY, FEZ_Pin.AnalogIn pPinZ, GSelect pGSel)
        {
            lock (syncRoot)
            {
                if (objAccMeter == null)
                {
                    objAccMeter = new Accelerometer() { 
                        pinX = new AnalogIn((AnalogIn.Pin)pPinX),
                        pinY = new AnalogIn((AnalogIn.Pin)pPinY),
                        pinZ = new AnalogIn((AnalogIn.Pin)pPinZ),
                        gSel = pGSel };
                    objAccMeter.pinX.SetLinearScale(0, 3300);
                    objAccMeter.pinY.SetLinearScale(0, 3300);
                    objAccMeter.pinZ.SetLinearScale(0, 3300);
                }
                return objAccMeter;
            }
        }

        public void Read_G_Values(out float XVal, out float YVal, out float ZVal)
        {
            float divVal = (float)((gSel == GSelect.Hi) ? 206 : 800);
            XVal = (float)((pinX.Read() - 1650) / (divVal));
            YVal = (float)((pinY.Read() - 1650) / (divVal));
            ZVal = (float)((pinZ.Read() - 1650) / (divVal));
        }

        public void Dump()
        {
            Microsoft.SPOT.Debug.Print("X: "+pinX.Read().ToString()+"\nY: "+pinY.Read().ToString()+"\nZ: "+pinZ.Read().ToString());
        }

    }

The Read_G_Vals method converts the incoming raw data into G values…

The board uses 3 Analog pins and is powered by Fez’s 3V3 pin. A G select ping on the board allows us to set the G-Range ±1.5G and ±6G.

Note: The driver is still crude and needs some work…

You should add it to www.fezzer.com :wink:

Already there ;D

Thanks for posting this.

I was looking at getting one of these and this will make it FEZzy for me.

U r welcome #mhectorgato

Just an FYI… In my testing i have found that the sensor is sensitive to temperature variations. which is not taken into account in the driver. However if the intended use is to find the direction of motion or just approximate G values, i would say its a great buy.

To just get the direction of motion just subtract 1650 from the X,Y,Z values, the sign of the resultant represents the direction.

Could we use this way of getting direction (subtract 1650) on any Accelerometer, i.e the one that is sell on tinyclr hardware page (smb380)??

Thanks,
sam

#Sam
No you cannot do the same for SMB3080. There are core differences between the two is that MMA is an Analog device where as SMB is digital… The both behave in a different way.

The number 1650 is derived from the fact that MMA’s axis output is centered around half of the Vin.

But i would assume there is a similar approach available in SMB3080 too… Using accelerometers for getting direction is quiet common.

Tanu:

Thanks for the info.

Since I’m a h/w n00b …

I’ll be using this with a Domino and a Component Shield (JST connectors).

I’m not quite sure what needs to be connected and what can be left open. The docs say the g-Select, Test and 0g-Detect pin can be unwired.

The JST will provide 3v3, so do I need use the Vin and the 3V3 in?

So I’m guessing it’s wired like this:

  • 3 JSTs into 3 analog ports on the shield.
  • From the shield to the MMA:

Vin = open (assuming that the 3v3 can be used alone)
Gnd - using the 1st JST’s black
3v3 - using the 1st JST’s red

X - 1st JST’s white (data)
Y - 2nd JST’s white
Z - 3rd JST’s white
(assuming I don’t need/want the other 3 connected)

Thanks

Your setup is correct. You may want to connect the second 3v3 to G select if you intend on measuring ±6G, otherwise the default is ±1.5G.

Make sure X,Y,Z are connected to analog pins only.

Have fun :slight_smile:

Since this initially will be for a very simple autonomous (ground) vehicle - using low powered brushed DC motors, I’m not expecting readings of greater than 1.5G :smiley:

This primarily is more about learning than filling an actual need for my project.

My plan is to see if I could use this inexpensive device to determine if I am stuck. I’m essentially going out of my way to see if I could find a use for the $15 part :wink:

Thanks again.