Library 28- L3GD20 3-axis digital gyroscope

MEMS sensor L3GD20 is included on STM32F429-Discovery board, so I made a library to use it. This is 3-axis digital gyroscope, so it can measure rotation in X, Y and Z axis. L3GD20 sensor works with SPI communication, or I2C. On Discovery board is connected for SPI mode, SPI5 is used for communication.

L3GD20 can be set to work in 3 different full scales: 250, 500 and 2000 dps.

Sensor has also possibility to measure temperature, but this is not included in this library.

L3GD20 Library


  • Measure 3 axis rotation
  • Enables high pass filter to stabilize output
  • Selectable 3 full scale modes


    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx SPI
  • TM
    • TM SPI
    • TM GPIO
    • defines.h

Default pinout

Default pinout for L3GD20 sensor on F429-discovery board
L3GD20 STM32F4 Description
VCC 3.3V 3.3V power
GND GND Ground
MOSI PF9 Master Out Slave In for SPI
MISO PF8 Master In Slave Out for SPI
SCK PF7 Clock for SPI
CS PC1 Chip select for SPI

This pinout is used on F429-Discovery board by default. If you want to change your pinout for other application, add these lines in defines.h file and edit them:

Functions and enumerations


Example below produces something like this:

L3GD20 3-axis digital gyroscope example

L3GD20 3-axis digital gyroscope example

View project on Github, download library below.


Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!