Skip to content

Version 1.18.8 - Beta Bonanza

Pre-release
Pre-release
Compare
Choose a tag to compare
@Gadgetoid Gadgetoid released this 18 May 13:05
· 1383 commits to main since this release
db60553

Beta Bonanza

⚠️ This release has some spicy changes that you might not want to be dealing with right now. If you're looking for your code to keep ticking along as usual then please grab v1.18.7. If you want to help find all the ways in which I've broken our MicroPython build... please give this release a go!

Unified ST7789 Display Driver

We were wasting a lot of precious bytes duplicating code for our display products. Indeed Pico Display, Pico Display 2.0, 240x240 1.3" SPI LCD and the 240x240 round SPI LCD were all using the same ST7789 driver under the hood and we'd reinvented how to read a pin (Pico Display's buttons) in an effort to keep things simple and self contained.

As a consequence I have replaced all of the libraries for these display products with just ST7789 which accepts a width and height corresponding to the product you want to use. This hides the bytearray buffer wart we needed to avoid display buffers being eaten by MicroPython's GC.

This means you can now do really cool stuff like driving two Pico Display 2.0 boards from one Pico.

ST7789 discards the LED and Button functionality. With Pico Zero, MicroPython's own machine.Pin and our Button and RGBLED libraries on the scene, we really didn't need yet another way to drive RGB LEDs and buttons.

Dropping four libraries in favour of one helps slim down our batteries-included MicroPython build so we can continue to add functionality. It does- however- mean you'll need to make some changes to your code.

Code that once looked like:

import picodisplay as display

width = display.get_width()
height = display.get_height()

display_buffer = bytearray(width * height * 2)
display.init(display_buffer)

Should now look like:

import st7789

WIDTH = 240
HEIGHT = 135

display = st7789.ST7789(WIDTH, HEIGHT, rotate180=False)

And if you want a portrait display you can just swap the width/height like so:

import st7789

WIDTH = 135
HEIGHT = 240

display = st7789.ST7789(WIDTH, HEIGHT, rotate180=False)

For buttons you can use Pico Zero, or our baked-in button library. Our Button library supports auto-repeat if you need it.

Here's how to set up the Pico Display and Pico Display 2.0" buttons:

from pimoroni import Button
button_a = Button(12)
button_b = Button(13)
button_x = Button(14)
button_y = Button(15)

And the RGB LED:

from pimoroni import RGBLED
led = RGBLED(6, 7, 8)

ℹ️ The 160x80 colour LCD uses the ST7735 driver under the hood and the way you use it has not changed!

Pimoroni I2C vs machine.I2C

It's been bugging me for a while, but it wasn't until @alphanumeric007 raised #359 that it truly dawned upon me how our Pimoroni I2C object feels like a dose of not-invented-here syndrome. It's not. It exists because we needed a standard set of I2C functions for our C++ libraries, and it works well for this. However MicroPython already has a standard set of I2C functions, so wrapping our C++ libraries up for it resulted in this ugly wart of a... weird third party I2C library. There was no real reason not to sweep this under the rug as an implementation detail; so I have.

I2C has now changed in two ways:

  1. PimoroniI2C is a weird superset of machine.I2C and will work fine as a drop-in replacement if you want to keep using it
  2. machine.I2C instances will now be accepted by all of our MicroPython I2C-based sensor libraries, and quietly promoted to PimoroniI2C behind the scenes

This means that, should you wish to, you can now do this:

sda = machine.Pin(4)
scl = machine.Pin(5)
i2c = machine.I2C(0, sda=sda, scl=scl, freq=400_000)
bme280 = BreakoutBME280(i2c)

And machine.I2C and PimoroniI2C are equivalent:

>>> import pimoroni_i2c
>>> i2c = pimoroni_i2c.PimoroniI2C(4, 5)
>>> dir(i2c)
['__class__', 'readinto', 'start', 'stop', 'write', 'init', 'readfrom', 'readfrom_into', 'readfrom_mem', 'readfrom_mem_into', 'scan', 'writeto', 'writeto_mem', 'writevto']
>>> import machine
>>> i2c = machine.I2C(0, sda=machine.Pin(4), scl=machine.Pin(5))
>>> dir(i2c)
['__class__', 'readinto', 'start', 'stop', 'write', 'init', 'readfrom', 'readfrom_into', 'readfrom_mem', 'readfrom_mem_into', 'scan', 'writeto', 'writeto_mem', 'writevto']

Your existing scripts should continue to work, and you should generally continue to use PimoroniI2C since it avoids some extra overhead when used with our libraries. However you can now share one single I2C object (whichever it might be) with both Pimoroni baked-in libraries and any third-party MicroPython libraries you might want to use!

What's Changed

Full Changelog: v1.18.7...v1.18.8