I'm currently building a little lego segway and I thing I might have made a small misstake...
I'm using this formula to calculate an angle from the accelerometers raw data:
angle=((atan(y/sqrt(pow(x, 2)+pow(z,2))))*(180/3.14159265359));
This works just fine as long as the segway is lying down flat on a table. The accelerometer circuit board is mounted on my veroboard in such a way that it is also lying flat on a table when the entire segway is lying flat on a table. This position will give me an angle of about zero degrees. And if I raise the seaway up into an upright position the accelerometer shows around 90 degrees. So far so good. But if I tilt the segway more than 90 degrees the accelerometer shows less than 90 degrees. It seems as the accelerometer can't produce a value more than 90 degrees? As long as the segway is upright I have no way of knowing if it's tilting forwards or backwards. Is there a clever way to work around this or do I have no other choice then to mount the accelerometer the correct way?