Class library for a LIS3DSH MEMS digital output motion sensor (acceleromoter).

Embed: (wiki syntax)

« Back to documentation index

LIS3DSH Class Reference

LIS3DSH Class Reference

Class library for a LIS3DSH MEMS digital output motion sensor (acceleromoter). More...

#include <LIS3DSH.h>

Public Member Functions

 LIS3DSH (PinName mosi, PinName miso, PinName clk, PinName cs)
 Create a LIS3DSH object connected to the specified pins.
int Detect (void)
 Determines if the LIS3DSH acceleromoter can be detected.
void WriteReg (uint8_t addr, uint8_t data)
 Write a byte of data to the LIS3DSH at a selected address.
uint8_t ReadReg (uint8_t addr)
 Read data from the LIS3DSH from a selected address.
void ReadData (int16_t *X, int16_t *Y, int16_t *Z)
 Reads the raw X, Y, Z values from the LIS3DSH as signed 16-bit values (int16_t).
void ReadAngles (float *Roll, float *Pitch)
 Reads the roll angle and pitch angle from the LIS3DSH.

Detailed Description

Class library for a LIS3DSH MEMS digital output motion sensor (acceleromoter).

Example:

 #include "mbed.h"
 #include "LIS3DSH.h"

 LIS3DSH acc(PA_7, PA_6, PA_5, PE_3);
 //          mosi, miso, clk , cs
 
 int main() {
    int16_t X, Y, Z;    //signed integer variables for raw X,Y,Z values
    float roll, pitch;  //float variables for angles
    
    if(acc.Detect() != 1) {
        printf("LIS3DSH Acceleromoter not detected!\n");
        while(1){ };
    }
    
    while(1) {
        acc.ReadData(&X, &Y, &Z);           //read X, Y, Z values
        acc.ReadAngles(&roll, &pitch);      //read roll and pitch angles
        printf("X: %d  Y: %d  Z: %d\n", X, Y, Z);
        printf("Roll: %f   Pitch: %f\n", roll, pitch);
       
        wait(1.0);  //delay before reading next values
    }
 }

Definition at line 61 of file LIS3DSH.h.


Constructor & Destructor Documentation

LIS3DSH ( PinName  mosi,
PinName  miso,
PinName  clk,
PinName  cs 
)

Create a LIS3DSH object connected to the specified pins.

Parameters:
mosiSPI compatible pin used for the LIS3DSH's MOSI pin
misoSPI compatible pin used for the LIS3DSH's MISO pin
clkSPI compatible pin used for the LIS3DSH's CLK pin
csDigitalOut compatible pin used for the LIS3DSH's CS pin

Definition at line 27 of file LIS3DSH.cpp.


Member Function Documentation

int Detect ( void   )

Determines if the LIS3DSH acceleromoter can be detected.

Parameters:
None
Returns:
1 = detected; 0 = not detected.

Definition at line 70 of file LIS3DSH.cpp.

void ReadAngles ( float *  Roll,
float *  Pitch 
)

Reads the roll angle and pitch angle from the LIS3DSH.

Parameters:
RollReference to variable for the roll angle (0.0 - 359.999999)
PitchReference to variable for the pitch angle (0.0 - 359.999999)
Returns:
None

Definition at line 93 of file LIS3DSH.cpp.

void ReadData ( int16_t *  X,
int16_t *  Y,
int16_t *  Z 
)

Reads the raw X, Y, Z values from the LIS3DSH as signed 16-bit values (int16_t).

Parameters:
XReference to variable for the raw X value
YReference to variable for the raw Y value
ZReference to variable for the raw Z value
Returns:
None

Definition at line 77 of file LIS3DSH.cpp.

uint8_t ReadReg ( uint8_t  addr )

Read data from the LIS3DSH from a selected address.

Parameters:
addr8-bit address from where the data should be read
Returns:
Contents of the register as a 8-bit data byte.

Definition at line 59 of file LIS3DSH.cpp.

void WriteReg ( uint8_t  addr,
uint8_t  data 
)

Write a byte of data to the LIS3DSH at a selected address.

Parameters:
addr8-bit address to where the data should be written
data8-bit data byte to write
Returns:
None

Definition at line 52 of file LIS3DSH.cpp.