๐ข SevenSeg
January 25, 2026 ยท View on GitHub
A lightweight, easy-to-use MicroPython library to control single-digit 7-segment displays (common cathode or common anode) on boards like ESP32, ESP8266, and Raspberry Pi Pico 2 W.
๐ Features
- Supports both Common Cathode & Common Anode types
- Optional decimal point (dp) control
- Simple API:
show(),clear(),dot() - Works on multiple MicroPython boards
- Clean, modular design for beginners & embedded developers
โ๏ธ Installation
Copy the sevenseg.py file to your device using Thonny, ampy, or rshell.
Or clone this repo:
git clone https://github.com/kritishmohapatra/micropython-sevenseg.git
# Copy to the root directory of your MicroPython board
sevenseg.py โ /
๐ง Pin Diagram (Typical)
---a---
| |
f b
| |
---g---
| |
e c
| |
---d--- โ dp
๐งช Board Examples
| Board | File | Description |
|---|---|---|
| ESP32 | examples/esp32_basic_counter_example.py | Demo on ESP32 with GPIO 23โ17 |
| ESP8266 | examples/esp8266_basic_counter_example.py | Demo on NodeMCU (D1โD8 pins) |
| Raspberry Pi Pico 2 W | examples/rpi_pico_2_w_counter_example.py | Demo using GP0โGP7 |
๐งฉ Library API
| Function | Description |
|---|---|
show(num) | Display a number (0โ9) |
clear() | Turn off all segments |
dot(on=True) | Turn the decimal point on/off |
common_anode | Set True for common-anode displays |
๐ฆ Folder Structure
micropython-sevenseg/
โโโ sevenseg/
โ โโโ __init__.py
โ โโโ sevenseg.py
โโโ examples/
โ โโโ sevenseg_esp32_demo.py
โ โโโ sevenseg_esp8266_demo.py
โ โโโ sevenseg_pico2w_demo.py
โโโ setup.py
โโโ LICENSE
โโโ README.md
๐ License
This project is licensed under the MIT License.
ยฉ 2025 Kritish Mohapatra โ Open Source for MicroPython Community ๐ก
๐ What's New in v1.1.0
- Optimized segment control logic using XOR operation
- Correct decimal point (DP) behavior for common anode and cathode displays
- Cleaner and faster pin value handling
- Community-reviewed improvements
โค๏ธ Contribute
Pull requests are welcome!
If you find a bug or want to suggest an improvement, feel free to open an issue.
๐ Author
Kritish Mohapatra
๐ GitHub
๐ง kritishmohapatra06norisk@gmail.com
โจ Made with passion for Embedded Systems and MicroPython learners.