This repository contains a C library for interfacing with the TM1637 4-digit 7-segment display using the Raspberry Pi Pico. The library provides functions to initialize the display, set brightness, display digits or numbers, and clear the display.
- Features
- Hardware Requirements
- Getting Started
- Usage
- Library API
- Example Code
- License
- Acknowledgments
- Easy-to-use API for the TM1637 display
- Supports setting display brightness
- Display individual digits or full numbers (0-9999)
- Clear the display
- Compatible with the Raspberry Pi Pico SDK
- Raspberry Pi Pico
- TM1637 4-digit 7-segment display module
- Connecting wires
- (Optional) Pull-up resistors (if not included on the TM1637 module)
- Raspberry Pi Pico SDK installed and properly set up
- CMake version 3.13 or higher
- GCC compiler for ARM (e.g.,
arm-none-eabi-gcc) - Build tools (
make)
Clone this repository to your local machine:
git clone https://github.com/yourusername/tm1637-pico-library.gitReplace yourusername with your GitHub username or the appropriate URL.
Connect the TM1637 module to the Raspberry Pi Pico as follows:
| TM1637 Pin | Raspberry Pi Pico Pin |
|---|---|
| VCC | 3.3V (Pin 36) |
| GND | GND (Pin 38) |
| DIO | GPIO 3 (Pin 5) |
| CLK | GPIO 2 (Pin 4) |
Note: You can change the GPIO pins used by modifying the tm1637.h file or by specifying different pins when initializing the library.
-
Copy the Library Files:
Copy
tm1637.handtm1637.cinto your project directory. -
Include the Header in Your Code:
In your
main.cor any other source file where you want to use the library, include the header file:#include "tm1637.h"
Your CMakeLists.txt file should include the tm1637.c source file and link against the necessary libraries.
cmake_minimum_required(VERSION 3.13)
# Include the Pico SDK
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
project(tm1637_project)
# Initialize the Pico SDK
pico_sdk_init()
# Add executable and include source files
add_executable(tm1637_project
main.c # Your main application file
tm1637.c # The tm1637 library source file
)
# Link against Pico libraries
target_link_libraries(tm1637_project
pico_stdlib
hardware_gpio
)
# Enable USB output (optional)
pico_enable_stdio_usb(tm1637_project 1)
pico_enable_stdio_uart(tm1637_project 0)
# Create map/bin/hex/uf2 files
pico_add_extra_outputs(tm1637_project)-
Create a build directory:
mkdir build cd build -
Run CMake configuration:
cmake ..
-
Build the project:
make
-
The UF2 file will be generated in the build directory. Copy it to the Raspberry Pi Pico's storage to flash the firmware.
Initializes the TM1637 display with the specified GPIO pins.
gpio_clk: GPIO pin connected to the CLK pin of TM1637.gpio_dio: GPIO pin connected to the DIO pin of TM1637.
Sets the brightness of the display.
brightness: Brightness level (0 to 7).
Displays a single digit at the specified position.
position: Position on the display (0 to 3).digit: Digit to display (0 to 9).
Displays a number on the display.
number: Number to display (0 to 9999).
Clears the display by turning off all segments.
Here's an example of how to use the library in your main.c:
#include "pico/stdlib.h"
#include "tm1637.h"
int main() {
stdio_init_all();
// Initialize the TM1637 display
tm1637_init(2, 3); // Use GPIO 2 for CLK and GPIO 3 for DIO
// Set display brightness (0 to 7)
tm1637_set_brightness(4);
// Display a number
tm1637_display_number(1234);
// Main loop
while (true) {
// Increment and display numbers
for (int i = 0; i <= 9999; i++) {
tm1637_display_number(i);
sleep_ms(500);
}
// Clear the display
tm1637_clear_display();
sleep_ms(1000);
}
return 0;
}This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by various TM1637 libraries and tutorials.
- Special thanks to the Raspberry Pi Foundation for the Pico SDK.
