Labs / MicroPython module projects

Posture Sensing Interactive Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

1. Introduction

1.1 Project Background

Traditional LED display devices mostly support static or simple animation display, lacking the real-time interaction capability with users' postures. This project is based on the GraftPort-RP2040 development board, and integrates the serial gyroscope module based on JY60 and the 8×8 WS2812 matrix module to implement a "posture sensing - dynamic display" interactive system, which addresses the problem of insufficient interactivity of traditional display devices. Meanwhile, it incorporates MicroPython ' s lightweight task scheduling and interrupt handling mechanism to ensure the stable operation of the system.

1.2 Overview of Main Functions of the Project

This project is developed based on MicroPython. Its core function is to use a serial gyroscope module based on JY60 to detect the device's attitude (roll angle and pitch angle) in real time, and dynamically adjust the position of the pattern on the LED matrix according to attitude changes; it supports on-board key interrupt to switch task start/stop, has built-in automatic garbage collection (GC) to avoid memory leaks, and is equipped with exception capture and rate-limited printing for convenient problem locating.

1.3 Applicable Scenarios or Application Area

2. Main Functions

3. Hardware Requirements

3.1 Hardware Required

The project is based on the GraftPort-RP2040 development board as the main controller:

v1.0 GraftPort-RP2040 JY60 WS2812 SY7656

Other required modules include:

JY60 WS2812 SY7656

3.2 Hardware Connection

JY60-based serial port gyroscope module: connected via PH2.0 connecting cable to the UART0 interface;

WS2812 Matrix Module: Connected via PH2.0 connecting cable to DIO0 interface;

Lithium battery charge-discharge module: BAT interface connects to the lithium battery, and the OUT interface supplies power to the main control board via a PH2.0-2P connection cable.

GraftPort-RP2040 PH2.0-2P
3.1
3.3

3.3 Structural Assembly

First, use M3 plastic pillars to fix each module and the main control board to the bottom plate of the casing (M3 screw holes are pre-reserved on both the main control board and the casing):

M3 10 3.3
M3

Next, secure the periphery of the housing with M3 plastic pillars, then fasten M3 screws at the corresponding positions to complete the assembly:

M3

3.4 Notes

When the main control board is not connected to an external watchdog module, the RUN DIP switch 2 must be turned on:

2 R5 R6

The lithium battery charge-discharge module supports power level display, and you can charge it via the Type-C interface below:

Posture Sensing Interactive Device (Based on GraftPort-RP2040 Development Board)(Open Version)

4. Software Environment

5. File Structure

ws2812_imu_hourglass
├─ LICENSE
├─ tools
│  ├─ dependency_analyzer.py
│  ├─ mpy_compiler.py
│  ├─ mpy_uploader.py
│  └─ README.md
├─ firmware
│  ├─ board.py
│  ├─ boot.py
│  ├─ conf.py
│  ├─ main.py
│  ├─ tasks
│  │  ├─ imu_task.py
│  │  ├─ maintenance.py
│  │  └─ __init__.py
│  ├─ libs
│  │  ├─ __init__.py
│  │  └─ scheduler
│  └─ drivers
│     ├─ __init__.py
│     ├─ serial_imu_driver
│     └─ neopixel_matrix_driver
├─ examples
│  └─ README.md
├─ docs
   └─ docs_here

6. Description of Key Documents

7. Core Idea of Software Design

Posture Sensing Interactive Device (Based on GraftPort-RP2040 Development Board)(Open Version)
I2C I2S

8. Instructions for Use

8.1 Hardware Connection

Connect the main control board, each sensor module and the battery according to the connection method specified in the "hardware requirements";

8.2 Run the Project (Using PyCharm + MicroPython Plugin)

Open PyCharm and install the corresponding MicroPython plugin.

1.4.5-2024.1

In the plugin, select Target Device as RP2040, and enable Auto-detect device path.

Posture Sensing Interactive Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Set Project/firmware as the project root directory.

8.1

Modify Run Configuration:

Posture Sensing Interactive Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Click the IDE green triangle button in the upper right corner to run, and you can start uploading the firmware and executing the project.

8.3 8.4

8.3 Modification of Running Configuration

You can configure conf.py to modify or add parameters as needed, for example:

# conf.py example configuration
ENABLE_DEBUG = True            # Whether to enable debug printing
AUTO_START = True              # Whether to run tasks automatically at startup

8.4 Functional Testing

The terminal output is as follows:

359.81872 0.016479492 8.5

8.5 Debugging and Problem Localization

9. Sample Program

There are no other reference sample codes for this project, you can directly firmware make modifications in the folder.

10. Notes

11. Version Record

12. Contact the Developer

If you have any questions or need assistance, please contact the developer via the following channels:
📧 Email: 10696531183@qq.com
💻 GitHub: https://github.com/FreakStudioCN

13. Licensing Agreement

In this project, except for machine and other MicroPython official modules (MIT License), all driver and extension codes written by the author are released under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) Licensing Agreement.

You are free to:

Only the following conditions shall be complied with:

Copyright belongs to FreakStudio.

Appendix I: Project Source Code Download

https://github.com/FreakStudioCN/GraftPort_MicroPython_Labs/tree/main/ws2812_imu_hourglass

Appendix II: Hardware Module Reference Materials

JY60-based Serial Port Gyroscope Module

WS2812 Matrix Module

SY7656 Lithium Battery Charge-Discharge Module

GraftPort - Raspberry Pi Pico Expansion Board (Open Edition Template Files)

Version Record

Document Version

Date of Modification

Modifier

Modified Content

V1.0.0

2025-11-05

Hou Junhan

Draft the initial version of the document.

V1.1.0

2026-01-04

Li Zisheng

Final version.