Labs / MicroPython module projects

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

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

Contents
Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)
Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Project Description

1. Introduction

1.1 Project Background

Traditional light detection devices usually have a single function and lack intuitive visual display of light intensity. This project is based on the GraftPort-RP2040 development board, and combines the light intensity sensor module based on the BH1750 chip and the 8-segment light bar digital tube module based on the PCF8574 chip to realize an integrated system of "light intensity detection and visual display", which intuitively presents the current light intensity through an LED bar graph. Meanwhile, it integrates the lightweight task scheduling and exception handling mechanism of MicroPython to ensure the stable operation of the system.

1.2 Overview of Main Functions of the Project

This project is based on MicroPython development, the core function is through the light intensity sensor module based on the BH1750 chip real-time detection of ambient light intensity (unit: lux ), based on the PCF8574 chip eight-segment light bar digital tube module in the form of a bar graph visual display of light intensity level; support onboard key interrupt switching task start and stop, built-in automatic garbage collection ( GC ) to avoid memory leaks, abnormal capture and speed limit printing for problem location.

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:

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

The other required modules include:

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

3.2 Hardware Connections

Light intensity sensor module based on BH1750 chip: connected via PH2.0 connecting cable to I2C0 interface;

8-segment bar LED digital tube module: connected via PH2.0 connecting cable to I2C1 interface

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Lithium Battery Charge and 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.

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)
Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)
Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

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):

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)
Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Next, secure the housing around its perimeter using M3 plastic pillars, then fasten M3 screws into the corresponding positions to complete the assembly.:

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

3.4 Notes

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

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

The lithium battery charge-discharge module supports power level display and can be charged via the Type-C port below:

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

4. Software Environment

5. File Structure

light_intensity_display
├─ .flake8
├─ LICENSE
├─ README.md
├─ tools
│  ├─ dependency_analyzer.py
│  ├─ mpy_compiler.py
│  ├─ mpy_uploader.py
│  └─ README.md
├─ firmware
│  ├─ board.py
│  ├─ boot.py
│  ├─ conf.py
│  ├─ main.py
│  ├─ tasks
│  │  ├─ maintenance.py
│  │  ├─ sensor_task.py
│  │  └─ __init__.py
│  ├─ libs
│  │  ├─ __init__.py
│  │  └─ scheduler
│  └─ drivers
│     ├─ __init__.py
│     ├─ pcf8574_led_driver
│     └─ BH1750_driver
└─ examples
   └─ README.md

6. Description of Key Documents

7. Core Idea of Software Design

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

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.

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

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

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Set Project/firmware as the project root directory.

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

Modify the runtime configuration:

Light Intensity Parameter Visual Monitoring 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.

Light Intensity Parameter Visual Monitoring Device (Based on GraftPort-RP2040 Development Board)(Open Version)

8.3 Modification of Running Configuration

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

# conf.py example configuration
I2C_INIT_MAX_ATTEMPTS = 3      # Maximum number of sensor initialization retries
I2C_INIT_RETRY_DELAY_S = 0.5   # Interval between retries (seconds)
ENABLE_DEBUG = True            # Whether to enable debug printing
AUTO_START = True              # Whether to run tasks automatically at startup

8.4. Functional Testing

8.5 Debugging and Troubleshooting

9. Sample Program

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

10. Precautions

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 (under the 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 © FreakStudio. All rights reserved.

Appendix 1: Project Source Code Download

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

Appendix II: Hardware Module Reference Materials

GraftSense - A Light Intensity Sensor Module Based on the BH1750 Chip

GraftSense - An 8-segment bar digital tube module based on the PCF8574 chip

GraftSense-SY7656 Lithium Battery Charge-Discharge Module

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

Version Record

Document Version

Date of Revision

Modifier

Modify Content

V1.0.0

2025-11-03

Junhan Hou

Draft the document.

V1.1.0

2026-01-04

Li Zisheng

Final version.