Page 1 of 1

TM1637 - Grove 4 digit display

Posted: Mon Jan 22, 2018 12:07 pm
by mcauser
Ported my MicroPython TM1637 library to the micro:bit.

Code: Select all

from microbit import *
from tm1637 import TM1637
tm = TM1637(clk=pin1, dio=pin2)

tm.scroll('cool story bro')

Re: TM1637 - Grove 4 digit display

Posted: Mon Jan 22, 2018 2:26 pm
by deshipu
Great job! We need more displays for micro:bit.

Re: TM1637 - Grove 4 digit display

Posted: Sun Jun 02, 2019 11:30 am
by benb

I am a teacher and I would love to use your programme with my micro:bit to use the TM1637.
I code in python since a while but I am quite new with micro:bit, And to say the truth... I have an issue.

I tried your programme but sadly I have no idea how to instal the library into my card ...

Do you have a simple solution to add a library into my micro:bit ?

Thank you.


Re: TM1637 - Grove 4 digit display

Posted: Sun Jun 02, 2019 12:26 pm
by mcauser

I use UFS to copy .py files to my board.

First, you need to upload the driver:
ufs put

Then create a file, which will run on boot. See examples: ... r/examples
ufs put

Alternatively, you can use the mu editor:

Re: TM1637 - Grove 4 digit display

Posted: Sun Jun 02, 2019 1:07 pm
by benb
What a quick reply

First of all, thanks a lot!

Sadly I can't instal UFS, my computer is provided by my school and I need admin account (a nightmare)...

But hopefully, I got mu on my computer
My only issue is how to upload properly the driver into my card with mu.
I drag the file directly into my board on Windows Explorer, but when I flash the with mu, the card write the message " error line 2" where the tm library is called "from tm1637 import TM1637"

Do you have a solution?

Re: TM1637 - Grove 4 digit display

Posted: Sun Jun 02, 2019 1:22 pm
by jimmo
Just some extra background in case it's helpful:

The microbit has two ways of putting python code onto it -- via the .hex file that you drag onto the virtual flash drive, and the built-in filesystem. (My experience has been that many people, even who have spent a lot of time doing cool stuff with the micro:bit, have never used the built-in fileystem).

When you use Mu (it's really good!) it's doing the first way. Whichever file you're currently viewing, when you click the flash button, it makes up a .hex file and sends it over to the device. But as mcauser mentioned, Mu also has a way to browse the built-in filesystem too (using the Files button), and you can store files on there too, but these will be wiped if you flash a program the regular way. There's a special case for if there's a file named on the filesystem.

So for this library, you need to be on the filesystem, such that you can write "import tm1637" in your program.

My experience with doing micro:bit workshops and classes with students has been that working with modules and the filesystem is too complicated. The easiest option has been to just copy the contents of the library to the top of your program and use it directly.

i.e. this is your python code in Mu:

Code: Select all

# Copy the contents of exactly
from microbit import sleep

_SEG = 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')

class TM1637(object):
  # ... etc
# Then write your actual micro:bit program here:
display = TM1637(pin0, pin1)
while True:
  if button_a.was_pressed():
    # ... etc
There is a small disadvantage to doing it this way (you will have less space available for your program), but for us it was worth it.

(What I said above about Mu and the hex file isn't strictly accurate if you have a slightly newer micro:bit with the upgraded daplink firmware, but the idea is the same)

Re: TM1637 - Grove 4 digit display

Posted: Sun Jun 02, 2019 1:32 pm
by benb
What a quick reply.

Thanks a lot!

I am using mu. I may do something wrong.

What I do is :
- I drag the into my card with Microsoft explorer
- I oper the with mu and I flash it into my card.

And the card sends me the message "line 3 import error no module named 'TM1637' " where the tm1637 library is called ...
line 3 is: from tm1637 import TM1637

I think to drag the directly into the card is not the solution but I don't know how to do it with mu

Re: TM1637 - Grove 4 digit display

Posted: Sun Jun 02, 2019 11:57 pm
by jimmo
benb wrote:
Sun Jun 02, 2019 1:32 pm
- I drag the into my card with Microsoft explorer
Sorry I should have added an extra point -- the built-in filesystem in the micro:bit has nothing to do with the virtual USB drive you see in Windows Explorer. The foloder you see in Windows Explorer only supports one thing: dragging a .hex file onto it to completely reprogram the micro:bit. (And this is what Mu is doing behind the scenes when you press the "Flash" button)

The "built-in filesystem" feature we're talking about it is not visible to Windows Explorer. Mu has this special "Files" mode which you can use to access it (or you can use ufs/microfs as @mcauser mentioned). More info here:

Re: TM1637 - Grove 4 digit display

Posted: Mon Jun 03, 2019 6:42 pm
by rhubarbdog
That @mcauser code is bloated. I offered this as a pull request

The code is slightly bigger, but it's obvious what can be deleted and therefore more useful in the very limited microbit