{"id":31926417,"url":"https://github.com/bobbyesp/tm1638","last_synced_at":"2025-10-14T01:43:19.890Z","repository":{"id":318325689,"uuid":"1070386538","full_name":"BobbyESP/TM1638","owner":"BobbyESP","description":"A comprehensive C library for controlling TM1638-based display modules using STM32 microcontrollers with HAL drivers.","archived":false,"fork":false,"pushed_at":"2025-10-06T13:32:43.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-06T15:26:00.566Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BobbyESP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-05T20:21:22.000Z","updated_at":"2025-10-06T13:32:46.000Z","dependencies_parsed_at":"2025-10-06T15:26:01.691Z","dependency_job_id":null,"html_url":"https://github.com/BobbyESP/TM1638","commit_stats":null,"previous_names":["bobbyesp/tm1638"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/BobbyESP/TM1638","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobbyESP%2FTM1638","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobbyESP%2FTM1638/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobbyESP%2FTM1638/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobbyESP%2FTM1638/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BobbyESP","download_url":"https://codeload.github.com/BobbyESP/TM1638/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BobbyESP%2FTM1638/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017500,"owners_count":26086085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-14T01:43:18.206Z","updated_at":"2025-10-14T01:43:19.885Z","avatar_url":"https://github.com/BobbyESP.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TM1638 Library for STM32\n\nA comprehensive C library for controlling TM1638-based display modules using STM32 microcontrollers with HAL drivers.\n\n## 📋 Overview\n\nThis library provides a complete interface for the **TM1638** LED controller chip, commonly found in affordable display modules. The TM1638 module typically features:\n\n- **8× Seven-Segment Displays** (arranged as 2 groups of 4 digits)\n- **8× Red-Color LEDs** (red)\n- **8× Push Buttons** (S1-S8)\n- **Simple 3-wire interface** (CLK, DIO, STB)\n\nThe library is designed specifically for **STM32** microcontrollers using the **HAL (Hardware Abstraction Layer)** libraries.\n\n## ✨ Features\n\n- ✅ Display text and numbers on 7-segment displays\n- ✅ Individual LED control\n- ✅ Button scanning (blocking and non-blocking)\n- ✅ Configurable brightness (8 levels: 0-7)\n- ✅ Decimal point support\n- ✅ Custom segment patterns\n- ✅ Right-aligned text display\n- ✅ Comprehensive character set (digits, letters, symbols)\n- ✅ Well-documented and easy to use\n\n## 🔧 Hardware Requirements\n\n- STM32 microcontroller (tested with NUCLEO-F401RE)\n- TM1638 display module\n- 3 GPIO pins for communication (CLK, DIO, STB)\n\n## 📦 Installation\n\n1. Copy `TM1638.h` and `TM1638.c` to your STM32 project\n2. Include the header file in your main code:\n```c\n#include \"TM1638.h\"\n```\n3. Configure 3 GPIO pins as outputs (Push-Pull mode) in STM32CubeMX or manually\n\n## 🚀 Quick Start\n\n### Basic Initialization\n\n```c\n#include \"TM1638.h\"\n\n// Create TM1638 instance\nTM1638 display;\n\n// Configure pins\ndisplay.clk_port = GPIOA;\ndisplay.clk_pin = GPIO_PIN_0;\ndisplay.dio_port = GPIOA;\ndisplay.dio_pin = GPIO_PIN_1;\ndisplay.stb_port = GPIOA;\ndisplay.stb_pin = GPIO_PIN_2;\n\n// Initialize with brightness level 5 (0-7)\ntm1638_init(\u0026display, 5);\n```\n\n### Display Text\n\n```c\n// Display a string (right-aligned)\ntm1638_display_txt(\u0026display, \"HELLO\");\n\n// Display a number\ntm1638_display_txt(\u0026display, \"12345678\");\n\n// Display with decimal point\ntm1638_display_txt(\u0026display, \"12.34\");\n```\n\n### Display Individual Characters\n\n```c\n// Display 'A' on position 1 (leftmost)\ntm1638_display_char(\u0026display, 1, 'A', false);\n\n// Display '5' with decimal point on position 4\ntm1638_display_char(\u0026display, 4, '5', true);\n```\n\n### Control LEDs\n\n```c\n// Turn on LED 1\ntm1638_set_led(\u0026display, 1, true);\n\n// Turn off LED 3\ntm1638_set_led(\u0026display, 3, false);\n\n// Turn on all LEDs\nfor (uint8_t i = 1; i \u003c= 8; i++) {\n    tm1638_set_led(\u0026display, i, true);\n}\n```\n\n### Read Buttons\n\n```c\n// Non-blocking button scan\nuint8_t buttons = tm1638_scan_buttons(\u0026display);\nif (buttons \u0026 (1 \u003c\u003c 0)) {\n    // Button S1 is pressed\n}\n\n// Blocking button read (waits for press and release)\nuint8_t key = tm1638_read_key_blocking(\u0026display);\n// Returns 1-8 for single key press\n```\n\n### Brightness Control\n\n```c\n// Set brightness (0 = dimmest, 7 = brightest)\ntm1638_set_brightness(\u0026display, 7);\n```\n\n### Clear Display\n\n```c\n// Clear all displays and turn off all LEDs\ntm1638_display_clear(\u0026display);\n```\n\n## 📚 API Reference\n\n### Initialization\n\n```c\nvoid tm1638_init(TM1638 *tm, uint8_t brightness);\n```\nInitializes the TM1638 module. Must be called before any other function.\n\n### Display Functions\n\n```c\nvoid tm1638_display_txt(TM1638 *tm, const char *str);\nvoid tm1638_display_char(TM1638 *tm, uint8_t position, char c, bool dot);\nvoid tm1638_set_segment(TM1638 *tm, uint8_t position, uint8_t data);\nvoid tm1638_display_clear(TM1638 *tm);\n```\n\n### LED Control\n\n```c\nvoid tm1638_set_led(TM1638 *tm, uint8_t position, bool on);\n```\n\n### Button Input\n\n```c\nuint8_t tm1638_scan_buttons(TM1638 *tm);\nuint8_t tm1638_read_key_blocking(TM1638 *tm);\n```\n\n### Configuration\n\n```c\nvoid tm1638_set_brightness(TM1638 *tm, uint8_t brightness);\n```\n\n## 🎨 Supported Characters\n\n### Digits\n`0 1 2 3 4 5 6 7 8 9`\n\n### Uppercase Letters\n`A B C E F H I J L O P S U`\n\n### Lowercase Letters\n`a b c d f g h i n o r t u y`\n\n### Symbols\n`space _ - .`\n\n\u003e **Note:** Unsupported characters will be displayed as blank.\n\n## 🔌 Pin Configuration Example (STM32CubeMX)\n\n1. Configure 3 GPIO pins as **GPIO_Output**\n2. Set GPIO output level to **High** (default)\n3. Set GPIO mode to **Push Pull**\n4. Set GPIO pull-up/pull-down to **No pull-up and no pull-down**\n5. Set GPIO speed to **Low** or **Medium**\n\n## 📖 Example Projects\n\n### Simple Counter\n\n```c\nint main(void) {\n    HAL_Init();\n    SystemClock_Config();\n    \n    TM1638 display;\n    display.clk_port = GPIOA;\n    display.clk_pin = GPIO_PIN_0;\n    display.dio_port = GPIOA;\n    display.dio_pin = GPIO_PIN_1;\n    display.stb_port = GPIOA;\n    display.stb_pin = GPIO_PIN_2;\n    \n    tm1638_init(\u0026display, 5);\n    \n    uint32_t counter = 0;\n    char buffer[16];\n    \n    while (1) {\n        sprintf(buffer, \"%lu\", counter);\n        tm1638_display_txt(\u0026display, buffer);\n        counter++;\n        HAL_Delay(1000);\n    }\n}\n```\n\n### Button-Controlled LED\n\n```c\nwhile (1) {\n    uint8_t buttons = tm1638_scan_buttons(\u0026display);\n    \n    for (uint8_t i = 0; i \u003c 8; i++) {\n        if (buttons \u0026 (1 \u003c\u003c i)) {\n            tm1638_set_led(\u0026display, i + 1, true);\n        } else {\n            tm1638_set_led(\u0026display, i + 1, false);\n        }\n    }\n    \n    HAL_Delay(50);\n}\n```\n\n## 🐛 Troubleshooting\n\n### Display shows nothing\n- Check that GPIO pins are correctly configured as outputs\n- Verify power supply to the TM1638 module (usually 5V)\n- Ensure proper connections between MCU and module\n- Try increasing brightness: `tm1638_set_brightness(\u0026display, 7);`\n\n### Buttons not responding\n- Check that DIO pin can be reconfigured as input\n- Verify button connections on the module\n- Try adding a small delay in the button scanning loop\n\n### Garbled display\n- Ensure proper grounding between MCU and module\n- Check for loose connections\n- Reduce clock speed if communication is unreliable\n\n## 📄 License\n\nThis project is open source. Feel free to use, modify, and distribute as needed.\n\n## 👤 Author\n\n**BobbyESP**\n\n## 🤝 Contributing\n\nContributions, issues, and feature requests are welcome!\n\n## 📝 Version History\n\n- **v1.1** (2025-10-05) - Current version with full feature set\n- Complete button scanning implementation\n- Comprehensive character support\n- Improved documentation\n\n## 🔗 References\n\n- [TM1638 Datasheet](https://futuranet.it/futurashop/image/catalog/data/Download/TM1638_V1.3_EN.pdf)\n- STM32 HAL Documentation\n\n\u003e This library is a rewritten and improved version of the one originally provided to me during my time at university. For privacy and licensing reasons, I will not be sharing the original file.\n\n---\n\n⭐ If you find this library useful, please consider giving it a star!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbyesp%2Ftm1638","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobbyesp%2Ftm1638","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbyesp%2Ftm1638/lists"}