Pico Micropython Image

Thank you so much.

Graphics and buttons now working properly on both Explorer and Display. (Strange font choice)

Now I can put pixels on the screen writing lines, empty rectangles and circles routines will be the next project.

These are great add-on boards supporting an excellent and inexpensive new board from Raspberry Pi.

I’ve spent a happy morning ‘playing’ with Pico Explorer and built routines for lines at any angle, outline rectangles and circles, and special characters.
If you are new to graphical programming on Pico Explorer you may find this helps get you started:

# Graphics routines for Pimoroni Pico Explorer
#      and Raspberry Pi Pico
# Tony Goodhew (arduinolink(AT)gmail.com)
# 25 January 2021
import picoexplorer as display
import time
import math
width = display.get_width()
height = display.get_height()
display_buffer = bytearray(width * height * 2)
display.init(display_buffer)

# Set the backlight to 90%
display.set_backlight(0.9)

# Define special 5x8 characters - 8 bytes each - 0...7
# Bytes top to bottom, 5 least significant bits only
smiley = [0x00,0x0A,0x00,0x04,0x11,0x0E,0x00,0x00]
sad = [0x00,0x0A,0x00,0x04,0x00,0x0E,0x11,0x00]
heart = [0,0,0,10,31,14,4,0]
b_heart = [0,10,31,0,0,14,4,0]
up_arrow =[0,4,14,21,4,4,0,0]
down_arrow = [0,4,4,21,14,4,0,0]
bits = [128,64,32,16,8,4,2,1]  # Powers of 2

def mychar(xpos, ypos, pattern):  # Print defined character
    for line in range(8):       # 5x8 characters
        for ii in range(5):     # Low value bits only
            i = ii + 3
            dot = pattern[line] & bits[i]  # Extract bit
            if dot:  # Only print WHITE dots
                display.pixel(xpos+i*2, ypos+line*2)
                display.pixel(xpos+i*2+1, ypos+line*2)
                display.pixel(xpos+i*2, ypos+line*2+1)
                display.pixel(xpos+i*2+1, ypos+line*2+1)

def horiz(l,t,r):  # left, top, right
    n = r-l+1        # Horizontal line
    for i in range(n):
        display.pixel(l + i, t )

def vert(l,t,b):   # left, top, bottom
    n = b-t+1        # Vertical line
    for i in range(n):
        display.pixel(l, t+i)

def box(l,t,r,b):  # left, top, right, bottom
    horiz(l,t,r)   # Empty rectangle
    horiz(l,b,r)
    vert(l,t,b)
    vert(r,t,b)

def line(x,y,xx,yy): # (x,y) to (xx,yy)
    if x > xx:
        t = x  # Swap co-ordinates if necessary
        x = xx
        xx = t
        t = y
        y = yy
        yy = t
    if xx-x == 0:  # Avoid div by zero if vertical
        vert(x,min(y,yy),max(y,yy))
    else:          # Draw line one dot at a time L to R
        n=xx-x+1
        grad = float((yy-y)/(xx-x))  # Calculate gradient
        for i in range(n):
            y3 = y + int(grad * i)
            display.pixel(x+i,y3)  # One dot at a time
            
def ring(cx,cy,rr): # Centre and radius
    display.circle(cx,cy,rr)
    display.set_pen(0,0,0) # background colour
    display.circle(cx,cy,rr-1)
    
def ring2(cx,cy,r):   # Centre (x,y), radius
    for angle in range(0, 90, 2):  # 0 to 90 degrees in 2s
        y3=int(r*math.sin(math.radians(angle)))
        x3=int(r*math.cos(math.radians(angle)))
        display.pixel(cx-x3,cy+y3)  # 4 quadrants
        display.pixel(cx-x3,cy-y3)
        display.pixel(cx+x3,cy+y3)
        display.pixel(cx+x3,cy-y3)

def show(t): # Update display and short pause
    display.update()
    time.sleep(t)

# ===== Main ======
display.set_pen(255,255,0)
line(10,10,100,100)
show(1)
display.set_pen(255,0,255)
line(10,100,100,10)
show(1)
display.set_pen(0,255,255)
box(0,105,100,205)
show(1)
display.set_pen(255,0,0)
ring(160,50,50)
show(1)
display.set_pen(0,0,255)
ring2(160,160,50)
show(1)
display.text("Tony Goodhew", 15, 220, 240,3)  
display.update()
mychar(20, 130, up_arrow)    # Defined characters
mychar(40, 130, smiley)      
mychar(60, 130, heart)
mychar(20, 160, down_arrow)  
mychar(40, 160, sad) 
mychar(60, 160, b_heart)
display.update()
1 Like

Oh wow, I love your wee icons! I hadn’t thought of doing that with the Pixel command.

As much as I like the Pico Display, I hadn’t realised that the Explorer has a larger screen and that could be fun…

Great piece of kit - bigger screen is well worth it. Very glad I bought it. Just need to get more into Micropython - I’ve been using Circuitpython but this appears less user-friendly. It’s difficult to see what you have on the device and I’m not sure how to get a script to execute with power ON.

I think to run scripts at power-on you have to call the file main.py.

It is a bit less friendly than CircuitPython, but I’m hoping that with a surge in interest thanks to the Pico that some changes will happen. I really like being able to manually add/remove files to the storage when CircuitPython shows up as a thumb drive, I’d really like MicroPython to do that too.

You can run Circuitpython on a RPi Pico. Adafruit tell you how here:
Overview | Getting Started with Raspberry Pi Pico and CircuitPython | Adafruit Learning System
I’ll get another Pico and give it a try as there are so many library files already written and tested.
Pico Download (circuitpython.org) This is the UF2 file

I’m in two minds about whether or not to run CircuitPy, I think it’s a little more intuitive but then the official (and Pimoroni!) resources will probably be in MicroPy.

I think I’ll stick with MicroPy for now and see how it goes.

Request withdrawn - found the answer

Thanks for posting these links! I’m the lead on CircuitPython for Adafruit so feel free to mention me when I can help answer questions. I should have Discourse setup to email me in case I forget to check here.

Hi tannewt
Welcome to this side of the pond. We have been in touch many times on the Adafruit forums about CircuitPython matters.
I’ll be putting CP on a Pico as soon as I can get hold of another. They all seem to have disappeared.

Can we please have a pinout for the Pico Explorer Base on the shop page as you have done for the Pico Display.

They have a pinout diagram linked in the product details, is that not what you mean?

Thanks - but Pin31 = GP26 is ADC0 not ADC2.

To which pin is the piezo speaker connected? Is it the socket marked Audio and we connect one from GP0 - GP7 and use that?

Ah you’re right, they’ve accidentally put ADC2 in twice. It would be worth pointing that out to them on twitter or via support@pimoroni.com.

In their example scripts they use the function explorer.set_audio_pin(0), so it seems like you can choose the pin. Like you said, that’s presumably what the Audio socket is for.

I’ve not seen this before. Can you put up a link to the document, please.

It’s in the micropython/examples/pico_explorer/demo.py script in the source of Pimoroni’s firmware. I’m not certain that the demo scripts demonstrate all of the available functions, so I’ve been scraping information out of the other files there.

Thanks. The jumper between GP0 and Audio socket makes a quiet noise in the speaker.

Does your code display text on the Explorer screen in upper case only? That is the case on the pico display. Do you know if there is another parameter in the .text function to display in upper/lower case?

Yes, there are no lower case characters. I think they are saving space. I get:
!"#$%&’()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[ \ ]^_ `{|}’
but the last tips more to the right - single quote right? Not too sure about the font.
The display on the Explorer is a delight - fast and very clear
I’ve managed to get it scrolling text on a sine curve at a reasonable rate. I’ll put the code up shortly, once I’ve finished checking it.
Probably not a good idea to run too bright. There appeared to be screen burn when I tried to photograph after running for some time.
Have you tried a pot on an ADC? Mine not getting properly to zero. Had to adjust with code.
Have fun

Fingers crossed that the PICO’s are still in stock when I order some stuff early next month. I really want to get in on the fun. =)
Leaning towards also getting a Pico Breakout Garden Base if they are in stock. I already have several Breakout Garden Breakouts on hand.