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

Poundland Universal Remote Control

I’ve been experimenting with the infra-red input commands on the PICAXE for some simple remote control Lego robots. There is an official remote control for the PICAXE – in an eye-catching blue case, but for economy I’ve bought a bunch of Poundland universal remote controls.

They don’t give the same hardwearing impression that the official ones give – the cases are a little more flimsy, but they do seem more than adequate to remote control a PICAXE and can therefore add a whole new dimension to PICAXE circuits. An infra-red receiver is an easy thing to add and it means that one input can effectively pretend to be many switches – all present remotely on the handset.

To program the remote, press and hold the TV remote for 5 seconds. The LED will light at this point. Type in the code 0495. When this is completed, the LED will go out and the remote is ready to use.

The command to receive the remote signals is to use:

irin [100],3,b0

Assuming that you’re using input 3. I often use the 08M2 Picaxe, and this is fine. The value is dumped into byte variable b0.

Often I use the following program:

main:
    irin [100],3,b0
    debug
    goto main

to see the effect of pressing different buttons in the debug window.

I’ve discovered the following codes  (File: PoundlandUniversalRemote as a PDF file):

PoundlandUniversalRemote

Scratch, Python and PICAXE conversion

Python, Scratch and PICAXE conversion for simple commands and I/O

Python, Scratch and PICAXE conversion for simple commands and I/O

I often find that I’m having to jump around between Scratch, Python and PICAXE Basic. It’s quite easy to get tangled with the different structures – I keep putting in a # for a PICAXE comment, and the odd colon here and there. Colons in PICAXE are used for labels, not at the end of looping and conditional branches. So… here’s a quick chart which also covers some GPIO stuff.

Scratch-PICAXE Conversion

Scratch -to- Python Conversion

Scratch to Python conversion sheet - click for a PDF file

Scratch to Python conversion sheet – click for a PDF file

Just as you get used to one programming language, the goalposts change and you need another one! This little guide sheet, on two A4 pages, covers the basics of using variables, decisions, lists and loops.

It has been written for Python 3 (the most commonly encountered difference is the need to put brackets around bits that need printing).

I’m going to keep a printed version with me as I’m sure it’ll be useful for explaining the different ways of constructing decisions and loops.

If I get the time, I’ll create pages 3 & 4 – perhaps to cover using GPIO within Scratch and Python.

Python-Scratch Conversion