CircuitPython libraries on MicroPython (Raspberry Pi Pico)

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

Following the steps of the respective chapter in your ‚Learn‘ section by M. LeBlanc-Williams, everything was executed and properly downloaded as instructed. When running the code.py script (BME280 example) on the Raspberry Pi Pico (MicroPython version v1.19.1), the following message appears:

Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "/lib/board.py", line 21, in <module>
ImportError: no module named 'adafruit_platformdetect'

Platform_detect and Blinka files were all uploaded on the Pico (lib), and several resets didn‘t change the result. Any advice what to do? Many thanks in advance for your comments.

User avatar
Franklin97355
 
Posts: 23902
Joined: Mon Apr 21, 2008 2:33 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Franklin97355 »

Have you downloaded the circuit python uf2?

User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

No, I am running the Pico with MicroPython (version 1.19.1).

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by neradoc »

Hi, can you show the content of your lib directory ?
Does it look like this ?

Image

User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

Many thanks neradoc for your comment.

Yes, absolutely right, that is one of two questionable points which I found. After troubleshooting yesterday, I noticed two steps in the tutorial that caused error messages:
1.) In the Blinka zip package, copying the entire content of the src folder is not correct, as it adds the „micropython stubs“ archive. This archive is not to be copied onto the ‚lib‘ of the pico.
2.) The statement in the tutorial ‚If you want to free up some more room, many of the linux board and microcontroller files can be removed under the adafruit_blinka folder. The only ones used by the Pico are the adafruit_blinka/microcontroller/rp2040.py and adafruit_blinka/board/raspberrypi/pico.py.‘
makes your delete more files than you‘re supposed to do, as I got a new import failure message of a missing gen micropython lib. ‚Generic linux‘ and ‚generic micropython‘ was guarded and uploaded on the pico.

Now the software seems to work, however I got an error message that the BME280 sensor cannot be detected (and hence no readings appear). Previous I2C scan, however, showed the right address (119 and 0x77). The fault was that my I2C pins were set to GP4 and GP5, as the example in the tutorial mentions GP0 and GP1. After reconnecting, the hardware spitted out an SCL line fault. Up to me to continue to troubleshoot why GP1 is not responding. As this is no longer a software issue – seems at least – I thank you for your comments.

User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

Last part resolved: typo in the i2c scanning code, instead of the GP numbering (0 and 1) I typed the pico numbers of the pins, 1 and 2. The sensor readings are now correctly displayed. Thanks!

User avatar
MakerMelissa
 
Posts: 375
Joined: Wed Jun 05, 2013 2:10 am

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by MakerMelissa »

Awesome Zororojo. Do you have any suggestions that would have made the tutorial easier to follow?

User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

Hi Melissa,
firstly, I would like to thank you for this great tutorial - it is easy to follow and succeeded at the end to not only learn a lot about the CircuitPython - Micropython architecture, but made the BME280 sensor running. Let me go through the tutorial again and come up with some precise suggestions. These are only minor details, but as always the devil lies in the detail... :-)
I will get back to you.

User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

Hi Melissa,

here my feedback to the tutorial.

- My background is mechanical engineering with basic/advanced IT knowledge. In terms of IoT and the microcomputer and -controller world, I am rather at a beginner‘s level. My hardware is a RP pico 2040 (headers soldered by myself) and I use Thonny as an IDE. Computer OS is Linux Mint.

- Starting point was „Installation and libraries“. Section „Using the file transfer interface“ was great, as it showed me in a clear way how to download the different libraries from pip to my computer, and upload them to the pico.

- „Download the Blinka and PlatformDetect files“: clear explanations with accurate link to the zip files.

- „Installation of the Blinka files“: Here I suggest to mention that the ‚micropython-stubs‘ folder should be excluded from the download.

- Note to free some more room on the pico:
Firstly, I suggest to stress that the respective ‚microcontroller‘ folder can be found under ‚/Adafruit_Blinka-8.16.1/src/adafruit_blinka/‘, as there is a second one under ‚/Adafruit_Blinka-8.16.1/src/‘. Should be fool-proof as the latter only contains two scripts, but with a hint it would be unambiguous.
Secondly, under the link ‚/Adafruit_Blinka-8.16.1/src/adafruit_blinka/microcontroller/‘, the two files ‚generic_linux‘ and ‚generic_micropython‘ should be kept and uploaded on the pico (at least the generic_micropython‘ one, as this caused a error message during one of my attempts.

- „Download the CircuitPython library bundle“: Well-explained and easy to identify, although three zip files can be downloaded. In the past, I often faced issues to find the right file to download, as in other literature there were ambiguities.

- „Code download / copy“: Easy way to get the code on the board, and running.

Overall, great job – congratulations. As I continue to explore all the hardware of my purchases from Adafruit, my next step is to connect an 128x128 1.5“ OLED display (SSD1327) to show the BME280 data, and I already saw that you have provided a tutorial for this part as well! Looking forward studying it. I already have a question (a dumb one, as I am on beginner‘s level, sorry. Goal is eventually to build a sort of mini-weather station): In terms of power supply (with no breakout board), I intend to connect a LiPo 3.7V battery to the pico. Which pins do you recommend to use to supply both the BME280 sensor and the screen, apart from pin38 (3V3OUT)? GRD pins we have plenty, but which 2nd power supply pin would make most sense?

Many thanks and again, great job!

Greetings,
Zororojo

User avatar
MakerMelissa
 
Posts: 375
Joined: Wed Jun 05, 2013 2:10 am

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by MakerMelissa »

Awesome. Thank you so much for your time and suggestions going through there.
As I continue to explore all the hardware of my purchases from Adafruit, my next step is to connect an 128x128 1.5“ OLED display (SSD1327) to show the BME280 data, and I already saw that you have provided a tutorial for this part as well! Looking forward studying it.
One thing you may run into with connecting a bunch of devices is that you may run out of memory. Unfortunately Blinka + MicroPython + Libraries leave very little. My suggestion would be to try out CircuitPython for the following reasons:
  • It's a fork of MicroPython and the main difference is the approach in getting up and running. It appears as a drive on your computer and you just edit the files. It's super simple and powerful at the same time.
  • You won't need Blinka to be a compatibility layer because the libraries are primarily written for CircuitPython
  • CircuitPython has a native display driver called displayio built in, so it makes adding a display super simple
  • It runs on almost 400 boards at this point including the Pico and PicoW, so if you wanted to switch to a different board that has built-in lipo charging, it would be super simple to make the change.
I already have a question (a dumb one, as I am on beginner‘s level, sorry. Goal is eventually to build a sort of mini-weather station): In terms of power supply (with no breakout board), I intend to connect a LiPo 3.7V battery to the pico. Which pins do you recommend to use to supply both the BME280 sensor and the screen, apart from pin38 (3V3OUT)? GRD pins we have plenty, but which 2nd power supply pin would make most sense?
Not a dumb question at all. First, I believe Pin 38 is Ground and Pin 36 is the 3V3 out. You should be able to power both devices off of Pin 36 since it appears they both can be powered by 3V.

User avatar
MakerMelissa
 
Posts: 375
Joined: Wed Jun 05, 2013 2:10 am

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by MakerMelissa »

Also, for powering the Pico, you may want to use something like this if you aren't already: https://www.adafruit.com/product/5612

User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

Many thanks Melissa, these are super valuable comments. Great that you dedicate your time to answer all my questions on this topic. I will check everything out and comment in this forum how I progress.
Again, overall the Adafruit website is well-organized and very informative plus explains everything in detail. Tutorials are great. Keep going in this manner!

User avatar
Zororojo
 
Posts: 8
Joined: Wed Mar 22, 2023 4:27 pm

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by Zororojo »

Hi Melissa,
here are already my first questions: I switched to the KB2040 microcontroller and installed CircuitPython with the respective UF2 file. Everything is ok, as the LED - or rather NEO pixel - blinking code works. When I now follow the tutorial of the BME280 sensor using the I2C interface, I cannot connect the standard SDA and SCL ports (GPIO12 and 13), as these are only available via the QT STEMMA connector which I don't have. I tried it with KB2040 ports D0 and D1 (SDA0 and SCL0) using jumper wires and the breadboard, but when running the code I get a fault message 'ValueError: no device detected on 0x77'. Cables and the BME280 sensor are ok, as they worked with the Raspberry Pico. I wanted to adjust the code to be sure the BME280 sensor gets recognized via the ports D0 and D1, but couldn't do so in Thonny, as the mpy.files are not in UTF-8 format. Any advice what would be the wisest way to continue?
Thanks in advance for your help and Happy Easter!
Zororojo

User avatar
MakerMelissa
 
Posts: 375
Joined: Wed Jun 05, 2013 2:10 am

Re: CircuitPython libraries on MicroPython (Raspberry Pi Pico)

Post by MakerMelissa »

Hi,

Sorry for the delay, I didn't see there was a reply on the topic, but just happened to have it open in a tab. One option is to install CircuitPython (or even Arduino) temporarily just to make sure your wiring is correct. MicroPython likely has a way as well, though, I'm less familiar with it. With I2C, a couple common things that can happen with wiring are the SDA and SCL lines are hooked up backwards or sometimes pull up resistors (maybe something like 1k, though I'm not sure on the value) need to be added. I'm hoping you already got it working in the meantime.

Melissa

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”