Skip to content

Commit

Permalink
Merge pull request #1 from grobx/main
Browse files Browse the repository at this point in the history
LIS2DU12 Version 1.0.0
  • Loading branch information
cparata authored Jul 25, 2022
2 parents 8423fcb + 7115b9f commit 1db7a23
Show file tree
Hide file tree
Showing 10 changed files with 3,807 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/Continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: LIS2DU12 Continuous Integration
on:
push:
branches:
- main
paths-ignore:
- '*'
- '**.md'
- '**.txt'
pull_request:
paths-ignore:
- '*'
- '**.md'
- '**.txt'
jobs:
astyle_check:
runs-on: ubuntu-latest
name: AStyle check
steps:
# First of all, clone the repo using the checkout action.
- name: Checkout
uses: actions/checkout@main

- name: Astyle check
id: Astyle
uses: stm32duino/actions/astyle-check@main

# Use the output from the `Astyle` step
- name: Astyle Errors
if: failure()
run: |
cat ${{ steps.Astyle.outputs.astyle-result }}
exit 1
spell-check:
runs-on: ubuntu-latest
name: Spell check
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Spell check
uses: codespell-project/actions-codespell@master
with:
ignore_words_file: ./extras/codespell-ignore-words-list.txt
lib_build:
runs-on: ubuntu-latest
name: Library compilation
steps:

# First of all, clone the repo using the checkout action.
- name: Checkout
uses: actions/checkout@main

- name: Compilation
id: compile
uses: stm32duino/actions/compile-examples@main
with:
board-pattern: "NUCLEO_L476RG"

# Use the output from the `Compilation` step
- name: Compilation Errors
if: failure()
run: |
cat ${{ steps.compile.outputs.compile-result }}
exit 1
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# LIS2DU12

Arduino library to support the LIS2DU12 ultra-low-power 3D accelerometer

## API

This sensor uses I2C or SPI to communicate.
For I2C it is then required to create a TwoWire interface before accessing to the sensors:

TwoWire dev_i2cf(I2C_SDA, I2C_SCL);
dev_i2c.begin();

For SPI it is then required to create a SPI interface before accessing to the sensors:

SPIClass dev_spi(SPI_MOSI, SPI_MISO, SPI_SCK);
dev_spi.begin();

An instance can be created and enabled when the I2C bus is used following the procedure below:

LIS2DU12Sensor Accelero(&dev_i2c);
Accelero.begin();
Accelero.Enable_X();

An instance can be created and enabled when the SPI bus is used following the procedure below:

LIS2DU12Sensor Accelero(&dev_spi, CS_PIN);
Accelero.begin();
Accelero.Enable_X();

The access to the sensor values is done as explained below:

Read accelerometer.

int32_t accelerometer[3];
Accelero.Get_X_Axes(accelerometer);

## Documentation

You can find the source files at
https://github.com/stm32duino/LIS2DU12

The LIS2DU12 datasheet is available at
https://www.st.com/content/st_com/en/products/mems-and-sensors/accelerometers/lis2du12.html
44 changes: 44 additions & 0 deletions examples/LIS2DU12_DataLog_Terminal/LIS2DU12_DataLog_Terminal.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
@file LIS2DU12_DataLog_Terminal.ino
@author Giuseppe Roberti <[email protected]>
@brief Example to use the LIS2DU12 advanced Ultra Low Power 3D
accelerometer
*******************************************************************************
Copyright (c) 2022, STMicroelectronics
All rights reserved.
This software component is licensed by ST under BSD 3-Clause license,
the "License"; You may not use this file except in compliance with the
License. You may obtain a copy of the License at:
opensource.org/licenses/BSD-3-Clause
*******************************************************************************
*/

#include <LIS2DU12Sensor.h>

LIS2DU12Sensor sensor (&Wire);
uint8_t sensor_id;
int32_t acceleration[3];

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
Wire.begin();
sensor.begin();
sensor.Enable_X();
sensor.ReadID(&sensor_id);
}

void loop() {
sensor.Get_X_Axes(acceleration);
Serial.printf(
"Id:%d, X:%d, Y:%d, Z:%d\r\n",
sensor_id, acceleration[0], acceleration[1], acceleration[2]);
blink(LED_BUILTIN);
}

void blink(uint8_t pin) {
digitalWrite(pin, HIGH);
delay(25);
digitalWrite(pin, LOW);
delay(975);
}
1 change: 1 addition & 0 deletions extras/codespell-ignore-words-list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ois
40 changes: 40 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#######################################
# Syntax Coloring Map For LIS2DU12
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

LIS2DU12Sensor KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
end KEYWORD2
Enable_X KEYWORD2
Disable_X KEYWORD2
ReadID KEYWORD2
Get_X_Axes KEYWORD2
Get_X_AxesRaw KEYWORD2
Get_X_Sensitivity KEYWORD2
Get_X_ODR KEYWORD2
Set_X_ODR KEYWORD2
Get_X_FS KEYWORD2
Set_X_FS KEYWORD2
Set_Interrupt_Latch KEYWORD2
Enable_DRDY_Interrupt KEYWORD2
Disable_DRDY_Interrupt KEYWORD2
Set_X_SelfTest KEYWORD2
Get_X_DRDY_Status KEYWORD2
ReadReg KEYWORD2
WriteReg KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

LIS2DU12_OK LITERAL1
LIS2DU12_ERROR LITERAL1
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=STM32duino LIS2DU12
version=1.0.0
author=SRA
maintainer=stm32duino
sentence=Ultra Low Power 3D accelerometer.
paragraph=This library provides Arduino support for the advanced Ultra Low Power 3D accelerometer LIS2DU12 for STM32 boards.
category=Sensors
url=https://github.com/stm32duino/LIS2DU12
architectures=stm32, avr, sam
Loading

0 comments on commit 1db7a23

Please sign in to comment.