Using accelerometer on TeensyWiNo

The TeensyWiNo embeds a triple-axis accelerometer and a digital compass (magnetometer) bundle in the same component : the LSM303CTR made STMicroelectronics. It as a I2C component that allow you to to measure acceleration or direction towards the center or the earth (by measuring gravity), and measure magnetic force in order to locate magnetic north.

What are the libraries needed ?

First of all, you will need to install relevant libraries.

Unified Sensor Driver

This library (Apache 2.0 licence) reduce all data to a single sensors_event_t ‘type’ and sets on specific, standardised SI units for each sensor family the same sensor types return values that are comparable with any other similar sensor.  It becomes fairly easy to use all kind of sensors !

You will need it for most of sensors. Just pop at https://github.com/winocc/sensor and download it into your Arduno librairie folder.

LSM303 Driver

This driver is based on the former library and originally developped by Adafruit.

If this library is not already included in your Arduino installation,  download and install this driver

More information on the LSM303CTR can be found in the relevant datasheet.

My first code running

Once all librairies installed, just open the accelsensor example code that you will find under File > Example > Adafruit LSM303

You can view it online here : https://github.com/winocc/LSM303/blob/master/examples/accelsensor/accelsensor.pde

Looking at the serial Monitor, you should get an output like :

 X: 0.89 Y: 0.23 Z: 9.53 m/s^2

X: 0.89 Y: 0.23 Z: 9.52 m/s^2

X: 0.89 Y: 0.22 Z: 9.52 m/s^2

X: 0.88 Y: 0.22 Z: 9.53 m/s^2 

In this situation, WiNo is standing still on the table and this is totally normal not to have 0 values for all coordinates : every object is under the influence of earth gravity (9.81 m/s^2).

Looking deeper, we can see that measured gravity by the WiNo is slighlty different. We get a measured earth gravity of 9.57 m/s^2.

Her again, this is totally normal. Every sensor needs to be more or less calibrated. You will find on our github account an example code with software calibration : https://github.com/winocc/LSM303/blob/master/examples/accelsensor_software_calibrated/accelsensor_software_calibrated.ino or, again, under File > Example > Adafruit LSM303.

Going deeper

You can find some informations about “Computing tilt measurement and tilt-compensated e-compass”, “Ellipsoid or sphere fitting for sensor calibration ” or “Exploiting the gyroscope to update tilt measure and e-compass” here :

http://www.st.com/content/st_com/en/products/mems-and-sensors/e-compasses/lsm303c.html

In some documents it is advised to use Quaternions and Cordic Algorithm

Here is a potentially useful reasearch paper but unfortunately a link to the source code is not provided : http://franciscoraulortega.com/pubs/Algo3DFusionsMems.pdf

Another one : https://www.academia.edu/29075877/3DCane_A_Monitoring_System_for_the_Elderly_using_a_Connected_Walking_Stick/





Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Leave a Reply