
Managing MicroPython Modules with Mip on Raspberry Pi Pico
Managing modules in Python is often achieved by way of pip, the Python package deal supervisor that makes use of a PyPi-provided repository to record obtainable Python modules. However what about MicroPython? There was once upip, the micro model of pip, however now there may be mip, the brand new, official light-weight package deal supervisor for MicroPython.
Mip is designed for all MicroPython gadgets, whether or not on-line or offline. Units that may connect with the web can be utilized straight via the Python Shell, whereas offline gadgets can use a device known as mpremote to put in modules out of your laptop.
On this how-to charge, we’ll present you how one can use mip straight on a pc. Raspberry Pi Pico Wthen a Raspberry Pi Pico and distant management. We’ll additionally undergo just a few helpful mpremote instructions.
Utilizing mip with Raspberry Pi Pico W
Utilizing mip with a networked MicroPython system signifies that modules will be put in straight on the system, just like pip putting in Python modules and package deal managers on Linux.
one. observe these steps To obtain the newest model of MicroPython for Raspberry Pi Pico W. An important steps are to obtain and set up the UF2 firmware picture and set up Thonny. The remainder is optionally available. Ensure you obtain MicroPython 1.20 or newer.
2. open Tonny And Click on the cease button to refresh the connection. This ensures that the Python shell works clearly and accurately.
3. Create a brand new file. This file will comprise all the required steps to connect with Wi-Fi.
4. Add the next strains of code to the brand new file. Change the SSID and PASSWORD to go well with you.
import community
wlan = community.WLAN(community.STA_IF)
wlan.energetic(True)
wlan.join("SSID","PASSWORD")
print(wlan.isconnected())
5. Save the file as network-connection.py on Raspberry Pi Pico W
6. Click on Run to provoke a Wi-Fi connection. After just a few seconds it ought to print True to the Python shell. This means that we now have an Web connection. If incorrect, click on Cease after which Run once more.
7. Import mip, the light-weight package deal supervisor.
import mip
8. Check mip by putting in a package deal. I selected umqtt, an MQTT module for MicroPython. Packages are put in by calling the set up operate of mip and passing a package deal identify to it. Mip makes use of micropython-lib as its index, Python 3’s package deal administration, pip makes use of the PyPI index.
mip.set up(“umqtt.easy”)
9. Check putting in a third-party MicroPython package deal. Mip may also be used to put in third-party packages outdoors of the micropython-lib listing. Right here we move the URL of the add operate. PicoZero library From the Raspberry Pi Basis.
mip.set up(“https://uncooked.githubusercontent.com/RaspberryPiFoundation/picozero/grasp/picozero/picozero.py”)
Utilizing Mip with Mpremote on Raspberry Pi Pico
For MicroPython on a tool with out community entry, a Raspberry Pi Pico, mip will should be used with mpremote, a device that can talk with the system over a USB/serial interface.
one. observe these steps To obtain the newest model of MicroPython for Raspberry Pi Pico W. An important steps are to obtain and set up the UF2 firmware picture and set up Thonny. The remainder is optionally available. Ensure you obtain MicroPython 1.20 or newer.
2. make sure Python 3 is put in in your machine.
3. Open a Command Immediate and use pip to put in mpremote.
pip set up mpremote
4. run mpremote and move mip as argument, And then specify the package deal identify or the URL of the module. I am putting in a package deal to make use of right here Seven section show with Pico.
mpremote mip set up https://uncooked.githubusercontent.com/mcauser/micropython-tm1637/grasp/tm1637.py
Different Helpful mpremote Instructions
Mpremote is a useful gizmo for fast duties on a MicroPython system. We have detailed just a few further helpful instructions to assist handle a MicroPython system.
distant management: It mechanically connects to a tool operating MicroPython to view the output of the operating code. Press CTRL + ]to shut the connection.
distant repl: An interactive Python shell, the place the consumer can work straight with the {hardware}, opens a REPL (Learn, Consider, Print, Loop).
mpremote gentle reset: Restart the linked MicroPython system. This is similar as urgent CTRL + D in REPL.
mpremote fs
command | Definition |
---|---|
cat | Reveals the contents of a file |
work | Record the contents of the present listing |
work | Record the contents of a particular listing |
CP [-r] | Copy the recordsdata. Use the : prefix to specify a file on a MicroPython system. Recursive makes use of -r |
rm | Take away recordsdata from system |
mkdir | Create a listing on the system |
is rm | Delete a listing on the system |
to the touch | Create a file on the system utilizing |
Within the instance, we record the contents of the flash storage, create a brand new file, then relist the storage to see the brand new file.
MORE: Greatest RP2040 Motherboards
MORE: Greatest Raspberry Pi Tasks
MORE: Raspberry Pi: Tips on how to Get Began
#Managing #MicroPython #Modules #Mip #Raspberry #Pico