Showing temperature ranges with 12864 I2C OLED screen on Microbit

Using the 12864 I2C OLED screen on Microbit

Here is a nice project done in the Makecode BLOCK environment where the Micro:bit will measure give the min and max temperatures that it is exposed to over a period. It is essentially acting as a basic datalogger of key information!

The OLED itself is a 0.96 OLED Display Module IIC 128 x 64 Pixel 12864 OLED Yellow Blue I2C 0.96inch OLED Display IIC Serial with SSD1306 – what a mouthfull! These are the OLEDS we bought from amazon in a set – they work quite well!

hello world OLED screen microbit

In order to work with this, you need to install the library. In Makecode, this is nice and easy! To do this, in the code block area next to the block canvas, go to:

ADVANCED > EXTENSIONS.

Search for OLED, then select the OLED12864_I2C option. You will then see a new category of coding blocks available (called OLED12864_I2C). In there you will see some code blocks to:

  • initialise the OLED with address 60 (or if that doesn’t work, try 61)
  • show a number at a co-ordinate on the screen (remember it’s a 126 x 64 pixel screen) in some colour (0 or 1)
  • show some text at a co-ordinate on the screen (remember it’s a 126 x 64 pixel screen) in some colour (0 or 1)
  • draw a rectangle or vertical line or horizontal line or set a pixel a colour
  • invert display (dark on light or light on dark)
  • and others!

Here is the GitHub page with more information about this library – this is essentially where makecode gets the library information from!

To connect the OLED screen to the microbit, we use the following pins (these pins are standard for anything involving I2C)

Pin Label micro:bit PIN I2C Function Notes
GND Ground Ground 0V
VCC Power Power Regulated 3V supply.
SDA P20 SDA Serial data in
SCL P19 SCL  I2C clock

Generally it is worth knowing what the pins in the microcontroller can do, here’s a pinout diagram (sourced from this site):

microbit pinout diagram

Here is the ‘breadboard’ wiring diagram I made in Fritzing, showing how the OLED is connected to the Microbit (you might be using an edge connector, but the pins are the same):

microbit OLED wiring diagram

Some useful links for doing this kind of thing in Fritzing:

Simple display example

To start with, here is a simple example showing some text and some numbers. Note that the address used here is 60, if this doesn’t work you can try 61.

 

Temperature measurement and display on OLED

Below is the embedded code I used for this project to measure min and max temperatures (to see how cold my bedroom gets at night!).

Feel free to edit this and run it yourself, or you can start from a new project and build it up yourself. Note that I had some issues with the use of the ‘Download’ button when the microbit was paired. It seemed to work when I hit save, then copied the hex file onto the Microbit in the USB port.

Here is the result!

12864 i2c OLED showing temp range on microbit

Print Friendly, PDF & Email

Derek Covill

Leave a Reply

Your email address will not be published. Required fields are marked *