{"id":13613301,"url":"https://github.com/mcauser/micropython-tm1638","last_synced_at":"2025-07-28T05:32:47.859Z","repository":{"id":53934625,"uuid":"125058490","full_name":"mcauser/micropython-tm1638","owner":"mcauser","description":"MicroPython driver for TM1638 dual quad 7-segment LED modules with switches","archived":false,"fork":false,"pushed_at":"2023-06-15T04:33:50.000Z","size":5706,"stargazers_count":29,"open_issues_count":4,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-04T15:50:40.000Z","etag":null,"topics":["7-segment","esp8266","leds","micropython","tm1638","wemos-d1-mini"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcauser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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}},"created_at":"2018-03-13T13:47:03.000Z","updated_at":"2025-02-18T08:31:11.000Z","dependencies_parsed_at":"2024-11-07T21:33:49.718Z","dependency_job_id":"38ac07fb-3c74-4c58-ade1-1b284c07df3b","html_url":"https://github.com/mcauser/micropython-tm1638","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mcauser/micropython-tm1638","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-tm1638","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-tm1638/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-tm1638/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-tm1638/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcauser","download_url":"https://codeload.github.com/mcauser/micropython-tm1638/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-tm1638/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267468379,"owners_count":24092332,"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-07-28T02:00:09.689Z","response_time":68,"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":["7-segment","esp8266","leds","micropython","tm1638","wemos-d1-mini"],"created_at":"2024-08-01T20:00:43.664Z","updated_at":"2025-07-28T05:32:46.985Z","avatar_url":"https://github.com/mcauser.png","language":"Python","readme":"# MicroPython TM1638 LED Driver\n\nA MicroPython library for LED\u0026KEY modules with 8x 7-segment decimal LED modules, 8x individual LEDs and 8x switches using the TM1738 LED driver.\n\n![demo](docs/demo.jpg)\n\n## Examples\n\nCopy the file to your device, using [ampy](https://github.com/adafruit/ampy), [rshell](https://github.com/dhylands/rshell), [webrepl](http://micropython.org/webrepl/) or compiling and deploying. eg.\n\n```bash\n$ ampy put tm1638.py\n```\n\n**Basic usage**\n\n```python\n# TinyPICO / ESP32\nimport tm1638\nfrom machine import Pin\ntm = tm1638.TM1638(stb=Pin(5), clk=Pin(18), dio=Pin(23))\n\n# Wemos D1 Mini / ESP8266\nimport tm1638\nfrom machine import Pin\ntm = tm1638.TM1638(stb=Pin(13), clk=Pin(14), dio=Pin(12))\n\n# STM32F407VET6\nimport tm1638\nfrom machine import Pin\ntm = tm1638.TM1638(stb=Pin('B4'), clk=Pin('B5'), dio=Pin('B6'))\n\n# every 2nd LED on\ntm.leds(0b01010101)\n\n# all LEDs off\ntm.leds(0)\n\n# segments\ntm.show('cool')\ntm.show('abcdefgh')\ntm.number(-1234567)\ntm.number(1234)\ntm.number(5678, 4)\ntm.hex(0xdeadbeef)\n\n# dim both LEDs and segments\ntm.brightness(0)\n\n# all LEDs and segments off\ntm.clear()\n\n# get which buttons are pressed on LED\u0026KEY module\ntm.keys()\n\n# get which buttons are pressed on QYF-TM1638 module\ntm.qyf_keys()\n```\n\nFor more detailed examples, see [examples](/examples).\n\n# Seven Segment Font\n\nThey are called 7-segment displays as there are 7 LEDs for each digit (segment).\nOne byte (7 lower bits) for each segment. The 8th bit (MSB) is for the decimal point on each segment.\n\n```\n      A\n     ---\n  F |   | B\n     -G-\n  E |   | C\n     ---  * H\n      D\n\n  HGFEDCBA\n0b01101101 = 0x6D = 109 = show \"5\"\n```\n\nDisplay | Bin        | Hex  | Dec\n------- | ---------- | ---- | ---\n0       | 0b00111111 | 0x3F | 63\n1       | 0b00000110 | 0x06 | 6\n2       | 0b01011011 | 0x5B | 91\n3       | 0b01001111 | 0x4F | 79\n4       | 0b01100110 | 0x66 | 102\n5       | 0b01101101 | 0x6D | 109\n6       | 0b01111101 | 0x7D | 125\n7       | 0b00000111 | 0x07 | 7\n8       | 0b01111111 | 0x7F | 127\n9       | 0b01101111 | 0x6F | 111\nA       | 0b01110111 | 0x77 | 119\nb       | 0b01111100 | 0x7C | 124\nC       | 0b00111001 | 0x39 | 57\nd       | 0b01011110 | 0x5E | 94\nE       | 0b01111001 | 0x79 | 121\nF       | 0b01110001 | 0x71 | 113\nG       | 0b00111101 | 0x3D | 61\nH       | 0b01110110 | 0x76 | 118\nI       | 0b00000110 | 0x06 | 6\nJ       | 0b00011110 | 0x1E | 30\nK       | 0b01110110 | 0x76 | 118\nL       | 0b00111000 | 0x38 | 56\nM       | 0b01010101 | 0x55 | 85\nn       | 0b01010100 | 0x54 | 84\nO       | 0b00111111 | 0x3F | 63\nP       | 0b01110011 | 0x73 | 115\nq       | 0b01100111 | 0x67 | 103\nr       | 0b01010000 | 0x50 | 80\nS       | 0b01101101 | 0x6D | 109\nt       | 0b01111000 | 0x78 | 120\nU       | 0b00111110 | 0x3E | 62\nv       | 0b00011100 | 0x1C | 28\nW       | 0b00101010 | 0x2A | 42\nX       | 0b01110110 | 0x76 | 118\ny       | 0b01101110 | 0x6E | 110\nZ       | 0b01011011 | 0x5B | 91\nblank   | 0b00000000 | 0x00 | 0\n\\-      | 0b01000000 | 0x40 | 64\n\\*      | 0b01100011 | 0x63 | 99\n\n# Methods\n\nPower up, power down or check status.\n```\npower(val=None)\n```\n\nGet or set brightness.\n```\nbrightness(val=None)\n```\n\nWrite zeros to each address.\n```\nclear()\n```\n\nWrite to all 16 addresses from a given position.\nOrder is left to right, 1st segment, 1st LED, 2nd segment, 2nd LED etc.\n```\nwrite(data, pos=0)\n```\n\nSet the value of a single LED.\n```\nled(pos, val)\n```\n\nSet all LEDs at once. LSB is left most LED.\nOnly writes to the LED positions (every 2nd starting from 1).\n```\nleds(val)\n```\n\nSet one or more segments at a relative position.\nOnly writes to the segment positions (every 2nd starting from 0).\n```\nsegments(segments, pos=0)\n```\n\nReturn a byte representing which keys are pressed. LSB is SW1.\n```\nkeys()\n```\n\nReturn a 16-bit value representing which keys are pressed. LSB is SW1.\n```\nqyf_keys()\n```\n\nConvert a single hex digit (0x00-0x0f) to a segment.\n```\nencode_digit(digit)\n```\n\nConvert a string to a list of segments. Dots are merged with the previous character.\n```\nencode_string(string)\n```\n\nConvert a single character to a segment.\n```\nencode_char(char)\n```\n\nDisplay a number in hexadecimal format 00000000 through FFFFFFFF, right aligned, leading zeros.\n```\nhex(val)\n```\n\nDisplay a numeric value -9999999 through 99999999, right aligned.\n```\nnumber(num)\n```\n\nDisplay a temperature -9 through 99 followed by degrees C.\n```\ntemperature(num, pos=0)\n```\n\nDisplays a relative humidity -9 through 99 followed by RH.\n```\nhumidity(num, pos=4)\n```\n\nDisplays as much of a string as will fit.\n```\nshow(string, pos=0)\n```\n\nDisplay a string, scrolling from the right to left, speed adjustable.\nString starts off-screen right and scrolls until off-screen left at 4 FPS by default.\n```\nscroll(string, delay=250)\n```\n\n## Parts\n\n* [WeMos D1 Mini](https://www.aliexpress.com/store/product/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/1331105_32529101036.html) $6.36 AUD\n* [LED\u0026KEY TM1638 Module](https://www.aliexpress.com/item/TM1638-Module-Key-Display-For-AVR-Arduino-New-8-Bit-Digital-LED-Tube-8-Bit-TM1638/32805933184.html) $2.30 AUD\n* [Female-Female Dupont wires](https://www.aliexpress.com/item/10pcs-10cm-2-54mm-1p-1p-Pin-Male-to-Male-Color-Breadboard-Cable-Jump-Wire-Jumper/32636873838.html) $0.62 AUD\n\n## Connections\n\nWeMos D1 Mini | LED\u0026KEY TM1638 Module\n------------- | -----------------\n3V3 (or 5V)   | VCC\nG             | GND\nD7 (GPIO13)   | STB\nD5 (GPIO14)   | CLK\nD6 (GPIO12)   | DIO\n\nSTM32F407VET6 | LED\u0026KEY TM1638 Module\n------------- | -----------------\n3V3           | VCC\nG             | GND\nB4            | STB\nB5            | CLK\nB6            | DIO\n\n## Links\n\n* [WeMos D1 Mini](https://wiki.wemos.cc/products:d1:d1_mini)\n* [micropython.org](http://micropython.org)\n* [TM1638 datasheet](http://titanmec.com/index.php/en/project/download/id/303.html)\n* [Titan Micro TM1638 product page](http://titanmec.com/index.php/en/project/view/id/303.html)\n* [Adafruit Ampy](https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy)\n\n## License\n\nLicensed under the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Libraries","Python","精选驱动库"],"sub_categories":["Display","显示类"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-tm1638","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcauser%2Fmicropython-tm1638","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-tm1638/lists"}