For an index to all my stories click this text.
The world changes, and so does the MicroPython language.
In the latest versions of MicroPython a new method to install libraries was introduced : MIP And it is supposed to make life less complicated.
How I use(d) to install libraries.
When I need a display in a MicroPython project I often use a TM1637 quad 7 segment display. To be able to use this display you'll need a library.
THE place to find libraries for MicroPython is Mike Causers repo at Github:
https://github.com/mcauser/awesome-micropython
Scrolling through this huge list of libraries the TM1637 library is in the LED Segment section (about half way down the page).
Clicking micropython-tm1637 brings you to the github page that contains the driver.
At that page I click on the drivers entry being tm1637.py
This is the MicroPython driver for the TM1637. As you can see it is actually just a MicroPython program.
I copy the complete code and paste it into Thonny.
Then I save this in the lib folder using the exact name the library has. In this case tm1637.py
And there it is, in the Pico's memory, in the lib folder, ready to use.
Using MIP
Now let's see how the new method works. MIP is supposed to make this all less complicated. Well let's have a look.
First step is to know where the library is located.
So we need to look at the same library list mentioned above.
Then we need to scroll downwards to the LED Segment section.
Like above described we need to click on the drivers entry in the list.
And then click on the actual driver.
So until now everything is the same.
But we now have the exact URL where the driver is located:
https://github.com/mcauser/micropython-tm1637/tm1637.py
We can use that with MIP.
MIP knows Github so we can leave https://github.com/ out and just use github: like this:
mip.install("github:mcauser/micropython-tm1637/tm1637.py")
But first we need to install MIP.
So these are the lines that are needed:
import mip
mip.install("github:mcauser/micropython-tm1637/tm1637.py")
And this is the output I got.
It did not work.
Of course it did not work !!! MIP gets the driver from the internet, so you have to activate Wifi first.........
import network import time ssid = "Ziggo2903181" pw = "ptzbB2ohKbgs7agp" print("Connecting to wifi...") # wifi connection wifi = network.WLAN(network.STA_IF) wifi.active(True) wifi.connect(ssid, pw) print('Waiting for connection.',end="") while wifi.isconnected() == False: time.sleep(1) print('', end='.') print("") ip = wifi.ifconfig()[0] print("Connected with IP adress : "+ip) import mip mip.install("github:mcauser/micropython-tm1637/tm1637.py")
And now it works.
The library is automatically downloaded and placed in the /lib folder.
Conclusion:
Actually it is a lot of hassle.
The first steps are the same as in my original method. Then you have to make sure you got the URL right and then write a small program in MicroPython that activates the Wifi.
To be frank: by that time I have already copied and pasted and saved the library by hand.
Mip comes from the land of Python. And Python runs mostly on desktop computers and notebooks. These machines have an internet connection standard activated and then it is a lot less hassle.
On our microcontrollers Wifi is not standard activated.
Looking at the start of this story:
The world changes and MicroPython changes to.
But not all changes are for the better. Luckily the old method still works.
Till next time
have fun
Luc Volders