LIS302 Accelerometer

An LIS302 is a 3-axis accelerometer, accessible via a digital SPI interface with a selectable range of 2g or 8g.

LIS302 Breakout

Hello World!

» Import this program

// LIS302 Hello World! moves leds based on x acceleration

#include "mbed.h"
#include "LIS302.h"

LIS302 acc(p5, p6, p7, p8); // mosi, miso, sclk, ncs
BusOut leds(LED1, LED2, LED3, LED4);

int main() {
    while(1) {
        leds = 1 << (int)(4 * acc.x());
        wait(0.1);
    }
}
LIS302 Signal Namembed pin
VccVout
GndGnd
SCLp7
MOSIp5
MISOp6
CSp8

Hello World Wiring

Library

» Import this library into a program

Public Member Functions

  LIS302 (PinName mosi, PinName miso, PinName clk, PinName ncs)
  Create an LIS302 interface, connected to the specified pins.
float  x ()
  Read the X axis acceleration.
float  y ()
  Read the Y axis acceleration.
float  z ()
  Read the Z axis acceleration.
void  range (int g)
  Select the range of the accelerometer.
void  calibrate (float maxx=1, float minx=-1, float maxy=1, float miny=-1, float maxz=1, float minz=-1)
  Configure the minima and maxima for the axes to linearise the readings.

Reference