lsm9ds0: Initial implementation

This module implements support for the LSM9DS0 accelerometer,
magnetometer, and gyroscope.

It was developed on the Sparkfun 9DOF sensor block for Intel Edison.

https://www.sparkfun.com/products/13033

Commonly used capabilities are supported, and methods/register
definitions exist to easily implement any desired functionality that
is missing.  Interrupt support has also been added.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2015-07-31 16:17:49 -06:00
committed by Mihai Tudor Panu
parent 03e72e02f8
commit 36b0e1dce0
9 changed files with 2468 additions and 0 deletions

View File

@ -131,6 +131,7 @@ add_executable (pn532-writeurl-example pn532-writeurl.cxx)
add_executable (sainsmartks-example sainsmartks.cxx)
add_executable (mpu60x0-example mpu60x0.cxx)
add_executable (ak8975-example ak8975.cxx)
add_executable (lsm9ds0-example lsm9ds0.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -236,6 +237,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/grovecircularled)
include_directories (${PROJECT_SOURCE_DIR}/src/rgbringcoder)
include_directories (${PROJECT_SOURCE_DIR}/src/hp20x)
include_directories (${PROJECT_SOURCE_DIR}/src/pn532)
include_directories (${PROJECT_SOURCE_DIR}/src/lsm9ds0)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -368,3 +370,4 @@ target_link_libraries (pn532-writeurl-example pn532 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (sainsmartks-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mpu60x0-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (ak8975-example mpu9150 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lsm9ds0-example lsm9ds0 ${CMAKE_THREAD_LIBS_INIT})

83
examples/c++/lsm9ds0.cxx Normal file
View File

@ -0,0 +1,83 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "lsm9ds0.h"
using namespace std;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate an LSM9DS0 using default parameters (bus 1, gyro addr 6b,
// xm addr 1d)
upm::LSM9DS0 *sensor = new upm::LSM9DS0();
sensor->init();
while (shouldRun)
{
sensor->update();
float x, y, z;
sensor->getAccelerometer(&x, &y, &z);
cout << "Accelerometer: ";
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
sensor->getGyroscope(&x, &y, &z);
cout << "Gryoscope: ";
cout << "GX: " << x << " GY: " << y << " GZ: " << z << endl;
sensor->getMagnetometer(&x, &y, &z);
cout << "Magnetometer: ";
cout << "MX = " << x << " MY = " << y << " MZ = " << z << endl;
cout << "Temperature: " << sensor->getTemperature() << endl;
cout << endl;
usleep(500000);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}