# MMA orientation

Is there any reason why I can’t alter the arduino code slightly so I can use the Z axis of the MMA?

It would suit the positioning of my PCB better.

Failing that I will fit 90 degree pins to the MMA.

I fitted 90 degree pins to the MMA

@Alan.Webb did you finally alter the code or use 90 degree pins?

I’d like to install mine like shown in the picture below (in a box obviously). I ended up mounting it to the case with a short ribbon cable. That solved the orientation issue and also the pinout as I had an adafruit 8 pin module.

1 Like

Hello,

I use the z axis :
accelerometer.getRawData(&x_, &y_, &z_);
roll = z_; //Conversion uint to int
if (roll > 4200) roll = 4200; /* 4096 counts/g */
if (roll < -4200) roll = -4200;
rollK = - map(roll, -4200, 4200, -960, 960); //16 counts per degree (good for 0 - +/-30 degrees)

francois

1 Like

I’ve tried fitting my box in a 45 degree angle and of course I was looking for trouble But it fits so nice on the side panel like that so I’d like to give it a shot.

So just to make sure I got the implementation correct. The arduino sends angle*16 to the AOG in the serial message. However, in the .ino it’s just directly picking the raw acceleration value, hence I guess it’s just approximating arcsin(x) ~= x. Now, I just shifted the value to zero in the ino code and I get unstable heading, I presume due to the nonlinearity of the approximation. I guess introducing floating point math would kill the arduino performance, so either there would need to be a series expansion around the 45 degree point or the I just need to tilt the box to horizontal.

EDIT: I guess the offset point is correct. But the resolution is not. So 1 G = 2^14 = 16384 in the uint16 value with ±2 G range.This corresponds to 90 degrees tilt range. So near zero say 0±5 degrees gives a raw data value of sin(±5 deg)*16384 = ±1428. This gets converted to deg by dividing twice by 16, so AOG sees ±1428/256 = ±5.58 degrees of tilt when the actual is ±5 degrees. For ±10 degrees, it’s already ± ±11.1 degrees. With antenna height of 300 cm this gives a tilt error of +3.0 and +5.6 cm.

Now if the zero is at 45 deg, 45±5 degrees gives (sin(45±5 deg)-sin(45 deg))*16384 = -1054…966 raw value. Hence, if zeroed at 45 degrees, ±5 degrees actual tilt is seen in AOG as -4.12…3.77 degrees. For ±10 degrees, here it’s -8.55…7.17 degrees. So with the 300 cm antenna height error is -4.6…-6.4 cm and -7.5…-14.6 cm from actuals.

Did the calculations bit hastily and might be I got something wrong with understanding how the sensor data is defined, but any thoughts?

Z should be used as a vertical type of measurement as gravity will pull the accelerometer 90 degrees to how it was built. I am surprised it would work at all!

Come to think of it, why do we even need the angle at all, we’re directly getting the sine value from the sensor, like so: x_ is the uint16 raw data value, then we could just use that directly in AOG side and omit the sine evaluation from the correction code.