TM1637 - Grove 4 digit display

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
User avatar
mcauser
Posts: 373
Joined: Mon Jun 15, 2015 8:03 am

TM1637 - Grove 4 digit display

Post by mcauser » Mon Jan 22, 2018 12:07 pm

Ported my MicroPython TM1637 library to the micro:bit.
https://github.com/mcauser/microbit-tm1637
https://github.com/mcauser/micropython-tm1637

Code: Select all

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

tm.scroll('cool story bro')

User avatar
deshipu
Posts: 1346
Joined: Thu May 28, 2015 5:54 pm

Re: TM1637 - Grove 4 digit display

Post by deshipu » Mon Jan 22, 2018 2:26 pm

Great job! We need more displays for micro:bit.

benb
Posts: 3
Joined: Sun Jun 02, 2019 11:21 am

Re: TM1637 - Grove 4 digit display

Post by benb » Sun Jun 02, 2019 11:30 am

Hello.

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.

Ben-B

User avatar
mcauser
Posts: 373
Joined: Mon Jun 15, 2015 8:03 am

Re: TM1637 - Grove 4 digit display

Post by mcauser » Sun Jun 02, 2019 12:26 pm

Hi,

I use UFS to copy .py files to my board.
https://github.com/ntoll/microfs

First, you need to upload the driver:
ufs put tm1637.py

Then create a main.py file, which will run on boot. See examples:
https://github.com/mcauser/microbit-tm1 ... r/examples
ufs put main.py

Alternatively, you can use the mu editor:
https://codewith.mu/

benb
Posts: 3
Joined: Sun Jun 02, 2019 11:21 am

Re: TM1637 - Grove 4 digit display

Post by benb » Sun Jun 02, 2019 1:07 pm

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 tm1637.py driver into my card with mu.
I drag the file directly into my board on Windows Explorer, but when I flash the main.py 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?

User avatar
jimmo
Posts: 230
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: TM1637 - Grove 4 digit display

Post by jimmo » Sun Jun 02, 2019 1:22 pm

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 main.py on the filesystem.

So for this library, you need tm1637.py 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 tm1637.py 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)

benb
Posts: 3
Joined: Sun Jun 02, 2019 11:21 am

Re: TM1637 - Grove 4 digit display

Post by benb » Sun Jun 02, 2019 1:32 pm

What a quick reply.

Thanks a lot!

I am using mu. I may do something wrong.

What I do is :
- I drag the tm1637.py into my card with Microsoft explorer
- I oper the main.py 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 tm1637.py directly into the card is not the solution but I don't know how to do it with mu

User avatar
jimmo
Posts: 230
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: TM1637 - Grove 4 digit display

Post by jimmo » Sun Jun 02, 2019 11:57 pm

benb wrote:
Sun Jun 02, 2019 1:32 pm
- I drag the tm1637.py 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: https://codewith.mu/en/howto/1.0/copy_files_microbit

rhubarbdog
Posts: 164
Joined: Tue Nov 07, 2017 11:45 pm

Re: TM1637 - Grove 4 digit display

Post by rhubarbdog » Mon Jun 03, 2019 6:42 pm

That @mcauser code is bloated. I offered this as a pull request https://github.com/rhubarbdog/microbit-tm1637

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

Post Reply