Circuitpython on RPi 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
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Circuitpython on RPi Pico

Post by ray_leiter »

I have some Rpi Picos which I was hoping to program using Circuitpython (as opposed to Micropython, which appears to be easy to implement).
I'm not really clear on this topic but I am getting the idea, from my readings, that what I want to do REQUIRES something called "Blinka"?
I thought all I had to do was install Circuitpython on the Pico similar to what I did on some other MCUs I have (I believe I did the install using an Arduino UNO)?
I'm sur somewhere on the Adafruit site there is an excellent article telling how to turn a Pico into a Circuitpython machine regardless of whether the Pico is factory fresh or has gone through many other installs of various other products for other programming environments (I'm thinking of the Pico being used to program in C under the Arduino IDE).

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Circuitpython on RPi Pico

Post by jerryn »


User avatar
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Re: Circuitpython on RPi Pico

Post by ray_leiter »

Yes, jerryn, I did find the guide you're suggesting.
I had a little trouble understanding exactly what I should and should not do -- the guide seems to be a compilation of instructions dealing with more than 1 board.
I'll go back to it and see if I can make more sense of it now.
Thanks

User avatar
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Re: Circuitpython on RPi Pico

Post by ray_leiter »

Thanks for the mention of the "getting started" guide. I was able to follow it and get CircuitPython 7 installed on my Pico.
I actually had done it before, but I seemed to have forgotten it all or it was the result of me working with too many various boards and languages and operating systems(Arduino UNO, ESP32 & Pico; Python & C++; Windows 10 & Ubuntu).

I'm finding it more difficult to keep my wits about me as I get older.

Here is what I am currently trying to accomplish -- some guidance would be appreciated:
I want to use CircuitPython 7 on my Pico to program 2 mono OLEDs: one is a SH1106 based display and the other is a SSD1306 based display. BOTH displaya has the typical 4 pin interface(Vcc, Gnd, SCL. SDA).
It seems to me I should be able to use the same program on BOTH displays (provided I use only those functions supported by BOTH drivers) and do it by essentially changing only the library and whatever display object declaration I need to create an instance of the display.
Lately, I've been scouring the net looking for examples of what I'm trying to do. It's unbelievable what's out there!
I think I'll start with the SSD1306 based display first since it seems to be the most popular.
I'm thinking I should be able to accomplish that task by going with Adafruit first?
Thanks for any help.
Ray

User avatar
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Re: Circuitpython on RPi Pico

Post by ray_leiter »

jerryn wrote:Have you looked at this guide? https://learn.adafruit.com/getting-star ... cuitpython
jerryn;
I was a little disappointed in Kattni's "getting started guide...". The title suggests it's about the Pico, but there is quite a few mentions of other boards (e.g. "Here is the output for the QT Py.").
For a document purporting to be about the Pico, I would expect ALL examples to be about the Pico.
This document will do 2 things for you: 1. help you get CircuitPython installed on your Pico, and, 2. show you the basic uses of the pins on the Pico for things like LEDs and some other peripherals.

What I am still searching for and am not finding is a good explanation of using the Pico with CircuitPython to drive OLEDs based on SH1106 and SSD1306 driver chips using I2C. I'm especially interested in the SH1106 driver.
There seem to be plenty of articles about the SSD1306 but many of them use SPI instead of I2C and quite a few use MicroPython instead of CircuitPython.
I did find an article online by a guy from Brazil (Nicolau dos Brinquedos) and I exchanged emails with him. His article worked at the time he published it but now it doesn't work and he doesn't know why. When you run his code you get the REPL on the OLED -- not what the code is trying to display.
This experience is so typical of what happens when one gets information from the web -- it's almost always out of date and either doesn't work at all or only partially works.
I suppose I'll keep looking for something using CircuitPython on the Pico to drive an OLED via I2C (BOTH SSD1306 AND SH1106).

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Circuitpython on RPi Pico

Post by adafruit_support_carter »

Once the firmware is installed, things largely become board agnostic. Specific pin usage is a good example of an exception. That's why you'll see a lot of cross referencing and mention of other boards.

You'll want to become familiar with displayio, so checkout this guide:
https://learn.adafruit.com/circuitpytho ... -displayio

There's a CP library for SH1106 here:
https://github.com/adafruit/Adafruit_Ci ... yIO_SH1106

There's a CP library for SSD1306 here:
https://github.com/adafruit/Adafruit_Ci ... IO_SSD1306

If you are using Adafruit displays based on those drivers, then the product guides for those should show basic CP usage examples. For non-Adafruit displays, you can use the libraries as a reference.

User avatar
danhalbert
 
Posts: 4654
Joined: Tue Aug 08, 2017 12:37 pm

Re: Circuitpython on RPi Pico

Post by danhalbert »

I was a little disappointed in Kattni's "getting started guide...". The title suggests it's about the Pico, but there is quite a few mentions of other boards (e.g. "Here is the output for the QT Py.").
The guide pages are shared among multiple guides. Otherwise updating them all individually is a maintenance nightmare. We have some ways of customizing and templating them, but they are written in a general way when that's not possible

User avatar
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Re: Circuitpython on RPi Pico

Post by ray_leiter »

adafruit_support_carter wrote:Once the firmware is installed, things largely become board agnostic. Specific pin usage is a good example of an exception. That's why you'll see a lot of cross referencing and mention of other boards.

You'll want to become familiar with displayio, so checkout this guide:
https://learn.adafruit.com/circuitpytho ... -displayio

There's a CP library for SH1106 here:
https://github.com/adafruit/Adafruit_Ci ... yIO_SH1106

There's a CP library for SSD1306 here:
https://github.com/adafruit/Adafruit_Ci ... IO_SSD1306

If you are using Adafruit displays based on those drivers, then the product guides for those should show basic CP usage examples. For non-Adafruit displays, you can use the libraries as a reference.
adafruit_support_carter;
Thank you for your reply. Unfortunately, none of what you suggested actually helps me accomplish my goal of driving a SSD1306 OLED from a Pico using CircuitPython 7.
For example;
-- Your reference to displayio -- the basic usage example has "display_bus = displayio.I2CDisplay(board.I2C(),device_address=0x3D)"
Since it has "board.I2C()", I don't think it is for a PICO. (NO board.I2C())
-- Your reference to SH1106 library -- Usage example "simpletest.py" is for SPI -- NOT I2C
-- Your reference to SSD1306 library -- Usage example "simpletest.py" is for SPI -- NOT I2C AND the same holds for "featherwing.py"
-- Your reference to Adafruit displays -- I bought Product #326 and sure enough, the example is using "i2c = board.I2C()", which will NOT work on a Pico.

I appreciate the help folks are trying to give me but what I would like is quite simple. I need a sample CP program that is for the displays I have, even the one I bought from Adafruit (Product #326) which will work on a Pico.
If there is NO CP version 7 program that will work on any of my displays running on a Pico, then I would like for someone to simply admit that fact and I can move on.
Do you actually know of a CP version 7 program to drive an OLED based on either SH1106 or SSD1306 that runs on a Pico?
I'm beginning to think I have happened upon that unique combination of pieces that don't play together.
Thanks for you assistance thus far.
Ray

User avatar
danhalbert
 
Posts: 4654
Joined: Tue Aug 08, 2017 12:37 pm

Re: Circuitpython on RPi Pico

Post by danhalbert »

`i2c = board.I2C()` doesn't work on Pico only because there are no default I2C pins (or more precisely, there are multiple ideas of what the defaults are, so we didn't choose one). `board.I2C()` is just `busio.I2C()` with some default pins.

You can just create your own bus with appropriate pins, picked from the diagram here: https://learn.adafruit.com/getting-star ... on/pinouts. The reason for the lack of `board.I2C()` is explained on that page. Here's an example of using `busio.I2C()`:

Code: Select all

import busio

i2c = busio.I2C(scl=board.GP1, sda=board.GP0)   # you don't have to use keywords args
For SSD1306, https://github.com/adafruit/Adafruit_Ci ... herwing.py can be altered slightly to use `busio.I2C(...)` per above.

What display breakout are you using that has an SH1106 display with I2C? (and is I2C only?)

User avatar
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Re: Circuitpython on RPi Pico

Post by ray_leiter »

danhalbert wrote:
I was a little disappointed in Kattni's "getting started guide...". The title suggests it's about the Pico, but there is quite a few mentions of other boards (e.g. "Here is the output for the QT Py.").
The guide pages are shared among multiple guides. Otherwise updating them all individually is a maintenance nightmare. We have some ways of customizing and templating them, but they are written in a general way when that's not possible
Dan;
I suspected as much.
I recognize it's a journey and I'm at the beginning, so I'll keep struggling until I get as far as I'd like.
Thus far I've found that if one reads enough and asks enough questions, the fog begins to lift.
Thanks for your help, Dan.
Ray

User avatar
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Re: Circuitpython on RPi Pico

Post by ray_leiter »

danhalbert wrote:`i2c = board.I2C()` doesn't work on Pico only because there are no default I2C pins (or more precisely, there are multiple ideas of what the defaults are, so we didn't choose one). `board.I2C()` is just `busio.I2C()` with some default pins.

You can just create your own bus with appropriate pins, picked from the diagram here: https://learn.adafruit.com/getting-star ... on/pinouts. The reason for the lack of `board.I2C()` is explained on that page. Here's an example of using `busio.I2C()`:

Code: Select all

import busio

i2c = busio.I2C(scl=board.GP1, sda=board.GP0)   # you don't have to use keywords args
For SSD1306, https://github.com/adafruit/Adafruit_Ci ... herwing.py can be altered slightly to use `busio.I2C(...)` per above.

What display breakout are you using that has an SH1106 display with I2C? (and is I2C only?)
Dan;
Thank you very much for your help.
I was able to understand what you are telling me and I was able to use the code you referenced with the mods you pointed out on, my Pico with a 0.96 inch mono SSD1306 based OLED and it worked (I chose GP16, GP17 for SDA and SCL respectively).
I think you may have also helped me see why the code from the guy in Brazil (Nicolau dos Brinquedos) did not work -- I believe it is because he didn't have the "displayio.release_displays()" statement -- his output was the REPL, NOT what he was trying to display.
I'll check it out further and then contact him about it so he can update his online article.
To answer you question about my OLEDs:
"What display breakout are you using that has an SH1106 display with I2C? (and is I2C only?)"
My display with the SH1106 chip is marked on the back in the silkscreen as follows: "1.3 inch OLED IIC".
I see no way to use any other interface with it.
I am taking an online course from "https://randomnerdtutorials.com/projects" to learn the ESP32 and the course suggested I purchase a 0.96 inch mono OLED from Banggood (it was NOT mentioned which chip was driving the display).
Banggood advertised the OLED as "Geekcreit® 0.96 Inch OLED I2C IIC Communication Display 128*64 LCD Module", BUT I received a 1.3 inch mono SH1106 based OLED. As you can imagine, I struggled mightily with the fact that my OLED would not work for my course and the course authors had sympathy but no solutions. I discovered the driver chip mix up with much internet searching.
At the time I was trying to use this Banggood display with my course, I had no idea about different driver chips being used.
I finally made it work with an Arduino UNO library I got from Github (U8glib).
I have learned way more than I bargained for when I signed up for the ESP32 course.
Thanks again Dan;
Ray

User avatar
ray_leiter
 
Posts: 49
Joined: Wed Mar 16, 2016 9:09 pm

Re: Circuitpython on RPi Pico

Post by ray_leiter »

Dan;
Just a final note regarding my efforts to get the OLEDs I have working with CP 7 on the Pico.
I was able to get the Adafruit OLED(SSD1306) (prod #326) to work using the example code you pointed me to (I had to change the I2C address from 0x3C to 0x3D).
I was also able to get the 0.96 mono OLED(SSD1306) I bought from some internet source (from China) to work with the example code (I2C address 0x3C).
And here is the kicker -- I was able to get the mis-advertised OLED from Banggood to work as well (it's 1.3 inch mono SSH1106, I2C address 0x3C).
Here's the problem with the 1.3 inch OLED. When I first tried to run it, I forgot to change everything necessary so it displayed what looked like lots of SNOW. Then I changed all that was necessary and it ALMOST looked OK -- there was some "BANNED-ola" on the extreme right side of the display so I changed the width to 130 and it went away. Then I changed the width back to 128 and it worked OK.
The real way to clear the screen is to use the appropriate function, but I don't know what it is in CP -- only in C using U8glib.
Anyway, thanks again for your help -- I am now sufficiently encouraged to be able to proceed with confidence that I can figure out most of what I need to make these various OLEDs work on the various boards I have.
Ray

User avatar
danhalbert
 
Posts: 4654
Joined: Tue Aug 08, 2017 12:37 pm

Re: Circuitpython on RPi Pico

Post by danhalbert »

Glad you got it working!

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

Return to “Adafruit CircuitPython”