Graphing Serial Data Arduino

  

Pitch Roll from an Accelerometer The C Continuum. One day, looking for cheap sensors on ebay, I found this interesting board which contained everything I was looking for. Diplay-Serial-Data-on-Real-Time-Graph-in-Labview.jpg' alt='Graphing Serial Data Arduino' title='Graphing Serial Data Arduino' />Graphing Serial Data ArduinoArduino Diecimila Board Available from the Make Store or from several other online resources. Note however that the techniques of this Instructable could be adapted. Air quality monitoring. Results Other types of realtime data have sites that users can share their data with the global Internet Community. It basically consists of a 3 axis accelerometer ADXL3. HMC5. 88. 3L, a 3 axis gyroscope L3. G4. 20. 0D and a barometric pressure sensor BMP0. My plan is to build an Inertial Measurement Unit IMU or maybe I should call it Attitude and heading reference system AHRS and in the process learn how to interact and interpret the information all of this sensors provide. The fact is I have some experience using IMUs since I used one on my master thesis and another one on the Avora AUV, but the fact is they come preprogrammed and there is not much point in working with the raw sensor data unless you want to improve the measurement or give it another use. For this project I am also using an Arduino Duemilanove, for that reason I wanted to call it Ardu. IMU, but there is already another project with the same name, so I will have to find another name suggestions would be appreciated. Connecting the sensor board to the Arduino is pretty straightforward, every sensor has an IC interface so you can access each of them using the Arduino Wire Library. Detroit Diesel Diagnostic Link Software Download on this page. The drawing was done using fritzing, on which I created the corresponding custom part for this board, although I did something wrong and it does not conform to the fritzing graphic standards. This will be the first of a series of posts I plan to write about this project, since there are several steps I need to take in order to fully understand each sensor and several more to combine them in order to improve accuracy. In this post I want to talk about the accelerometer and how to obtain the roll and pitch angles from it, which is a process that can also be called tilt sensing. Accelerometers are devices that are capable of measuring the acceleration they experience relative to free fall,  the same acceleration living beings feel. As a consequence, accelerometers are incapable of measuring the acceleration of gravity, but can be used to measure the upwards acceleration that counters gravity when at rest. This acceleration is measured as on the z axis, when both pitch and roll angles are zero, but when the sensor is tilted either the x axis or the y axis experiences a component of the upward acceleration, whose magnitude depends on the tilt angle. Pitch Roll estimation. Obtaining the pitch and roll angles is then a matter of being able to read the accelerometer, convert these readings to the g unit 1g 9. The process of obtaining and converting the accelerometer readings depends on the accelerometer you are using, in my case, the ADXL3. Generalizing, the formula used to calculate the acceleration from the accelerometer readings is Once we have the correct acceleration components, we can proceed to calculate the different angles using the following equations     For more information about where these equations come from, you can read the documentation I include at the end of this post. As you can see, the denominator of the pitch equation is defined to be always positive, so the equation itself only provides range, which is exactly what is expected for the pitch angle. In contrast, the roll equation provides range. It is important to take into account that when the pitch angle is 9. Gimbal Lock. Also, be aware that the roll equation is undefined when both and are equal to zero, and that for each possible value of the calculation done inside the arctan function there are two valid solutions, not only on the roll but also on the pitch equation. These problems can be easily solved in code by using the function atan. Removing short term fluctuations using a Low Pass filter. At this point we already have a fully functional pitch roll estimation system, but if we experiment with it we will discover that the readings fluctuate quite a bit and this may be very annoying for some applications. Removing these short term fluctuations can be achieved by means of what is called a Low Pass filter. This type of filter attenuates the higher frequencies of the signal, thus providing a smoother reading. The Low Pass filter is easily implemented by using the following equation Where is our filtered signal, the previous filtered signal, the accelerometer reading and the smoothing factor. It probably may seem obvious, but filtering should be done to the accelerometer readings before calculating the angles, instead of to the angles themselves. Regarding the smoothing factor, the lower we set it, the more it will take for the angle to stabilize, so we should not set it too low because then we could lose real time behaviour. With this I mean that the reading will not correspond to the real angle until it stabilizes, and this could take some time. The source code the ADXL3. I developed a small library to interface with the accelerometer, even though at the moment I have only implemented the basic functionality, I plan on supporting all of the device features. You can find it in my github account, where you can also find the processing code I used for the video example below. Thanks to the library, the code is pretty straightforward. It just reads the sensor accelerations which are already converted into gs by the library, applies the Low Pass filter and then uses the roll and pitch equations to calculate the angles. Wire. h. include lt ADXL3. Xg 0. double f. Yg 0. Zg 0. Serial. begin9. Xg, Yg, Zg. acc. read Xg, Yg, Zg. Low Pass Filter. f. Wireless Driver For Windows 8 64 Bit. Xg Xg alpha f. Xg 1. Yg Yg alpha f. Yg 1. Zg Zg alpha f. Zg 1. Roll Pitch Equations. Yg, f. Zg. 80. MPI. Xg, sqrtf. Yg. Yg f. Zg. Zg. MPI. Serial. Serial. print. Serial. The result. For a more interactive visualization of the data, I also developed an example using processing, which consists on a rotating 3. D cube. You can see the results in the following video. In the next post about my Arduino IMU, I will talk about how gyroscopes work and how to interpret the information they provide.