installing default libraries on pico

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
codeboy66
Posts: 6
Joined: Sat Feb 27, 2021 8:52 am

installing default libraries on pico

Post by codeboy66 » Sat Feb 27, 2021 9:15 am

hey, I'm very new to programming micropython, especially on the Raspberry Pi Pico :oops:
I don't get Libraries working... I know that if I use a Library, I need to copy the library file also to the Pico (e.g. via Thonny).

Currently, I'm trying to get the DHT sensor working... I saw that there is a default DHT Library included in Micropython: https://docs.micropython.org/en/latest/ ... l/dht.html
But how do I use this Library on the Pico?

if I'm using the default code from below, I get this error message

Code: Select all

import dht
import machine

d = dht.DHT11(machine.Pin(4))
d.measure()
d.temperature() # eg. 23 (°C)
d.humidity()    # eg. 41 (% RH)

d = dht.DHT22(machine.Pin(4))
d.measure()
d.temperature() # eg. 23.6 (°C)
d.humidity()    # eg. 41.3 (% RH)
Image

So how to handle these standard Libraries on the Pico?
What about other Libraries e.g. Neopixel etc.

Thank you so mutch
Joe

cebersp
Posts: 30
Joined: Mon Feb 08, 2021 12:07 pm

Re: installing default libraries on pico

Post by cebersp » Sat Feb 27, 2021 9:57 am

Hi,
per rightclick on the library in thonny you can upload the file to the board.
Christof

codeboy66
Posts: 6
Joined: Sat Feb 27, 2021 8:52 am

Re: installing default libraries on pico

Post by codeboy66 » Sat Feb 27, 2021 10:08 am

cebersp wrote:
Sat Feb 27, 2021 9:57 am
Hi,
per rightclick on the library in thonny you can upload the file to the board.
Christof
What do you mean with "right-click on the library"? in the actual code or were?

danjperron
Posts: 51
Joined: Thu Dec 27, 2018 11:38 pm
Location: Québec, Canada

Re: installing default libraries on pico

Post by danjperron » Sat Feb 27, 2021 1:35 pm

Did you try my version?
viewtopic.php?f=21&t=9808
It's using the state machine. This way timing is always perfect!
Just copy the DHT22.py into the Pico. Check the test script to see how to implement it

User avatar
Grumpy_Mike
Posts: 8
Joined: Sun Feb 14, 2021 8:04 pm

Re: installing default libraries on pico

Post by Grumpy_Mike » Sat Feb 27, 2021 2:17 pm

Code: Select all

But how do I use this Library on the Pico?
You first have to load in into the Pico. To do this click on the Tools menu in Thonny and choose "Manage Packages ..."
The search for dht in the box. It should come up with at least one option. Choose the one that looks right from the description and select download.
This will then create a folder in the flash memory of your Pico and install the dht file into that.
Then you won't get that error message again.

codeboy66
Posts: 6
Joined: Sat Feb 27, 2021 8:52 am

Re: installing default libraries on pico

Post by codeboy66 » Sat Feb 27, 2021 6:02 pm

Thanks a lot! This is useful for external libraries!
But I asked how to use the MicroPython Libraries that came with micropython. e.g. the default dht library which I posted a link to.

Is there a way to use these "default" Libraries?

codeboy66
Posts: 6
Joined: Sat Feb 27, 2021 8:52 am

Re: installing default libraries on pico

Post by codeboy66 » Sat Feb 27, 2021 6:36 pm

I've found these files: https://github.com/micropython/micropyt ... rivers/dht
are they the files I need? (because the .py is too "short")

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: installing default libraries on pico

Post by scruss » Sat Feb 27, 2021 9:52 pm

MicroPython doesn't have quite the same concept of standard libraries. Each board comes with its own set, and sometimes there's no overlap. For the Pico in particular, the WS2812 (NeoPixel) code uses the PIOs, which other boards don't have. This isn't wrapped in a standard library (yet)

The Pico WS2812 code looks like this: https://github.com/raspberrypi/pico-mic ... py#L1-L104

Post Reply