Asked — Edited

MMA7455L Accelerometer

*Note: this is temporary until the next SDK is released. Then this page will change because there will be an embedded class in the EZ-SDK and ARC.

User-inserted image

Address


    byte ITGWriteAddress = 0x1D << 1;
    byte ITGReadAddress = (0x1D << 1) + 1;

i2cRead - Create a generic function to read from the device (1 byte at a time)


    byte i2cRead(byte registerAddress) {

      ezB_Connect1.EZB.I2C.Start();

      ezB_Connect1.EZB.I2C.Write(new byte[] { ITGWriteAddress, registerAddress });

      ezB_Connect1.EZB.I2C.Restart();

      ezB_Connect1.EZB.I2C.Write(new byte[] { ITGReadAddress });
      byte val = ezB_Connect1.EZB.I2C.Read(false);

      ezB_Connect1.EZB.I2C.Stop();

      return val;
    }

Who Am I - Assuming you have a multiline textBox1 on your form, this will write the contents of who am i register to it


      textBox1.AppendText("Who Am I: ");
      textBox1.AppendText(i2cRead(0x0f).ToString());
      textBox1.AppendText(Environment.NewLine);

Set Mode - Look at the datasheet. The mode is being set to 0101. This needs to be done before any readings will work.


      i2cWrite(new byte[] { 0x16, Functions.ToByteFromBinary(0, 0, 0, 0, 0, 1, 0, 1) });

Who Am I - Assuming you have a multiline textBox1 on your form, this will write the contents of who am i register to it


      textBox1.AppendText("Who Am I: ");
      textBox1.AppendText(i2cRead(0x0f).ToString());
      textBox1.AppendText(Environment.NewLine);

Get Mode - Assuming you have a multiline textBox1 on your form, this will write the contents of the mode register.


      textBox1.AppendText("Get Mode: ");
      textBox1.AppendText(Functions.ByteToBinaryString(i2cRead(0x16)));
      textBox1.AppendText(Environment.NewLine);

Get Angles (8 bit) - This will read the current angle of the PCB in X, Y and Z


      byte x = i2cRead(0x06);
      byte y = i2cRead(0x07);
      byte z = i2cRead(0x08);


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.