My brother gave me the Memsic MXD1225 Dual Axis Accelerometer for Christmas! Consequently the next three days were spent playing with this sensor! This accelerometer is pretty neat because it uses an internat gas bubble to detect the acceleration on the x and y axes due to varying temperatures on each respective axis. The MXD2125 datasheet can be found on the parallax website mxd2125G&M.PDF and an good explaination about how the accelerometer works can be found in the SICmemsicTUT.PDF.
After many hours of playing with the arduino code (very similiar to C) I was able to generate code that calculated millig's (1/1000 of G). What this means is that a reading of 0 indicates that there is no force of gravity acting on the axis. In other words, the axis is perpendicular to gravity or parallel to the surface of the earth i.e. "level". When the reading is +/- 1000 there is 1000 millig's acting on the axis which is equivalent to 1 G or 9.81 m/s^2. You can convert millig's to G's by dividing the output by 1000. The following output is obtained when veiwing millig's:
In the hyperterminal output (I usually do not use windows but for some reason this was very buggy in Linux!) I was trying to hold the accelerometer level and you can see the small fluctuations with my hand. With the values close to 0, the board was relatively level as indicated. My next project is to convert the millig's into angles, which is not very simple. It's been done on the BASIC Stamp but trying to convert the functions and conversions to C on the arduino is a bit to wrap my head around! I will get it eventually! Once that is done it would be great to apply this to controlling a servo or motor and eventually lead to autopilot type applications.
The video below shows me tilting the accelerometer on each axis:
The left data field is the X-axis and the right data field is the Y-axis. I first tilted the X-up, which shows around -1000 which corresponds to -1G in the negative direction which is down towards the ground. I then tilted in down to the ground. The Hyperterminal output then showed 1000 which is +1G down. The Y-axis shows the same test in its axis. The accelerations due to me picking the board up can be seen with the wild jump in values. the breadboard isn't as level as it seems because the output when I set the accelerometer down is "-32 0" which is probably caused by the rubber band holding the Arduino down!
I figured out the algorithm after many hours of research and experimentation to convert the gravity on each axis to angle above horizontal! I searched through and read various documentation about programming for the Parallax BASIC Stamp to convert the output to an angle. However, I knew that the method used for the stamp is not worth pursuing with the Arduino and the Atmega168 microprocessor. The Stamp cannot do any floating point math whereas the Atmega 168 used in the Arduino can. In the code, I can include the math.h library and have acces to the trigonometry functions in the library! So the following code is what I ended up with and decided to share on the internet becuase I simply could not find a way to implement the Memsic MXD2125 Accelerometer (Radio Shack Parallax accelerometer module) with the arduino online.