Skip to content

Ilushenko/lsm303stm32

Repository files navigation

Simple LSM303DLHC Library for STM32

Library for using LSM303DLHC (GY-511) sensor by STM32
Tested on LSM303DLHC connected via I2C3 to ESP32 Nucleo L432KC

Features:

  • Configure linear accelerometer and magnetic field sensors
  • Read data from linear accelerometer and magnetic field sensors (raw data and convertion to sensor units)
  • Configure interrupts
  • Motion detection by linear accelerometer
  • Detection of magnetic field distortion
  • Orientation: pitch, roll and yaw
  • Compute incline angle

Stand With Ukraine

Pinout

I2C1

LSM303DLHC STM32L432KC
3V3 3V3
GND GND
SCL D5 (PB6)
SDA D4 (PB7)
INT1 D9 (PA8) for using IRQ
INT2 D10 (PA11) for using IRQ

I2C3

LSM303DLHC STM32L432KC
3V3 3V3
GND GND
SCL A6 (PA7)
SDA D12 (PB4)
INT1 D9 (PA8) for using IRQ
INT2 D10 (PA11) for using IRQ

Scheme

Using STM32CubeMX Project in Visual Studio Code

  1. Configure the project in STM32CubeMX and generate the source code.
  2. Then create a project in Visual Studio Code + PlatformIO extension:
    • Board: ST Nucleo L324 KC
    • Framework: STM32Cube
  3. In platformio.ini add:
[platformio]
src_dir = Core/
include_dir = Core/Inc
  1. For using on-chip floating point unit. The stm32flags.py file contains additional framework build flags. Include it in Your platformio.ini and add build flags:
extra_scripts = pre:stm32flags.py
build_flags =
    -Wall
    -mfpu=fpv4-sp-d16 -mfloat-abi=hard
    -Wl,-u,_printf_float
  1. For using code of this library add to platformio.ini
lib_deps = lsm303

Examples

Directory example/ cantain subdirectories: direction, interrupt, orientation Copy main.c from this subdirectories to Your Core folder instead of the existing main.c

Releases

No releases published

Packages

 
 
 

Contributors