I have a Pico 2 with two Display Pack V2.8’s. Also in use are various sensors.
RV3028
BME680
BME280
VEML6075
LTR-599
It’s a weather station build that displays the sensor info on the displays. Custom wired so I can use the two Display packs independently and simultaneously.
The following wall of code works fine when run from Thonny. Both displays display correctly. But it doesn’t run correctly when saved to the Pico as main.py. The second “R” right display doesn’t display anything. The file is running, I can see the time increment on the working “L” left display. But nothing ever shows on the right display. This did work on boot up with a Pico (RP2040), that was my original setup. I didn’t have all the sensors wired up then, just the BME680 for indoor info. Once I added the BME280 and light sensors, the RP2040 wasn’t up to the task. It just froze. I then swapped in the RP2350 and my code would run. All was good until i tried to run it stand alone from boot up.
# MicroPython feature/psram, pico2_rp2350 v0.0.5 on 2024-08-22; Raspberry Pi Pico with RP2350
# Display Left, Pico Display Pack v2.8
# Display Right, Pico Display Pack v2.8
import time
import pimoroni_bus
import picographics
import veml6075
#import breakout_icp10125
from machine import ADC, Pin
#from pimoroni import Button
#from pimoroni import RGBLED
from pimoroni_i2c import PimoroniI2C
from breakout_ltr559 import BreakoutLTR559
from breakout_bme280 import BreakoutBME280
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
from breakout_rtc import BreakoutRTC
from machine import RTC
i2c = PimoroniI2C(sda=(0), scl=(1))
bme_out = BreakoutBME280(i2c, 0x76)
bme_in = BreakoutBME68X(i2c, 0x77)
ltr = BreakoutLTR559(i2c)
uv = veml6075.VEML6075(i2c)
connected = uv.initUV()
#icp10125 = breakout_icp10125.BreakoutICP10125(i2c)
RV3028 = BreakoutRTC(i2c)
rtc = BreakoutRTC(i2c)
if rtc.is_12_hour:
rtc.set_24_hour()
from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY_2, get_buffer_size, PEN_RGB332
buffer = bytearray(get_buffer_size(DISPLAY_PICO_DISPLAY_2, PEN_RGB332))
from pimoroni_bus import SPIBus
spibus_R = SPIBus(cs=17, dc=16, sck=18, mosi=19, bl=20)
spibus_L = SPIBus(cs=22, dc=16, sck=18, mosi=19, bl=21)
display_R = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, rotate=90, buffer = buffer, bus=spibus_R, pen_type=PEN_RGB332)
display_L = PicoGraphics(display=DISPLAY_PICO_DISPLAY_2, rotate=90, buffer = buffer, bus=spibus_L, pen_type=PEN_RGB332)
display_R.set_font("bitmap8")
display_L.set_font("bitmap8")
display_R.set_backlight(0.5)
display_L.set_backlight(0.5)
def colour(R,G,B): # Convert RGB888 to RGB332
b = int(B/64)
g = int(G/32)
r = int(R/64)
return b + g * 4 +r * 64
white = colour(224,224,224)
black = colour(0,0,0)
red = colour(255,0,0)
green = colour(0,255,0)
blue = colour(0,0,255)
yellow = colour(255,255,0)
orange = colour(255,140,0)
grey = colour(175,175,175)
violet = colour(255,0,255)
aqua = colour(255,0,255)
display_R.set_pen(black)
display_R.clear()
display_L.set_pen(black)
display_L.clear()
def describe_month(month):
month = rtc.get_month()
if month == 1:
description = "Jan"
elif month == 2:
description = "Feb"
elif month == 3:
description = "Mar"
elif month == 4:
description = "Apr"
elif month == 5:
description = "May"
elif month == 6:
description = "Jun"
elif month == 7:
description = "Jul"
elif month == 8:
description = "Aug"
elif month == 9:
description = "Sep"
elif month == 10:
description = "Oct"
elif month == 11:
description = "Nov"
elif month == 12:
description = "Dec"
return description
def describe_date(date):
date = rtc.get_date()
if date == 1:
description = "st"
elif date == 2:
description = "nd"
elif date == 3:
description = "rd"
elif date == 21:
description = "st"
elif date == 22:
description = "nd"
elif date == 23:
description = "rd"
elif date == 31:
description = "st"
else:
description = "th"
return description
temp_out, press_out, hum_out = bme_out.read()
temp_in, press_in, hum_in, gas, status, _, _ = bme_in.read()
time.sleep(0.3)
temp_out, press_out, hum_out = bme_out.read()
temp_in, press_in, hum_in, gas, status, _, _ = bme_in.read()
time.sleep(0.3)
temp_out, press_out, hum_out = bme_out.read()
temp_in, press_in, hum_in, gas, status, _, _ = bme_in.read()
time.sleep(0.3)
if rtc.read_periodic_update_interrupt_flag():
rtc.clear_periodic_update_interrupt_flag()
if rtc.update_time():
rtc_date = rtc.string_date()
rtc_time = rtc.string_time()
while True:
hour = rtc.get_hours()
minute = rtc.get_minutes()
month = rtc.get_month()
date = rtc.get_date()
if rtc.read_periodic_update_interrupt_flag():
rtc.clear_periodic_update_interrupt_flag()
if rtc.update_time():
rtc_date = rtc.string_date()
rtc_time = rtc.string_time()
display_L.set_pen(black)
display_L.clear()
display_L.set_pen(white)
display_L.text(f"{describe_month(month)} {date}{describe_date(date)}",125,0,scale=3)
if hour == 0:
display_L.text(f"{12}:{minute:02} AM", 0, 0, scale=3)
elif 0 < hour < 10:
display_L.text(f"{hour:1}:{minute:02} AM", 0, 0, scale=3)
elif 10 <= hour < 12:
display_L.text(f"{hour:2}:{minute:02} AM", 0, 0, scale=3)
elif hour == 12:
display_L.text(f"{hour:2}:{minute:02} PM", 0, 0, scale=3)
elif hour > 12:
hour = hour - 12
if hour < 10:
display_L.text(f"{hour:1}:{minute:02} PM", 15, 0, scale=3)
elif 10 <= hour < 12:
display_L.text(f"{hour:2}:{minute:02} PM", 0, 0, scale=3)
elif hour == 12:
display_L.text(f"{hour:2}:{minute:02} AM", 0, 0, scale=3)
temp_out, press_out, hum_out = bme_out.read()
temp_in, press_in, hum_in, gas, status, _, _ = bme_in.read()
heater = "Stable" if status & STATUS_HEATER_STABLE else "Unstable"
pressuremb = press_in / 100
display_L.set_pen(aqua)
display_L.text("Indoor", 10, 35, scale = 3)
display_L.text("Outdoor", 125, 35, scale = 3)
temp_in = round(temp_in)
if temp_in < 0:
display_L.set_pen(white)
elif 0 <= temp_in < 12:
display_L.set_pen(blue)
elif 12 <= temp_in < 17:
display_L.set_pen(yellow)
elif 17 <= temp_in < 25:
display_L.set_pen(green)
elif 25 <= temp_in < 30:
display_L.set_pen(orange)
elif temp_in >= 30:
display_L.set_pen(red)
display_L.text('{:.0f}°C'.format(temp_in), 20, 70, scale = 4)
temp_out = round(temp_out)
if temp_out < 0:
display_L.set_pen(white)
elif 0 <= temp_out < 12:
display_L.set_pen(blue)
elif 12 <= temp_out < 17:
display_L.set_pen(yellow)
elif 17 <= temp_out < 25:
display_L.set_pen(green)
elif 25 <= temp_out < 30:
display_L.set_pen(orange)
elif temp_out >= 30:
display_L.set_pen(red)
display_L.text('{:.0f}°C'.format(temp_out), 140, 70, scale = 4)
hum_in = round(hum_in)
if hum_in < 30:
display_L.set_pen(red)
elif 30 <= hum_in < 61:
display_L.set_pen(green)
elif 61 <= hum_in < 81:
display_L.set_pen(yellow)
elif hum_in >= 81:
display_L.set_pen(orange)
display_L.text('{:.0f}%'.format(hum_in), 20, 115, scale = 4)
hum_out = round(hum_out)
if hum_out < 30:
display_L.set_pen(red)
elif 30 <= hum_out < 61:
display_L.set_pen(green)
elif 61 <= hum_out < 81:
display_L.set_pen(yellow)
elif hum_out >= 81:
display_L.set_pen(orange)
display_L.text('{:.0f}%'.format(hum_out), 140, 115, scale = 4)
'''
t, p, status = icp10125.measure(icp10125.NORMAL)
if status == icp10125.STATUS_OK:
icptemp = t
icppress = p / 100
#print('ICP Pressure {:05.2f}mb'.format(icppress))
'''
pressuremb = round(pressuremb)
if pressuremb < 982:
display_L.set_pen(red)
display_L.text('{:.0f}mb'.format(pressuremb), 60, 160, scale = 4)
display_L.text("Very Low", 30, 205, scale = 4)
elif 982 <= pressuremb < 1004:
display_L.set_pen(yellow)
display_L.text('{:.0f}mb'.format(pressuremb), 60, 160, scale = 4)
display_L.text("Low", 80, 205, scale = 4)
elif 1004 <= pressuremb < 1026:
display_L.set_pen(green)
display_L.text('{:.0f}mb'.format(pressuremb), 55, 160, scale = 4)
display_L.text("Unsettled", 30, 205, scale = 4)
elif 1026 <= pressuremb < 1048:
display_L.set_pen(blue)
display_L.text('{:.0f}mb'.format(pressuremb), 50, 160, scale = 4)
display_L.text("High", 35, 205, scale = 4)
elif pressuremb >= 1048:
display_L.set_pen(orange)
display_L.text('{:.0f}mb'.format(pressuremb), 50, 160, scale = 4)
display_L.text("Very High", 20, 205, scale = 4)
display_L.update()
display_L.set_pen(black)
display_L.clear()
display_R.set_pen(black)
display_R.clear()
display_R.set_pen(white)
display_R.text("Outside Light", 15, 0, scale = 3)
display_R.text("Rain Fall", 40, 80, scale = 3)
display_R.text("Wind", 65, 160, scale = 3)
reading = ltr.get_reading()
if reading is not None:
light = reading[BreakoutLTR559.LUX]
if light < 50:
display_R.set_pen(grey)
display_R.text("Dark", 20, 35, scale = 4)
elif 50 <= light < 100:
display_R.set_pen(orange)
display_R.text("Dim", 40, 35, scale = 4)
elif 100 <= light < 500:
display_R.set_pen(yellow)
display_R.text("Light", 0, 35, scale = 4)
elif light >= 500:
display_R.set_pen(blue)
display_R.text("Bright", 0, 35, scale = 4)
UVI, UVIA, UVIB = uv.readUV()
u = UVI
if UVI >= 0 and UVI < 3:
display_R.set_pen(green)
display_R.text('UV:{:.0f}'.format(UVI), 145, 35, scale = 4)
elif UVI >= 3 and UVI < 6:
display_R.set_pen(yellow)
display_R.text('UV:{:.0f}'.format(UVI), 145, 35, scale = 4)
elif UVI >= 6 and UVI < 8:
display_R.set_pen(orange)
display_R.text('UV:{:.0f}'.format(UVI), 145, 35, scale = 4)
elif UVI >= 8 and UVI < 11:
display_R.set_pen(red)
display_R.text('UV:{:.0f}'.format(UVI), 145, 35, scale = 4)
elif UVI >= 11:
display_R.set_pen(violet)
display_R.text('UV:{:.0f}'.format(UVI), 145, 35, scale = 4)
display_R.set_pen(green)
display_R.text("10" + 'mm', 0, 115, scale = 4)
display_R.text("2" + 'mm/h', 110, 115, scale = 4)
display_R.set_pen(green)
display_R.text("NE @", 0, 195, scale = 4)
display_R.text("22 kmh", 110, 195 , scale = 4)
display_R.text("Gusting 25", 20, 240, scale = 4)
display_R.update()
display_R.set_pen(black)
display_R.clear()
time.sleep(1.0)