Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Programming the micro:bit LCD display with MakeCode and Javascript

The Micro:bit is a great device for learning programming. One limitation is the limited display provided by the 5x5 LED matrix. This can be used to display scrolling text but it's difficult to read and far from user friendly.

I2C LCD display 1602 controlled by micro:bit

In this guide I will show how you can use an LCD display to show text messages to users. Through this you can create a stop watch program which uses the display for showing elapsed time.

This video gives an overview of the steps taken in programming the micro:bit. This uses the Microsoft block based editor MakeCode, and I also shown what the code looks like in JavaScript. In a future video I'll also show how this can be programmed using Python.

Hardware for MicroBit stop watch

You will need the following:

  • MicroBit (V1 or V2)
  • 1602 LCD display with I2C adapter
  • Breakout adapter
    • Available pre-soldered or may need soldering
    • Needs to include pins 19 and 20
  • 5v power supply
    • Some breakout adapters include 5V pins
    • Alternative use micro-USB breakout board
  • Some jumper wires (sometimes called dupont leads)

1602 LCD display with I2C

For this example I used a 1602 LCD display. The code refers to 16 characters per row and 2 rows in total. You could use other models such as a 16x4 which would also work.

It is important to get one with an I2C adapter. These are needed because the LCD display takes parallel data and so would use up many of the pins of the MicroBit. The I2C adapter allows you to instead send the data as serial data so needs only 2 pins (plus ground). The image below shows an LCD display without the adapter and one below with adapter. You can buy the adapter separately but that will need to be soldered to the display, whereas it is more convenient to buy them pre-soldered on. The adapters are normally based around the PCF8574 or PF8574A ICs. These normally have I2C address 39 (0x27) for the PF8574 or 63 (0x3F) for the PF8574A. If you want to connect multiple devices then you can change the address using solder pads on the bottom of the board.

I have created a separate guide which explains what I2C is and how it can be used.

LCD display 1602 with and without i2c adapter

The LCD display needs a 5V power supply. This is higher than the 3V power supply available on the micro:bit pins. Some breakout boards include 5V from the USB connector, but if not then you will need a separate power supply. In my case I used a USB lead with a micro-USB breakout connector. If using a separate power supply then the grounds will need to be connected together.

I2C LCD wiring diagram with microbit

The diagram below shows how I wired up my particular setup [click the image for a larger version]. This includes an external micro USB connector which is mounted on a breadboard and used to provide the 5V power needed by the LCD display.

Microbit circuit with LCD display 1602 with i2c adapter and usb power

The ground of the microbit and the LCD are connected together. Pin 19 from the MicroBit connects to SCL (Serial Clock) and pin 20 to SDA (Serial Data).

MakeCode to control I2C LCD on a MicroBit

The complete code is shown below (click for a larger image):

MakeCode programming code for controlling an LCD display with a MicroBit

More Information

See the following pages for more information:

Blog links and videos on programming

Previous Programming the BBC micro:bit
Programming the BBC micro:bit
Next Programming the Raspberry Pi Pico
Programming the Raspberry Pi Pico