{"id":187702,"date":"2026-03-11T15:10:45","date_gmt":"2026-03-11T15:10:45","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=187702"},"modified":"2026-03-11T17:02:49","modified_gmt":"2026-03-11T17:02:49","slug":"raspberry-pi-pico-tm1637-micropython","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-tm1637-micropython\/","title":{"rendered":"Raspberry Pi Pico: TM1637 4-Digit 7-Segment Display (MicroPython)"},"content":{"rendered":"\n<p>Learn how to use the TM1637 4-Digit 7-Segment Display with the Raspberry Pi Pico programmed with MicroPython. We provide instructions on how to wire the display to the board, install the required library, and we&#8217;ll explain the basic commands to control the display.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/Raspberry-Pi-Pico-TM1637-Micropython-Tutorial.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico TM1637 4-Digit 7-Segment Display MicroPython\" class=\"wp-image-187828\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/Raspberry-Pi-Pico-TM1637-Micropython-Tutorial.jpg?w=1920&amp;quality=100&amp;strip=all&amp;ssl=1 1920w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/Raspberry-Pi-Pico-TM1637-Micropython-Tutorial.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/Raspberry-Pi-Pico-TM1637-Micropython-Tutorial.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/Raspberry-Pi-Pico-TM1637-Micropython-Tutorial.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/Raspberry-Pi-Pico-TM1637-Micropython-Tutorial.jpg?resize=1536%2C864&amp;quality=100&amp;strip=all&amp;ssl=1 1536w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p class=\"rntbox rntclgreen\"><strong>New to the Raspberry Pi Pico? <\/strong><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-micropython-ebook\/\" title=\"\">Check out our eBook: Learn Raspberry Pi Pico\/Pico W with MicroPython<\/a>.<\/p>\n\n\n\n<p><strong>Table of Contents<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#intro-TM1637\" title=\"\">Introducing the TM1637 4-Digit LED 7-Segment Display<\/a><\/li>\n\n\n\n<li><a href=\"#TM1637-wiring\" title=\"\">Wiring the TM1637 4-Digit 7-Segment Display to the RPi Pico<\/a><\/li>\n\n\n\n<li><a href=\"#tm1637-micropython-library\" title=\"\">TM1637 MicroPython Library<\/a><\/li>\n\n\n\n<li><a href=\"#basic-functions\" title=\"\">Testing the TM1637 Display (Basic Functions)<\/a><\/li>\n\n\n\n<li><a href=\"#tm1637-display-temperature\" title=\"\">TM1637 7-Segment Display with RPi Pico &#8211; Display Internal Temperature Sensor<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites \u2013 MicroPython Firmware<\/h2>\n\n\n\n<p>To follow this tutorial, you need MicroPython firmware installed on your Raspberry Pi Pico board. You also need an IDE to write and upload the code to your board.<\/p>\n\n\n\n<p>The recommended MicroPython IDE for the Raspberry Pi Pico is Thonny IDE. Follow the next tutorial to learn how to install Thonny IDE, flash MicroPython firmware, and upload code to the board.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-raspberry-pi-pico-w\/#install-thonny-ide\">Programming Raspberry Pi Pico using MicroPython<\/a><\/li>\n<\/ul>\n\n\n\n<p>If you&#8217;re still getting started with the Raspberry Pi Pico, follow one of these getting-started guides:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-raspberry-pi-pico-2-w\/\">Getting Started with Raspberry Pi Pico 2 and Pico 2 W<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-raspberry-pi-pico-w\/\">Getting Started with Raspberry Pi Pico (and Pico W)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"intro-TM1637\">Introducing the TM1637 4-Digit LED 7-Segment Display<\/h2>\n\n\n\n<p>The TM1637 4-Digit LED 7-Segment display is a display module that combines four 7-segment digits on a single display that can be controlled via the TM1637 driver. The particular module we&#8217;re using here has four digits separated by a colon between the second and third digits.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/TM1637-Display.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"TM1637 4-Digit 7-Segment Display\" class=\"wp-image-187306\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/TM1637-Display.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/TM1637-Display.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>There are similar modules with dots between the digits.<\/p>\n\n\n\n<p>There are also similar modules with six 7-segment digits. These require a different library from the one we&#8217;ll use in this tutorial.<\/p>\n\n\n\n<p><strong>Note:<\/strong> I tried to use my six 7-segment display module, but it seems that there are many of those displays that come faulty by default. I couldn&#8217;t make mine work. So, this tutorial will be <em><span style=\"text-decoration: underline;\">only<\/span><\/em> about the one with four digits with a colon in the middle.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Where to Buy?<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-with-TM1637-Display.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RPi Pico Connected to TM1637 Display\" class=\"wp-image-187824\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-with-TM1637-Display.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-with-TM1637-Display.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>You can check our Maker Advisor Tools page to compare the TM1637 4-Digit 7-Segment Display module price in different stores:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/tm1637-4-digit-7-segment-display\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>TM1637 4-Digit 7-Segment Display<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/raspberry-pi-pico-2-w\/\" target=\"_blank\" rel=\"noreferrer noopener\">Raspberry Pi Pico<\/a>&nbsp;(any model)<\/li>\n\n\n\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noreferrer noopener\">Jumper wires<\/a><\/li>\n<\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"TM1637-wiring\">Wiring the TM1637 4-Digit 7-Segment Display to the RPi Pico<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/TM1637-Display-pins.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"TM1637 Display Module Pins\" class=\"wp-image-187430\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/TM1637-Display-pins.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/TM1637-Display-pins.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>Wiring the display to the RPi Pico is quite simple, as it only requires two digital pins: <strong>CLK <\/strong>and <strong>DI\/O<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>TM1637 Display<\/strong><\/td><td><strong>RPi Pico<\/strong><\/td><\/tr><tr><td>CLK<\/td><td>Any digital pin (for example: <span class=\"rnthl rntclblue\">GPIO 21<\/span>)*<\/td><\/tr><tr><td>DIO<\/td><td>Any digital pin (for example: <span class=\"rnthl rntclgreen\">GPIO 20<\/span>)*<\/td><\/tr><tr><td>VCC<\/td><td><span class=\"rnthl rntcred\">VIN<\/span><\/td><\/tr><tr><td>GND<\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>* you can use any other suitable GPIOs. Check the RPi Pico Pinout Guide:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-pinout-gpios\/\" title=\"\">Raspberry Pi Pico and Pico W Pinout Guide: GPIOs Explained<\/a><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"564\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637_bb.png?resize=879%2C564&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"RPi Pico Wiring to TM1637 Display\" class=\"wp-image-187837\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637_bb.png?w=879&amp;quality=100&amp;strip=all&amp;ssl=1 879w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637_bb.png?resize=300%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637_bb.png?resize=768%2C493&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 879px) 100vw, 879px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"tm1637-micropython-library\">TM1637 MicroPython Library<\/h2>\n\n\n\n<p>To make it easy to interface with the TM1637 Display, we&#8217;ll use a forked version of this <a href=\"https:\/\/github.com\/mcauser\/micropython-tm1637\" target=\"_blank\" rel=\"noopener\" title=\"\">TM1637 MicroPython module<\/a>.<\/p>\n\n\n\n<p>Follow the next steps to install it.<\/p>\n\n\n\n<p><strong>1. <\/strong><a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/refs\/heads\/master\/Projects\/Raspberry-Pi-Pico\/MicroPython\/tm1637\/tm1637.py\" target=\"_blank\" rel=\"noopener\" title=\"\">Click here to download our forked version of the <em>tm1637.py<\/em> file<\/a>.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-python\">&quot;&quot;&quot;\nMicroPython TM1637 quad 7-segment LED display driver\nhttps:\/\/github.com\/mcauser\/micropython-tm1637\n\nMIT License\nCopyright (c) 2016-2023 Mike Causer\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the &quot;Software&quot;), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and\/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n&quot;&quot;&quot;\n\n__version__ = '1.3.0'\n\nfrom micropython import const\nfrom machine import Pin\nfrom time import sleep_us, sleep_ms\n\nTM1637_CMD1 = const(64)  # 0x40 data command\nTM1637_CMD2 = const(192) # 0xC0 address command\nTM1637_CMD3 = const(128) # 0x80 display control command\nTM1637_DSP_ON = const(8) # 0x08 display on\nTM1637_DELAY = const(10) # 10us delay between clk\/dio pulses\nTM1637_MSB = const(128)  # msb is the decimal point or the colon depending on your display\n\n# 0-9, a-z, blank, dash, star\n_SEGMENTS = bytearray(b'\\x3F\\x06\\x5B\\x4F\\x66\\x6D\\x7D\\x07\\x7F\\x6F\\x77\\x7C\\x39\\x5E\\x79\\x71\\x3D\\x76\\x06\\x1E\\x76\\x38\\x55\\x54\\x3F\\x73\\x67\\x50\\x6D\\x78\\x3E\\x1C\\x2A\\x76\\x6E\\x5B\\x00\\x40\\x63')\n\nclass TM1637(object):\n    &quot;&quot;&quot;Library for quad 7-segment LED modules based on the TM1637 LED driver.&quot;&quot;&quot;\n    def __init__(self, clk, dio, brightness=7):\n        self.clk = clk\n        self.dio = dio\n\n        if not 0 &lt;= brightness &lt;= 7:\n            raise ValueError(&quot;Brightness out of range&quot;)\n        self._brightness = brightness\n\n        self.clk.init(Pin.OUT, value=0)\n        self.dio.init(Pin.OUT, value=0)\n        sleep_us(TM1637_DELAY)\n\n        self._write_data_cmd()\n        self._write_dsp_ctrl()\n\n    def _start(self):\n        self.dio(0)\n        sleep_us(TM1637_DELAY)\n        self.clk(0)\n        sleep_us(TM1637_DELAY)\n\n    def _stop(self):\n        self.dio(0)\n        sleep_us(TM1637_DELAY)\n        self.clk(1)\n        sleep_us(TM1637_DELAY)\n        self.dio(1)\n\n    def _write_data_cmd(self):\n        # automatic address increment, normal mode\n        self._start()\n        self._write_byte(TM1637_CMD1)\n        self._stop()\n\n    def _write_dsp_ctrl(self):\n        # display on, set brightness\n        self._start()\n        self._write_byte(TM1637_CMD3 | TM1637_DSP_ON | self._brightness)\n        self._stop()\n\n    def _write_byte(self, b):\n        for i in range(8):\n            self.dio((b &gt;&gt; i) &amp; 1)\n            sleep_us(TM1637_DELAY)\n            self.clk(1)\n            sleep_us(TM1637_DELAY)\n            self.clk(0)\n            sleep_us(TM1637_DELAY)\n        self.clk(0)\n        sleep_us(TM1637_DELAY)\n        self.clk(1)\n        sleep_us(TM1637_DELAY)\n        self.clk(0)\n        sleep_us(TM1637_DELAY)\n\n    def brightness(self, val=None):\n        &quot;&quot;&quot;Set the display brightness 0-7.&quot;&quot;&quot;\n        # brightness 0 = 1\/16th pulse width\n        # brightness 7 = 14\/16th pulse width\n        if val is None:\n            return self._brightness\n        if not 0 &lt;= val &lt;= 7:\n            raise ValueError(&quot;Brightness out of range&quot;)\n\n        self._brightness = val\n        self._write_data_cmd()\n        self._write_dsp_ctrl()\n\n    def write(self, segments, pos=0):\n        &quot;&quot;&quot;Display up to 6 segments moving right from a given position.\n        The MSB in the 2nd segment controls the colon between the 2nd\n        and 3rd segments.&quot;&quot;&quot;\n        if not 0 &lt;= pos &lt;= 5:\n            raise ValueError(&quot;Position out of range&quot;)\n        self._write_data_cmd()\n        self._start()\n\n        self._write_byte(TM1637_CMD2 | pos)\n        for seg in segments:\n            self._write_byte(seg)\n        self._stop()\n        self._write_dsp_ctrl()\n\n    def encode_digit(self, digit):\n        &quot;&quot;&quot;Convert a character 0-9, a-f to a segment.&quot;&quot;&quot;\n        return _SEGMENTS[digit &amp; 0x0f]\n\n    def encode_string(self, string):\n        &quot;&quot;&quot;Convert an up to 4 character length string containing 0-9, a-z,\n        space, dash, star to an array of segments, matching the length of the\n        source string.&quot;&quot;&quot;\n        segments = bytearray(len(string))\n        for i in range(len(string)):\n            segments[i] = self.encode_char(string[i])\n        return segments\n\n    def encode_char(self, char):\n        &quot;&quot;&quot;Convert a character 0-9, a-z, space, dash or star to a segment.&quot;&quot;&quot;\n        o = ord(char)\n        if o == 32:\n            return _SEGMENTS[36] # space\n        if o == 42:\n            return _SEGMENTS[38] # star\/degrees\n        if o == 45:\n            return _SEGMENTS[37] # dash\n        if o &gt;= 65 and o &lt;= 90:\n            return _SEGMENTS[o-55] # uppercase A-Z\n        if o &gt;= 97 and o &lt;= 122:\n            return _SEGMENTS[o-87] # lowercase a-z\n        if o &gt;= 48 and o &lt;= 57:\n            return _SEGMENTS[o-48] # 0-9\n        raise ValueError(&quot;Character out of range: {:d} '{:s}'&quot;.format(o, chr(o)))\n\n    def hex(self, val):\n        &quot;&quot;&quot;Display a hex value 0x0000 through 0xffff, right aligned.&quot;&quot;&quot;\n        string = '{:04x}'.format(val &amp; 0xffff)\n        self.write(self.encode_string(string))\n\n    def number(self, num):\n        &quot;&quot;&quot;Display a numeric value -999 through 9999, right aligned.&quot;&quot;&quot;\n        # limit to range -999 to 9999\n        num = max(-999, min(num, 9999))\n        string = '{0: &gt;4d}'.format(num)\n        self.write(self.encode_string(string))\n\n    def numbers(self, num1, num2, colon=True):\n        &quot;&quot;&quot;Display two numeric values -9 through 99, with leading zeros\n        and separated by a colon.&quot;&quot;&quot;\n        num1 = max(-9, min(num1, 99))\n        num2 = max(-9, min(num2, 99))\n        segments = self.encode_string('{0:0&gt;2d}{1:0&gt;2d}'.format(num1, num2))\n        if colon:\n            segments[1] |= 0x80 # colon on\n        self.write(segments)\n\n    def temperature(self, num):\n        if num &lt; -9:\n            self.show('lo') # low\n        elif num &gt; 99:\n            self.show('hi') # high\n        else:\n            string = '{0: &gt;2d}'.format(num)\n            self.write(self.encode_string(string))\n        self.write([_SEGMENTS[38], _SEGMENTS[12]], 2) # degrees C\n        \n    def temperature_f(self, num):\n        if num &lt; -9:\n            self.show('lo') # low\n        elif num &gt; 99:\n            self.show('hi') # high\n        else:\n            string = '{0: &gt;2d}'.format(num)\n            self.write(self.encode_string(string))\n        self.write([_SEGMENTS[38], _SEGMENTS[15]], 2) # degrees F\n\n    def show(self, string, colon=False):\n        segments = self.encode_string(string)\n        if len(segments) &gt; 1 and colon:\n            segments[1] |= 128\n        self.write(segments[:4])\n\n    def scroll(self, string, delay=250):\n        segments = string if isinstance(string, list) else self.encode_string(string)\n        data = [0] * 8\n        data[4:0] = list(segments)\n        for i in range(len(segments) + 5):\n            self.write(data[0+i:4+i])\n            sleep_ms(delay)\n\n\nclass TM1637Decimal(TM1637):\n    &quot;&quot;&quot;Library for quad 7-segment LED modules based on the TM1637 LED driver.\n\n    This class is meant to be used with decimal display modules (modules\n    that have a decimal point after each 7-segment LED).\n    &quot;&quot;&quot;\n\n    def encode_string(self, string):\n        &quot;&quot;&quot;Convert a string to LED segments.\n\n        Convert an up to 4 character length string containing 0-9, a-z,\n        space, dash, star and '.' to an array of segments, matching the length of\n        the source string.&quot;&quot;&quot;\n        segments = bytearray(len(string.replace('.','')))\n        j = 0\n        for i in range(len(string)):\n            if string[i] == '.' and j &gt; 0:\n                segments[j-1] |= TM1637_MSB\n                continue\n            segments[j] = self.encode_char(string[i])\n            j += 1\n        return segments\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/MicroPython\/tm1637\/tm1637.py\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p><strong>2.<\/strong> Copy the code to a file on Thonny IDE;<\/p>\n\n\n\n<p><strong>3.<\/strong>&nbsp;Go to&nbsp;<strong>File<\/strong>&nbsp;&gt;&nbsp;<strong>Save as\u2026<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"206\" height=\"294\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2020\/10\/Thonny-IDE-ESP32-ESP8266-MicroPython-Save-file-library-to-device-save-as.png?resize=206%2C294&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Thonny IDE ESP32 ESP8266 MicroPython Save file library to device save as\" class=\"wp-image-99603\"\/><\/figure><\/div>\n\n\n<p><strong>4.<\/strong>\u00a0Select save to &#8220;<strong>Raspberry Pi Pico<\/strong>\u201c:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"214\" height=\"203\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2023\/05\/Save-file-to-Raspberry-Pi-Pico.png?resize=214%2C203&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Save Files to Raspberry Pi Pico Thonny IDE\" class=\"wp-image-130899\"\/><\/figure><\/div>\n\n\n<p><strong>5.<\/strong> Save the file with the name&nbsp;<strong><em>tm1637.py<\/em><\/strong> (don\u2019t change the name).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"545\" height=\"327\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/save-tm1637-library-to-RPi-Pico.png?resize=545%2C327&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Save TM1637 library to RPi Pico\" class=\"wp-image-187705\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/save-tm1637-library-to-RPi-Pico.png?w=545&amp;quality=100&amp;strip=all&amp;ssl=1 545w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/save-tm1637-library-to-RPi-Pico.png?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 545px) 100vw, 545px\" \/><\/figure><\/div>\n\n\n<p>With the module loaded to the Pico, now you can use the library functionalities in your code to interface with the TM1637 display.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"basic-functions\">Testing the TM1637 Display (Basic Functions)<\/h2>\n\n\n\n<p>The following example shows most of the functions supported by the library. This is a modified and simplified version of the example provided by the library.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-python\"># Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n# Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-tm1637-micropython\/\n\nimport tm1637\nfrom machine import Pin\nfrom time import sleep\n\n# Initialize display (adjust pins if needed)\ndisplay = tm1637.TM1637(clk=Pin(21), dio=Pin(20))\n\n# Set display brightness\ndisplay.brightness(7)\n\nwhile True:\n    # all LEDS on &quot;88:88&quot;\n    display.write([127, 255, 127, 127])\n    sleep(1)\n\n    # all LEDS off\n    display.write([0, 0, 0, 0])\n    sleep(1)\n\n    # show &quot;0123&quot;\n    display.write([63, 6, 91, 79])\n    sleep(1)\n\n    # show &quot;COOL&quot;\n    display.write([0b00111001, 0b00111111, 0b00111111, 0b00111000])\n    sleep(1)\n\n    # show &quot;HELP&quot;\n    display.show('help')\n    sleep(1)\n\n    # display &quot;dEAd&quot;, &quot;bEEF&quot;\n    display.hex(0xdead)\n    sleep(1)\n    display.hex(0xbeef)\n    sleep(1)\n\n    # show &quot;12:59&quot;\n    display.numbers(12, 59)\n    sleep(1)\n\n    # show &quot;-123&quot;\n    display.number(-123)\n    sleep(1)\n\n    # show temperature '24*C'\n    display.temperature(24)\n    sleep(1)\n    \n    # show temperature '75*F'\n    display.temperature_f(75)\n    sleep(1)\n\n    # display scrolling text\n    display.scroll('Random Nerd Tutorials', delay=500)\n    sleep(1)\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/MicroPython\/tm1637\/tm1637_basic_functions.py\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>Now, let&#8217;s take a quick look at how the code works to understand how to use the library functions to control the display.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Initialize the Display<\/h3>\n\n\n\n<p>The following line initializes the display. You can modify it to use different pins.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>display = tm1637.TM1637(clk=Pin(21), dio=Pin(20))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Set the Brightness<\/h3>\n\n\n\n<p>To set the display brightness, you just need to use the <span class=\"rnthl rntliteral\">brightness()<\/span> method on the <span class=\"rnthl rntliteral\">display<\/span> object. Pass a number between 0 (minimum brightness) and 7 (maximum brightness).<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Set display brightness\ndisplay.brightness(7)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Writing Segments<\/h3>\n\n\n\n<p>You can use the <span class=\"rnthl rntliteral\">write()<\/span> method on the <span class=\"rnthl rntliteral\">display<\/span> object to control individual segments of each character.<\/p>\n\n\n\n<p>The TM1637 display comes with four 7-segment display digits. You can manually control individual segments of each digit with the <span class=\"rnthl rntliteral\">write()<\/span> method on the <span class=\"rnthl rntliteral\">display<\/span> object.<\/p>\n\n\n\n<p>One byte (7 lower bits) for each segment. The 8th bit (MSB) is for the colon and only on the 2nd segment.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"144\" height=\"259\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/7-segment-display-labeled.png?resize=144%2C259&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"7-segment display\" class=\"wp-image-187096\"\/><\/figure><\/div>\n\n\n<p>For example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>segment<\/strong><\/td><td><strong>bit<\/strong><\/td><\/tr><tr><td>A<\/td><td>0<\/td><\/tr><tr><td>B<\/td><td>1<\/td><\/tr><tr><td>C<\/td><td>2<\/td><\/tr><tr><td>D<\/td><td>3<\/td><\/tr><tr><td>E<\/td><td>4<\/td><\/tr><tr><td>F<\/td><td>5<\/td><\/tr><tr><td>G<\/td><td>6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Bit 1 turns a segment ON, and bit 0 turns a segment off.<\/p>\n\n\n\n<p>For example, to turn on segments A, B, and C, you&#8217;d have a byte like <span class=\"rnthl rntliteral\">0b0000111<\/span>.<\/p>\n\n\n\n<p>The byte starts with the G and ends with the A. For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><span class=\"rnthl rntliteral\">0b0000110<\/span> turns segments <strong>C<\/strong> and <strong>B<\/strong> on.<\/li>\n<\/ul>\n\n\n\n<p>You can use <span class=\"rnthl rntliteral\">0b0000110<\/span> or the corresponding hex or decimal number. <a href=\"https:\/\/github.com\/mcauser\/micropython-tm1637?tab=readme-ov-file#seven-segment-font\" target=\"_blank\" rel=\"noopener\" title=\"\">See the table provided by the library documentation<\/a>.<\/p>\n\n\n\n<p>The demo shows different examples:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># all LEDS on \"88:88\"\ndisplay.write(&#091;127, 255, 127, 127])\nsleep(1)\n\n# all LEDS off\ndisplay.write(&#091;0, 0, 0, 0])\nsleep(1)\n\n# show \"0123\"\ndisplay.write(&#091;63, 6, 91, 79])\nsleep(1)\n\n# show \"COOL\"\ndisplay.write(&#091;0b00111001, 0b00111111, 0b00111111, 0b00111000])\nsleep(1)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Display Strings<\/h3>\n\n\n\n<p>To display strings, use the <span class=\"rnthl rntliteral\">show()<\/span> method and pass as an argument the string you want to display.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># show \"HELP\"\ndisplay.show('help')<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Display a Number<\/h3>\n\n\n\n<p>Use the <span class=\"rnthl rntliteral\">numbers()<\/span> method if you want to display two numbers (with two digits) on each side of the colon. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># show \"12:59\"\ndisplay.numbers(12, 59)<\/code><\/pre>\n\n\n\n<p>To display a number, use the <span class=\"rnthl rntliteral\">number()<\/span> method. It accepts negative numbers. The number shouldn&#8217;t have more than four digits.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># show \"-123\"\ndisplay.number(-123)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Display Temperature Values<\/h3>\n\n\n\n<p>If you want to display temperature values (with two digits) with the \u00baC and \u00baF symbols, you can use the <span class=\"rnthl rntliteral\">temperature()<\/span> and <span class=\"rnthl rntliteral\">temperature_f()<\/span> functions on the <span class=\"rnthl rntliteral\">display<\/span> object. For example, in the code:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># show temperature '24*C'\ndisplay.temperature(24)\nsleep(1)\n    \n# show temperature '75*F'\ndisplay.temperature_f(75)\nsleep(1)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Display Scrolling Text<\/h3>\n\n\n\n<p>There is a very useful function if you want to display text with more than four characters. The <span class=\"rnthl rntliteral\">scroll()<\/span> function allows you to scroll a String on the display from right to left with adjustable speed.<\/p>\n\n\n\n<p>The first argument is the string you want to display, and the second argument is the speed offset in milliseconds. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># display scrolling text\ndisplay.scroll('Random Nerd Tutorials', delay=500)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Demonstration<\/h3>\n\n\n\n<p>Upload (<strong>File <\/strong>> <strong>Save as<\/strong> > <strong>Raspbberry Pi Pico<\/strong> > save the file with the name <em>main.py<\/em>) the code to your board using Thonny IDE.<\/p>\n\n\n\n<p>Or run it directly on the board from the computer using the green run button (with this option, the code will only run when the board is connected to the computer).<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"114\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/image.png?resize=470%2C114&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Thonny IDE Run Code\" class=\"wp-image-163213\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/image.png?w=470&amp;quality=100&amp;strip=all&amp;ssl=1 470w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/image.png?resize=300%2C73&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/figure><\/div>\n\n\n<p>Don&#8217;t forget that you must have uploaded the <em>tm1637.py<\/em> library previously.<\/p>\n\n\n\n<p>The display will be running the demo code, showing the different use cases.<\/p>\n\n\n\n<div class=\"wp-block-jetpack-tiled-gallery aligncenter is-style-rectangular\"><div class=\"\"><div class=\"tiled-gallery__gallery\"><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-4.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-4.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"RPi Pico TM1637 Display Demo, all segments on\" data-height=\"422\" data-id=\"187822\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=187822#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-4.jpg\" data-width=\"750\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-4.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-3.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-3.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"RPi Pico TM1637 Display Demo . Display Text\" data-height=\"422\" data-id=\"187821\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=187821#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-3.jpg\" data-width=\"750\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-3.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><\/div><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-2.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-2.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"RPi Pico TM1637 Display Demo . Display Negative Numbers\" data-height=\"422\" data-id=\"187820\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=187820#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-2.jpg\" data-width=\"750\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-2.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-1.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-1.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"RPi Pico TM1637 Display Demo . Display Time\" data-height=\"422\" data-id=\"187819\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=187819#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-1.jpg\" data-width=\"750\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Demo-1.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><\/div><\/div><\/div><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"tm1637-display-temperature\">TM1637 7-Segment Display with RPi Pico &#8211; Display Internal Temperature Sensor<\/h2>\n\n\n\n<p>To show you a practical example of using the TM1637 7-Segment display, we&#8217;ll create a simple project to display the <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-internal-temperature-micropython\/\" target=\"_blank\" rel=\"noopener\" title=\"\"><strong>RPi Pico internal temperature<\/strong><\/a> on the screen.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>We get the Pico&#8217;s internal temperature.<\/li>\n\n\n\n<li>The temperature is displayed on the TM1637 display in Celsius degrees.<\/li>\n\n\n\n<li>The temperature is also displayed in Fahrenheit degrees.<\/li>\n<\/ol>\n\n\n\n<p>To get readings from the Pico&#8217;s internal temperature sensor, we&#8217;ll use the <span class=\"rnthl rntliteral\">pico_temp_sensor<\/span> class from the <span class=\"rnthl rntliteral\">picozero<\/span> package. Follow the next instructions to install the package before proceeding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the picozero Package<\/h3>\n\n\n\n<p>You need to install the <span class=\"rnthl rntliteral\">picozero<\/span> package before proceeding.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to <strong>Tools<\/strong> &gt; <strong>Manage<\/strong> <strong>Packages<\/strong>.<\/li>\n\n\n\n<li>Search for <strong>picozero<\/strong>.<\/li>\n\n\n\n<li>Click on the first <em>picozero @ PyPi<\/em> option.<\/li>\n\n\n\n<li>Finally, click <strong>Install<\/strong>.<\/li>\n<\/ol>\n\n\n\n<p>After a few seconds, the package will be installed.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"464\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/install-picozero.png?resize=644%2C464&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Raspberry Pi Pico installing the picozero package\" class=\"wp-image-146347\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/install-picozero.png?w=644&amp;quality=100&amp;strip=all&amp;ssl=1 644w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/01\/install-picozero.png?resize=300%2C216&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Code<\/h2>\n\n\n\n<p>You can upload the following code to your board.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-python\"># Rui Santos &amp; Sara Santos - Random Nerd Tutorials\n# Complete project details at https:\/\/RandomNerdTutorials.com\/raspberry-pi-pico-tm1637-micropython\/\n\nimport tm1637\nfrom picozero import pico_temp_sensor\nfrom machine import Pin, Timer\nimport time\n\n# Initialize display (adjust pins if needed)\ndisplay = tm1637.TM1637(clk=Pin(21), dio=Pin(20))\n\n# Set display brightness\ndisplay.brightness(7)\n\n# Convert from celsius to fahrenheit\ndef celsius_to_fahrenheit(temp_celsius): \n    temp_fahrenheit = temp_celsius * (9\/5) + 32 \n    return temp_fahrenheit\n\n# Get temperature readings\ndef getTemperature(Timer):\n    # Declare these variables as globals\n    global temperature_c, temperature_f\n    \n    # Reading and printing the internal temperature\n    temperature_c = pico_temp_sensor.temp\n    temperature_f = celsius_to_fahrenheit(temperature_c)\n\n    print(f'Internal temperature in Celsius: {temperature_c:.2f}')\n    print(f'Internal temperature in Fahrenheit: {temperature_f:.2f}')\n\n# Get temperature for the first time\ngetTemperature(0)\n\n# Create a periodic timer that gets new temperature readings\napi_timer = Timer()\napi_timer.init(mode=Timer.PERIODIC, period=60000, callback=getTemperature)\n\nwhile True:\n    display.temperature(round(temperature_c))\n    time.sleep(5)\n    display.temperature_f(round(temperature_f))\n    time.sleep(5)\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Raspberry-Pi-Pico\/MicroPython\/tm1637\/tm1637_internal_temp_sensor.py\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How Does the Code Work?<\/h3>\n\n\n\n<p>Let&#8217;s just take a quick look to see how the code works.<\/p>\n\n\n\n<p>Start by including the required libraries.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>import tm1637\nfrom picozero import pico_temp_sensor\nfrom machine import Pin, Timer\nimport time<\/code><\/pre>\n\n\n\n<p>Initialize the display and set the maximum brightness.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Initialize display (adjust pins if needed)\ndisplay = tm1637.TM1637(clk=Pin(21), dio=Pin(20))\n\n# Set display brightness\ndisplay.brightness(7)<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">getTemperature()<\/span> function will get the Pico&#8217;s internal temperature sensor and save it in the <span class=\"rnthl rntliteral\">temperature_c<\/span> and <span class=\"rnthl rntliteral\">temperature_f<\/span> global variables.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Get temperature readings\ndef getTemperature(Timer):\n    # Declare these variables as globals\n    global temperature_c, temperature_f\n    \n    # Reading and printing the internal temperature\n    temperature_c = pico_temp_sensor.temp\n    temperature_f = celsius_to_fahrenheit(temperature_c)\n\n    print(f'Internal temperature in Celsius: {temperature_c:.2f}')\n    print(f'Internal temperature in Fahrenheit: {temperature_f:.2f}')<\/code><\/pre>\n\n\n\n<p>This function will then be called by a timer, which is why we need to add a <span class=\"rnthl rntliteral\">Timer<\/span> argument to the function.<\/p>\n\n\n\n<p>After that, we call the <span class=\"rnthl rntliteral\">getTemperature()<\/span> function when the code first runs.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Get temperature for the first time\ngetTemperature(0)<\/code><\/pre>\n\n\n\n<p>We create a timer that will call the <span class=\"rnthl rntliteral\">getTemperature()<\/span> function every 600000 milliseconds (10 minutes) to get the latest Pico&#8217;s internal temperature.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code># Create a periodic timer that gets new temperature readings\napi_timer = Timer()\napi_timer.init(mode=Timer.PERIODIC, period=60000, callback=getTemperature)<\/code><\/pre>\n\n\n\n<p class=\"rntbox rntclblue\">To learn more about timer interrupts with the Raspberry Pi Pico, check out this tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-interrupts-micropython\/\">Raspberry Pi Pico with Interrupts: External and Timer Interrupts (MicroPython)<\/a>.<\/p>\n\n\n\n<p>Finally, we create a <span class=\"rnthl rntliteral\">while True<\/span> loop to continuously display weather data. We display the temperature in Celsius and in Fahrenheit.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>while True:\n    display.temperature(round(temperature_c))\n    time.sleep(5)\n    display.temperature_f(round(temperature_f))\n    time.sleep(5)<\/code><\/pre>\n\n\n\n<p>To display the temperature in Celsius, we call the <span class=\"rnthl rntliteral\">temperature()<\/span> function on the <span class=\"rnthl rntliteral\">display<\/span> object. We need to round the temperature because the function only accepts numbers with two digits.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>display.temperature(round(temperature_c))<\/code><\/pre>\n\n\n\n<p>Finally, we call the <span class=\"rnthl rntliteral\">temperature_f()<\/span> function to display the temperature in Fahrenheit.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code>display.temperature_f(round(temperature_f))<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Run or upload (<strong>File <\/strong>&gt; <strong>Save as<\/strong> &gt; <strong>Raspberry Pi Pico<\/strong> &gt; save the file with the name <em>main.py<\/em>) the code to your board using Thonny IDE.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"114\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/image.png?resize=470%2C114&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Thonny IDE Run Code\" class=\"wp-image-163213\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/image.png?w=470&amp;quality=100&amp;strip=all&amp;ssl=1 470w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2024\/10\/image.png?resize=300%2C73&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/figure><\/div>\n\n\n<p>Don&#8217;t forget that you must have uploaded the <em>tm1637.py<\/em> library previously and installed the <span class=\"rnthl rntliteral\">picozero<\/span> package.<\/p>\n\n\n\n<p>You&#8217;ll get the current RPi Pico&#8217;s internal temperature on the screen in Celsius and Fahrenheit.<\/p>\n\n\n\n<div class=\"wp-block-jetpack-tiled-gallery aligncenter is-style-rectangular\"><div class=\"\"><div class=\"tiled-gallery__gallery\"><div class=\"tiled-gallery__row\"><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Celsius.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Celsius.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"RPi Pico with TM1637 Display Temperature Celsius\" data-height=\"422\" data-id=\"187817\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=187817#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Celsius.jpg\" data-width=\"750\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Celsius.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><div class=\"tiled-gallery__col\" style=\"flex-basis:50.00000%\"><figure class=\"tiled-gallery__item\"><img decoding=\"async\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Fahrenheit.jpg?strip=info&#038;w=600&#038;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Fahrenheit.jpg?strip=info&#038;w=750&#038;ssl=1 750w\" alt=\"RPi Pico with TM1637 Display Temperature Fahrenheit\" data-height=\"422\" data-id=\"187816\" data-link=\"https:\/\/randomnerdtutorials.com\/?attachment_id=187816#main\" data-url=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Fahrenheit.jpg\" data-width=\"750\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/RPi-Pico-TM1637-Display-Temperature-Fahrenheit.jpg?ssl=1\" data-amp-layout=\"responsive\"\/><\/figure><\/div><\/div><\/div><\/div><\/div>\n\n\n\n<p>You&#8217;ll get the same information on the MicroPython Shell.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"365\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/get-Pico-Internal-Temperature-MicroPython-Shell-Thonny-IDE.png?resize=735%2C365&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Get RPi Pico internal temperature sensor and display on the MicroPython shell - Thonny IDE\" class=\"wp-image-187734\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/get-Pico-Internal-Temperature-MicroPython-Shell-Thonny-IDE.png?w=735&amp;quality=100&amp;strip=all&amp;ssl=1 735w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/get-Pico-Internal-Temperature-MicroPython-Shell-Thonny-IDE.png?resize=300%2C149&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 735px) 100vw, 735px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to interface the TM1637 4-digit 7-segment display with the Raspberry Pi Pico programmed with MicroPython. As you&#8217;ve seen, it is straightforward to display data on the screen thanks to the <em>tm1637.py<\/em> module.<\/p>\n\n\n\n<p>You can display a wide variety of data on the display, but the most common uses are to display temperature and to create a digital clock or a countdown timer.<\/p>\n\n\n\n<p>We hope you&#8217;ve found this guide useful. We have Raspberry Pi Pico guides for other displays that you may be interested in:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-i2c-lcd-display-micropython\/\">Raspberry Pi Pico with I2C LCD Display (MicroPython)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-ssd1306-oled-micropython\/\">Raspberry Pi Pico: SSD1306 OLED Display (MicroPython)<\/a><\/li>\n<\/ul>\n\n\n\n<p>Learn more about programming the Raspberry Pi Pico using MicroPython with our eBook:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-w-micropython-ebook\/\"><strong>Learn Raspberry Pi Pico\/Pico W with MicroPython<\/strong><\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to use the TM1637 4-Digit 7-Segment Display with the Raspberry Pi Pico programmed with MicroPython. We provide instructions on how to wire the display to the board, install &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Raspberry Pi Pico: TM1637 4-Digit 7-Segment Display (MicroPython)\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/raspberry-pi-pico-tm1637-micropython\/#more-187702\" aria-label=\"Read more about Raspberry Pi Pico: TM1637 4-Digit 7-Segment Display (MicroPython)\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":187828,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324,326],"tags":[],"class_list":["post-187702","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspberry-pi-pico","category-raspberry-pi-pico-micropython"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2026\/01\/Raspberry-Pi-Pico-TM1637-Micropython-Tutorial.jpg?fit=1920%2C1080&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/187702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=187702"}],"version-history":[{"count":21,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/187702\/revisions"}],"predecessor-version":[{"id":190736,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/187702\/revisions\/190736"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/187828"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=187702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=187702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=187702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}