LSM9DS1 Library
0.7.0-alpha
C Library for the LSM9DS1 device.
|
Library for the LSM9DS1 from ST Microelectronics. Library makes use of the Linux platform device driver "spidev". The library was originally written for the RaspberryPi B+.
The LSM9DS1 provides 9 degrees of freedom (9-DOF), a 3 axis accelerometer, gyroscope and magnetometer. The accelerometer supports ± 2, 4, 8, or 16 g, the gyroscope supports ± 245, 500, and 2000 °/s, and the magnetometer has full-scale ranges of ± 2, 4, 12, or 16 gauss. It is equipped with a digital interface supporting both I2C and SPI.
Please see the releases to obtain prebuilt versions for the raspberrypi 3B+. Always use the latest version as only alpha version are released.
Install using RPM
Remember to replace v0.4.0-alpha with the appropriate version.
Uninstall using RPM
Remember to replace v0.4.0-alpha-1 with the appropriate version.
You can find the documentation here.
The API is simple to use. Here is a quick example of reading from the accelerometer.
This library depends on the cjson library by Dave Gamble. Please follow the installation steps to build for your system.
There are 2 options when building the LSM9DS1 Library.
You MUST have the SDK sourced to create a cross-compiled build for the raspberrypi system. (If you don't intend to build for this system you can skip this step.)
```bash source /opt/poky/2.6.2/environment-setup-cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi ```
Use the build shell script. This will use cmake and make to build for your system.
If building for release.
```bash ./build.sh release ```
If building for debugging purposes.
```bash ./build.sh debug ```
This project uses the the CUnit Testing Framwork. Tests can be run by running the lms9ds1_test program installed in the /usr/bin
directory.
You can remotely debug the application on the raspberry pi using gdbserver. A nice application to aid in debugging is gdbgui. You can install from the instructions foun here. In ubuntu also make sure you install gdb-multiarch if using ubuntu.
On the remote system, start the server.
```bash gdbserver localhost:5000 lsm9ds1_test ```
On the local machine start gdbgui.
```bash gdbgui -r -g gdb-multiarch ```
Pin Label | Pin Function | Notes |
---|---|---|
GND | Ground | 0V voltage supply |
VDD | Power Supply | Supply voltage to the chip. Should be regulated between 2.4V and 3.6V. |
SDA | SPI: MOSI I2C: Serial Data | SPI: Device data in (MOSI) I2C: Serial data (bi-directional) |
SCL | Serial Clock | I2C and SPI serial clock. |
DEN | Gyroscope Data Enable | Mostly unknown. The LSM9DS1 datasheet doesn't have much to say about this pin. |
INT2 | Accel/Gyro Interrupt 2 | INT1 and INT2 are programmable interrupts for the accelerometer and gyroscope. They can be set to alert on over/under thresholds, data ready, or FIFO overruns. |
INT1 | Accel/Gyro Interrupt 1 | |
INTM | Magnetometer Interrupt | A programmable interrupt for the magnetometer. Can be set to alert on over-under thresholds. |
RDY | Magnetometer Data Ready | An interrupt indicating new magnetometer data is available. Non-programmable. |
CS M | Magnetometer Chip Select | This pin selects between I2C and SPI on the magnetometer. Keep it HIGH for I2C, or use it as an (active-low) chip select for SPI. HIGH (1): SPI idle mode / I2C enabled LOW (0): SPI enabled / I2C disabled. |
CS AG | Accel/Gyro Chip Select | This pin selects between I2C and SPI on the accel/gyro. Keep it HIGH for I2C, or use it as an (active-low) chip select for SPI. HIGH (1): SPI idle mode / I2C enabled LOW (0): SPI enabled / I2C disabled. |
SDO M | SPI: Magnetometer MISO I2C: Magnetometer Address Select | In SPI mode, this is the magnetometer data output (SDO_M). In I2C mode, this selects the LSb of the I2C address (SA0_M) |
SDO AG | SPI: Accel/Gyro MISO I2C: Accel/Gryo Address Select | In SPI mode, this is the accel/gryo data output (SDO_AG). In I2C mode, this selects the LSb of the I2C address (SA0_AG) |