LSM9DS1 Library  0.7.0-alpha
C Library for the LSM9DS1 device.
Data Structures | Macros | Typedefs | Functions
lsm9ds1.h File Reference

Functions to access the lsm9ds1. More...

#include <stdbool.h>
#include <stdint.h>
#include "lsm9ds1_debug.h"
#include "lsm9ds1_config.h"
Include dependency graph for lsm9ds1.h:

Go to the source code of this file.

Data Structures

struct  lsm9ds1_data_t
 Stores the raw data for each sub device. More...
 
struct  accelerometer_converted_data_t
 
struct  mag_converted_data_t
 
struct  gyro_converted_data_t
 
struct  lsm9ds1_converted_data_t
 Stores the converted data for each sub device. More...
 
struct  lsm9ds1_device_t
 Data and configurations for the lsm9ds1 device. More...
 

Macros

#define _BUILD_VERSION   BUILD_VERSION
 

Typedefs

typedef struct lsm9ds1_data_t lsm9ds1_data_t
 Stores the raw data for each sub device.
 
typedef struct accelerometer_converted_data_t accelerometer_converted_data_t
 
typedef struct mag_converted_data_t mag_converted_data_t
 
typedef struct gyro_converted_data_t gyro_converted_data_t
 
typedef struct lsm9ds1_converted_data_t lsm9ds1_converted_data_t
 Stores the converted data for each sub device.
 
typedef struct lsm9ds1_device_t lsm9ds1_device_t
 Data and configurations for the lsm9ds1 device.
 

Functions

lsm9ds1_status_t get_temp (lsm9ds1_temperature_t *temperature)
 Read the temperature of the LSM9DS1. More...
 
lsm9ds1_status_t get_accel (accelerometer_converted_data_t *data)
 Read the accelerometer of the LSM9DS1. More...
 
lsm9ds1_status_t get_mag (mag_converted_data_t *data)
 Read the magnetometer of the LSM9DS1. More...
 
lsm9ds1_status_t get_gyro (gyro_converted_data_t *data)
 Read the gyroscope from the LSM9DS1. More...
 
lsm9ds1_status_t lsm9ds1_init ()
 Initialize the LSM9DS1. More...
 
lsm9ds1_status_t lsm9ds1_close ()
 Close the LSM9DS1. More...
 

Detailed Description

Functions to access the lsm9ds1.

Author
Christopher Jordan-Denny
Date
Initializes the LSM9DS1 for the Raspberry Pi 3B+. Currently the device is wired to the first spi device. Sets up the magnetometer, accelerometer and gyroscope. Provides functions to read and write the data collected on the LSM9DS1.

Function Documentation

◆ get_accel()

Read the accelerometer of the LSM9DS1.

Get the current converted accelerometer reading. The X, Y and Z coordinates are returned by this function.

Example Usage:

#include <lsm9ds1.h>
int main() {
lsm9ds1_status_t status = LSM9DS1_UNKNOWN_ERROR;
status = lsm9ds1_init();
if(status < 0) {
fprinf(stderr, "Error initializing lsm9ds1!\n");
}
status = get_accel(&data);
if(status < 0) {
fprintf(stderr, "Error reading accelerometer!\n");
}
printf("Accelerometer x: %f\n", data.x);
printf("Accelerometer y: %f\n", data.y);
printf("Accelerometer z: %f\n", data.z);
return status;
}
Parameters
datathe converted data read from the accelerometer.
See also
accelerometer_converted_data_t
Returns
Returns the function status as defined in lsm9ds1_status_t.
See also
lsm9ds1_status_t
Note
You must first initialize the lsm9ds1.
See also
lsm9ds1_init

◆ get_gyro()

Read the gyroscope from the LSM9DS1.

Get the current converted gyroscope reading. The X, Y and Z coordinates are returned by this function.

Example Usage:

#include <lsm9ds1.h>
int main() {
lsm9ds1_status_t status = LSM9DS1_UNKNOWN_ERROR;
status = lsm9ds1_init();
if(status < 0) {
fprinf(stderr, "Error initializing lsm9ds1!\n");
}
status = get_gyro(&data);
if(status < 0) {
fprintf(stderr, "Error reading gyroscope!\n");
}
printf("Gyroscope x: %f\n", data.x);
printf("Gyroscope y: %f\n", data.y);
printf("Gyroscope z: %f\n", data.z);
return status;
}
Parameters
datathe converted data read from the gyroscope.
See also
gyro_converted_data_t
Returns
Returns the function status as defined in lsm9ds1_status_t.
See also
lsm9ds1_status_t
Note
You must first initialize the lsm9ds1.
See also
lsm9ds1_init

◆ get_mag()

Read the magnetometer of the LSM9DS1.

Get the current converted magnetometer reading. The X, Y and Z coordinates are returned by this function.

Example Usage:

#include <lsm9ds1.h>
int main() {
lsm9ds1_status_t status = LSM9DS1_UNKNOWN_ERROR;
status = lsm9ds1_init();
if(status < 0) {
fprinf(stderr, "Error initializing lsm9ds1!\n");
}
status = get_mag(&data);
if(status < 0) {
fprintf(stderr, "Error reading magnetometer!\n");
}
printf("Magnetometer x: %f\n", data.x);
printf("Magnetometer y: %f\n", data.y);
printf("Magnetometer z: %f\n", data.z);
return status;
}
Parameters
datathe converted data read from the magnetometer.
See also
mag_converted_data_t
Returns
Returns the function status as defined in lsm9ds1_status_t.
See also
lsm9ds1_status_t
Note
You must first initialize the lsm9ds1.
See also
lsm9ds1_init

◆ get_temp()

lsm9ds1_status_t get_temp ( lsm9ds1_temperature_t *  temperature)

Read the temperature of the LSM9DS1.

Get the current converted temperature reading

Example Usage:

#include <lsm9ds1.h>
int main() {
lsm9ds1_status_t status = LSM9DS1_UNKNOWN_ERROR;
status = lsm9ds1_init();
if(status < 0) {
fprinf(stderr, "Error initializing lsm9ds1!\n");
}
lsm9ds1_temperature_t data = 0;
status = get_temp(&data);
if(status < 0) {
fprintf(stderr, "Error reading temperature!\n");
}
printf("Temperature: %f\n", data);
return status;
}
Parameters
datathe converted data read from the temperature monitor
See also
lsm9ds1_temperature_t
Returns
Returns the function status as defined in lsm9ds1_status_t.
See also
lsm9ds1_status_t
Note
You must first initialize the lsm9ds1.
See also
lsm9ds1_init

◆ lsm9ds1_close()

lsm9ds1_status_t lsm9ds1_close ( )

Close the LSM9DS1.

Close the open buses.

Example Usage:

#include <lsm9ds1.h>
int main() {
lsm9ds1_status_t status = LSM9DS1_UNKNOWN_ERROR;
status = lsm9ds1_init();
if(status < 0) {
fprinf(stderr, "Error initializing lsm9ds1!\n");
}
status = lsm9ds1_close();
if(status < 0) {
fprinf(stderr, "Error closing lsm9ds1!\n");
}
return status;
}
Returns
Returns the function status as defined in lsm9ds1_status_t.
See also
lsm9ds1_status_t

◆ lsm9ds1_init()

lsm9ds1_status_t lsm9ds1_init ( )

Initialize the LSM9DS1.

Initialize the lsm9ds1 according to the configuration file found in /etc/lsm9ds1.json. This function only has to be called once.

Example Usage:

#include <lsm9ds1.h>
int main() {
lsm9ds1_status_t status = LSM9DS1_UNKNOWN_ERROR;
status = lsm9ds1_init();
if(status < 0) {
fprinf(stderr, "Error initializing lsm9ds1!\n");
}
return status;
}
Returns
Returns the function status as defined in lsm9ds1_status_t.
See also
lsm9ds1_status_t