In this example we connect a LIS3DSH sensor to a Linkit One. Lets look at the sensor first of all
The LIS3DSH is an ultra-low-power high-performance three-axis linear accelerometer belonging to the “nano” family with an embedded state machine that can be programmed to implement autonomous applications.
The LIS3DSH has dynamically selectable full scales of ±2g/±4g/±6g/±8g/±16g and is capable of measuring accelerations with output data rates from 3.125 Hz to 1.6 kHz. The self-test capability allows the user to check the functioning of the sensor in the final application. The device can be configured to generate interrupt signals activated by user-defined motion patterns.
The LIS3DSH has an integrated first-in, first-out (FIFO) buffer allowing the user to store data in order to limit intervention by the host processor. The LIS3DSH is available in a small thin plastic land grid array package (LGA) and is guaranteed to operate over an extended temperature range from -40 °C to +85 °C.
Key Features
- Wide supply voltage, 1.71 V to 3.6 V
- Independent IOs supply (1.8 V) and supply voltage compatible
- Ultra-low power consumption
- ±2g/±4g/±6g/±8g/±16g dynamically selectable full scale
- I2C/SPI digital output interface
- 16-bit data output
- Programmable embedded state machines
- Embedded temperature sensor
- Embedded self-test
- Embedded FIFO
- 10000 g high shock survivability
Parts List
Part | Link |
Linkit One | |
LIS3DSH module | CJMCU- LIS3DSH High-resolution Three-axis Accelerometer Triaxial Accelerometer Module LIS3DH |
Connecting Wire | Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire |
Connection
An easy device to connect – remember its 3.3v
Code
You need to download and install the https://github.com/yazug/LIS3DSH library
[codesyntax lang=”cpp”]
#include <Wire.h> #include <LIS3DSH.h> LIS3DSH accel; void setup() { Serial.begin(9600); Wire.begin(); accel.enableDefault(); } void loop() { int16_t x, y, z; int8_t temperature; accel.readAccel(&x, &y, &z); accel.readTemperature(&temperature); Serial.print("Accel "); Serial.print("X: "); Serial.print(x); Serial.print(" Y: "); Serial.print(y); Serial.print(" Z: "); Serial.print(z); Serial.print(" T: "); Serial.println(temperature); delay(100); }
[/codesyntax]
Output
Open the serial monitor and you should see something like this – move the module around
Accel X: -383 Y: 674 Z: -12240 T: 28
Accel X: 3642 Y: 12416 Z: 14535 T: 28
Accel X: 20419 Y: 18191 Z: -23659 T: 28
Accel X: 20252 Y: 18191 Z: -23659 T: 28
Accel X: -9557 Y: -6184 Z: 15569 T: 29
Accel X: 30051 Y: 4745 Z: 9674 T: 28
Accel X: 8030 Y: 20493 Z: 7677 T: 28
Accel X: 32760 Y: 22656 Z: 3626 T: 28
Accel X: 32540 Y: 22656 Z: 3626 T: 28
Accel X: 26287 Y: 20544 Z: 5130 T: 28
Accel X: 26140 Y: 20544 Z: 5130 T: 28
Link