Pico Display V1/V2 WiFi demo (any chance)

Hi is there any chance that someone could put together a Pico Display V1/V2 WiFi demo?
I am thinking that the demo could show the IP address of the pico and maybe the time.
Thanks
Andrew

PS I’ve just installed pimoroni-pico-v1.19.3-micropython.uf2 only to find that my old modified version of the balls demo no longer works :(

PPS The new version modified just fine. My mod reduces the maximum size of the balls so you can see more deflections from the sides.

This my version of the Balls Demo that is working with 1.19.3 on my V1 Display Pack. I just flashed that Pico with 1.19.3, no modifications were needed to that file. Not sure if it was running 1.19.1 or 1.19.2? No WIFI on this Pico.

import time
import random
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8

display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P8)
display.set_backlight(1.0)

WIDTH, HEIGHT = display.get_bounds()

# We're creating 100 balls with their own individual colour and 1 BG colour
# for a total of 101 colours, which will all fit in the custom 256 entry palette!


class Ball:
    def __init__(self, x, y, r, dx, dy, pen):
        self.x = x
        self.y = y
        self.r = r
        self.dx = dx
        self.dy = dy
        self.pen = pen


# initialise shapes
balls = []
for i in range(0, 100):
    r = random.randint(0, 10) + 3
    balls.append(
        Ball(
            random.randint(r, r + (WIDTH - 2 * r)),
            random.randint(r, r + (HEIGHT - 2 * r)),
            r,
            (14 - r) / 2,
            (14 - r) / 2,
            display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
        )
    )

BG = display.create_pen(40, 40, 40)

while True:
    display.set_pen(BG)
    display.clear()

    for ball in balls:
        ball.x += ball.dx
        ball.y += ball.dy

        xmax = WIDTH - ball.r
        xmin = ball.r
        ymax = HEIGHT - ball.r
        ymin = ball.r

        if ball.x < xmin or ball.x > xmax:
            ball.dx *= -1

        if ball.y < ymin or ball.y > ymax:
            ball.dy *= -1

        display.set_pen(ball.pen)
        display.circle(int(ball.x), int(ball.y), int(ball.r))

    display.update()
    time.sleep(0.01)

I can help the the date and time and look forward to the IP address from someone else.

# Date and Time from Google.com display on Pico Display V1
# Tony Goodhew 23 July 2022
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P4

# We're only using a few colours so we can use a 4 bit/16 colour palette and save RAM!
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P4, rotate=0)

display.set_backlight(0.5)
display.set_font("bitmap8")
WIDTH, HEIGHT = display.get_bounds()

RED = display.create_pen(255,0,0)
BLACK = display.create_pen(0,0,0)
WHITE = display.create_pen(255,255,255)
YELLOW = display.create_pen(255,255,0)
display.set_pen(BLACK)
display.clear()
display.set_pen(RED)

#display.text(text, x, y, wordwrap, scale, angle, spacing)
display.text("From Google.com", 0,0,135, 2, 90, 2)
display.update()
# Connect to network
import network
from secret import ssid,password
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password) 
# Make GET request
import urequests
r = urequests.get("http://www.google.com")
print(r.content+'\n\n')
r.close
r = urequests.get("http://date.jsontest.com")
print("\nTime from 'http://date.jsontest.com'\n")
s = str(r.json())
print(s)
p = s.find("date")   # Find date
#print(p)
datestr = s[p+8:p+18]
print(datestr)

p = s.find("time")   # Find time
#print(p)
timestr = s[p+8:p+17]
print(timestr)
display.set_pen(YELLOW)
display.text("Date: "+datestr, 0,25,135, 2, 90, 3)
display.set_pen(YELLOW)
display.text("Time: "+timestr, 0,70,135, 2, 90, 3)
display.update()
r.close()

I’ve left in some of the testing and help lines.

Have fun.

Final, corrected version, is here:

# Date and Time from jsontest.com display on Pico Display V1
# Tony Goodhew 24th July 2022
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P4
import urequests

# We're only using a few colours so we can use a 4 bit/16 colour palette and save RAM!
display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P4, rotate=0)

display.set_backlight(0.5)
display.set_font("bitmap8")
WIDTH, HEIGHT = display.get_bounds()

RED = display.create_pen(255,0,0)
BLACK = display.create_pen(0,0,0)
WHITE = display.create_pen(255,255,255)
YELLOW = display.create_pen(255,255,0)
GREEN = display.create_pen(0,255,0)
display.set_pen(GREEN)

display.set_pen(BLACK)
display.clear()
display.set_pen(RED)

# Connect to network
import network
from secret import ssid,password
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)

# Handle connection error
if wlan.status() != 3:
    raise RuntimeError('network connection failed')
else:
    print('connected')
    status = wlan.ifconfig()
    print( 'IP = ' + status[0] )


display.set_pen(GREEN)
display.text('IP = ' + status[0], 0,0,135, 2, 90, 3)
display.update()
display.set_pen(RED)
display.text("date.jsontest.com", 0,25,135, 2, 90, 2)
display.update()

# Make GET request
r = urequests.get("http://date.jsontest.com")
print("\nTime from 'http://date.jsontest.com'\n")
s = str(r.json())
# Get date
p = s.find("date") 
datestr = s[p+8:p+18]
# Get time
p = s.find("time") 
timestr = s[p+8:p+17]

display.set_pen(YELLOW)
display.text("Date: "+datestr, 0,50,135, 2, 90, 3)
display.set_pen(YELLOW)
display.text("Time: "+timestr, 0,95,135, 2, 90, 3)
display.update()
r.close()

I hope that answers your question.

1 Like

I did a #cheerlights example for Pico Explorer that should be easy to adapt to Display Pack, if that’s any use?

1 Like

Awesome CheerLights demo!

1 Like