Skip to content

8Altair/Gyroscope-data-streaming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gyroscope-data-streaming

This repository contains a complete example showing how to read angular‑velocity data from the L3GD20 gyroscope on an STM32F411E‑Discovery board and stream it to a PC over USB. The C firmware (HAL‑based) configures SPI to communicate with the L3GD20, periodically samples the X/Y/Z axes and the onboard temperature sensor, and sends the readings via the USB CDC class. A cross‑platform Python GUI uses PySerial to receive the data, stores it in ring buffers, and displays the last N seconds as scrolling plots using Matplotlib. A PowerShell test script (Test.ps1) is also provided to check the workflow from the command line. The following document provides more insight for usage information: https://www.st.com/resource/en/application_note/an4505-l3gd20-3axis-digital-output-gyroscope-stmicroelectronics.pdf

Features

  • Firmware

    • Written in C using STM32Cube HAL.
    • Configures SPI for the on‑board L3GD20.
    • Samples X, Y, Z angular‑rate registers and the temperature register.
    • Button press toggles data streaming over USB.
    • Raw 16‑bit values are scaled to dps (degrees per second) using a user‑configurable scale factor.
    • Data transmitted as comma‑separated ASCII (X,Y,Z\r\n) and temperature as T=XX.XC\r\n.
  • Python GUI

    • Built using Python 3.13.
    • Uses PySerial for non‑blocking serial read, NumPy for ring buffers and Matplotlib for plots.
    • Connect/disconnect to a COM port at a selectable baud rate.
    • Choose display window length in seconds and gyroscope scale (dps/LSB).
    • Separate plots for angular velocity (X, Y, Z) and temperature with labeled axes.
    • Clears buffers via GUI and shows connection status and last received line.
  • Testing Script

    • Test.ps1 is a simple PowerShell script for Windows that opens a specified COM port, listens for incoming lines, and prints them to the console. It can be used to verify that the firmware is streaming correctly without launching the full GUI.

Directory Structure

Firmware/
├─ Core/
│  ├─ Inc/
│  └─ Src/
│     └─ main.c        - Main firmware entry point (SPI, L3GD20, USB CDC logic)
├─ Drivers/            - STM32 HAL and CMSIS drivers (Cube-generated)
├─ USB_Device/         - USB CDC device configuration and descriptors
└─ *.ioc               - STM32CubeMX configuration file

GUI/
├─ main.py             - GUI entry point (window, plots, controls)
├─ reader.py           - Background serial reader and data parser
└─ buffer.py           - Fixed-size ring buffer implementation

Test.ps1               - PowerShell script for testing CDC data output
.gitignore             - Git ignore rules
README.md              - Project documentation

Requirements

Firmware

  • Hardware: STM32F411E-Discovery development board
    • On-board gyroscope: L3GD20
  • IDE / Toolchain: STM32CubeIDE
  • Libraries: STM32 HAL, USB CDC middleware (generated by STM32CubeMX)

Python GUI

  • Python: 3.8 or newer
  • Required packages:
    • pyserial
    • numpy
    • matplotlib
    • customtkinter

Install: pip install pyserial numpy matplotlib customtkinter

PowerShell Test Script

  • Operating system: Windows
  • Shell: PowerShell 5.1 or newer
  • No additional modules required

Building and Running

Firmware

  1. Open the Firmware directory in STM32CubeIDE.
  2. Build the project using Project → Build Project.
  3. Flash the firmware to the board using Run → Run.
  4. After reset, press the blue user button (PA0) to start or stop data transmission over USB CDC.

Python GUI

  1. Connect the STM32F411E-Discovery board to the PC via USB.
  2. Verify that the board enumerates as a virtual COM port.
  3. Install Python dependencies.
  4. Start the GUI by running main.py.
  5. Select the COM port and baud rate, then click Connect.
  6. Press the board button to begin live data streaming.
  7. Use the slider to select the length of the displayed signal window.

Test.ps1 Script

The Test.ps1 script provides a minimal way to test the firmware without running the GUI.

It opens a serial connection, prints received gyroscope and temperature data to the console, and allows verification of:

  • USB CDC communication
  • SPI sensor configuration
  • Correct data formatting

The script is useful for validating the firmware data path independently of the GUI.

Data Scaling and Units

Raw gyroscope values are transmitted in LSB units. To convert them into physical units (degrees per second), the GUI applies a scale factor.

For the ±500 dps full-scale range of the L3GD20, the datasheet specifies:

0.0175 dps per LSB

This value is configurable in the GUI and corresponds to the sensor sensitivity defined in the datasheet.

About

A compact project demonstrating how to stream 3‑axis angular‑rate data from an STM32F411E‑Discovery board to a PC over USB. Firmware written in C reads the L3GD20 gyroscope via SPI and transmits the raw data plus temperature via the CDC.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages