Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
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 EZ-Builder.

User-inserted image


Address

Code:


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


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

Code:


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

Code:


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.

Code:


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

Code:


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.

Code:


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

Code:


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


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.