The attached example code uses a NI myDAQ and a multi-axis accelerometer to determine pitch and roll attitudes.
The MX2125 accelerometer uses a simple design premise to perform static acceleration measurements that can be converted to a pitch or roll angle. The accelerometer "has a chamber of gas with a heating element in the center and four temperature sensors around its edge. Just as hot air rises and cooler air sinks, the same applies to hot and cool gasses. If you hold the accelerometer still, all it senses is gravity, and tilting it gives us an example of how it senses static acceleration. When you hold the accelerometer level, the hot gas pocket...rises to the top-center of the accelerometer's chamber, and all the temperature sensors measure the same temperature. Depending on how you tilt the accelerometer, the hot gas will collect closer to one or maybe two of the temperature sensors." This sensed acceleration can then be converted to a pitch or roll angle via basic trigonometric functions, using known gravitational acceleration. The accelerometer works by generating a pulse train where the duty cycle of the pulse is proportional to the acceleration.
Steps to Implement or Execute Code
- Install the accelerometer on the protoboard and wire per the diagram in the pdf file within the Zip folder. Be especially careful to place the accelerometer so that the x-axis is pointing down the long axis of the protoboard
- Build a VI to acquire multiple channels at multiple samples a second using the DAQ clock. Start by creating a channel and entering in timing controls
- Then create a while loop with the read in it. Extract data from the array into the two channels using the index array function from the array palette. Plot both on a waveform graph and configure the VI parameters per the attached front panel which is included in the Zip folder.
- Run the VI. You should see two data streams with pulse width modulated data streams. The pulse width should increase as you pitch the protoboard up or roll the right. It should also change size as you slide the protoboard along the lab desk in the directions of the y-axis and x-axis. You may have to adjust the number of points displayed on the waveform graph to be able to see the size change. You can do this by clicking on the x-scale and right-clicking. Then on the x-scale submenu, disable autoscaling. Use the number of samples/channel and sample rate as in the front panel
- Now we need to turn the pulse widths into readings of g and angle. The ADI SubVI.vi implements this conversion
- Enter the necessary inputs into the front panel of the VI, be sure to set the proper Physical Channels for your NI myDAQ device.
- Run the code and observed the measured Pitch Angle as you tilt the mounted accelerometer in various directions
Requirements to Run
LabVIEW 9.0 or later (or compatible)
NI-DAQmx 9.1.5 (or compatible)
Memsic 2125 Accelerometer
10 µF Capacitor
7805 +5V Fixed-Voltage Regulator
**This document has been updated to meet the current required format for the NI Code Exchange. **