Pseudo 7-Segment Display on a 128×64 pixel OLED

Downloads appear at the end of this post.

Graphic image of a display device showing large and small numbers.
128×64 Pixel OLED showing the time on a simulated 7-segment display.

I’ve mentioned in a previous post that I’ve started to use MicroBlocks (https://microblocks.fun/) to write programs for the Raspberry Pi Pico. It comes with an OLED extension library which allows text and numbers to be written to the screen. The commands control the simple 128×64 I2C displays, which can be easily connected to Pins 4 and 5 on the Raspberry Pi Pico.

One thing that I noticed, however, is that the size of the standard text is really a bit small for my eyes now, so I wanted to see if I could write a small set of functions that would change the size of digits on screen, by simulating a 7-segment display.

I remembered that a 7-segment display starts with a simple diagram that names each segment with a letter. In the standard layout, segment “a” is at the top, and then the segments clockwise from here are “b” through to “f”, with the central segment being “g”. In order to store this using MicroBlocks, I needed a list.

It took me a little while to get my head around this. Digit 0 needs all of the segments except the central one. Digit 1 needs segments “b” and “c”. In MicroBlocks however, the lists start at item 1, which meant that I had to remember to take account of this later.

The next step was to create a function that looked that the digit required, decide which segments are turned-on or turned-off and draw these as rectangles on the screen using the OLED library commands. If there is an “a” in the SegmentList, then it is drawn on the OLED pixels, and if not, it is erased. I defer updating the OLED pixels until all of the segments have been drawn so that there is no flicker.

Part of the routine for drawing the segments

Once I had the main functions written, it’s a relatively simple task to use them to show large digits on the screen. I had to use modulo and division mathematical functions to separate out the units, tens and hundreds, and then shift the XPosition of each segment before display.

Downloads

There are two MicroBlocks programs ready to download:

Counting to 999 on an OLED display (7SegmentDisplay.ubp)

Real-time clock and large simulated display (LargeDisplayClock.ubp)

Advertisement

Pin Connections on the interface board

I wanted to create a board that offered as many different connections as possible. I like to create small robot models and it was really important to offer connections for H-bridges, stepper motors and a whole collection of servos. Sensors are either analogue or digital, and most of them require some sort of power connection.

As a result of all of these decisions, I’ve decided to make the connections based on the pattern set by servo connectors. On these, the centre connection is the positive (+V or Vcc) power supply, one connection is Ground (Gnd) and the final connection is the control signal. On this board, all of the connections face towards the Raspberry Pi Pico.

The pin allocations are based on those given for Microblocks running on the Raspberry Pi Pico at: https://wiki.microblocks.fun/boards/special_pins

Connection diagram for the Raspberry Pi Pico Interface Board
External Pins (Some pins can suit a variety of functions).Used For:
Pins 0-22Digital I/O only (2,3,6,7,8,9 in use for on-board functions)
Pins 0,1Serial UART : Pin 0 – TX Pin 1 – RX
Pins 4,5I2C : Pin 4 – SDA Pin 5 – SCL
Pin 10,11Suitable for an ultrasonic sensor or general I/O use.
Pins 12-19are suitable for servos and have 5v Power Available.
Pins 14-17are also available on the back for connection to a dual H-Bridge for DC motors or Bipolar/Unipolar Stepper Motor driver. A 5V Power Supply is available.
Pins 16-19SPI Pin 16 – SPI MISO Pin 17 – SPI SS Pin 18 – SPI Clock Pin 19 – SPI MOSI
Pins 20-22Digital I/O with 3.3v Power Supply
Pins 26-28Analog or digital inputs with 3.3v Power Supply
Internal Pins
Pin 23(digital output) turn on for better voltage regulation (uses a bit more power)
Pin 24(digital input) detects USB connected
Pin 25(digital output) user LED
Pin 29(analog input) temperature sensor
On-board components
Pin 2 and Pin 3On-board LEDs
Pin 6,7,8,9Tactile Switches
Pin 4,5I2C OLED Display connected to Pin 4 – SDA Pin 5 – SCL and running from 3.3v
Pin Connection List

Development Board for the Raspberry Pi Pico

I’ve been experimenting with the Raspberry Pi Pico for a little while now and I found that I kept coming back to the same issues – sensors need power, servos need power, I2C devices need power and the SCL/SDA connections. While there are plenty of Ground connections, I had to make up Y-leads so that the 3v3 connections went to other devices.

I also wanted to link this board to some handy little servos, piezo elements and LEDs, as well as having a few switches and an OLED display.

A bit of tinkering with Fritzing and I ended up with this board. Actually, this is version 2. The first was missing a few connections and I’d put the switches 90 degrees around, meaning that the connections were permanently short-circuited.

Pico PCB with Laser Cut Front Panel and 3d printed case.

I’m happy to make the files available and I’ve uploaded them to my webspace. I haven’t got my head around the whole CC-BY-SA thing, so use them. I’d love to hear from you if you have success though!

Files for the Raspberry Pi Pico circuit board:

Gerber files for the PCB are here: http://roulson.net/PiPicoPCB/Gerber.zip

STL files for the top and bottom layers of the sandwich are here: http://roulson.net/PiPicoPCB/TopSpacer.STL and here: http://roulson.net/PiPicoPCB/BottomSpacer.STL

DXF files for the top and bottom of the case are here: http://roulson.net/PiPicoPCB/TopAcrylic.DXF and here: http://roulson.net/PiPicoPCB/BottomAcrylic.DXF

You will also need a 128×64 i2c OLED display, a bunch of 0.1″ pin headers, two 5mm LEDs, four 6mm tactile push switches (with fairly long actuator around 12mm) and two 150ohm resistors. On the back is a longer pin header which is handy for a stepper motor controller or H-bridge.

Assembly

At some point I’ll do a little photo-shoot of the board being assembled. Not much to it, although some things need fitting in the right order as other parts cover up the joints.

Programming

Programming of the board seems to work really well using Microblocks, which runs either in a browser or (in my case) as a download to my Raspberry Pi 400. Microblocks is at https://microblocks.fun/

It is also possible to use BIPES or MicroPython directly with the board.