Test Instrumentation

Enter Your Electronics & Design Project for a chance to win a Grand Prize for Originality, a Tool Set, and a $100 Shopping Cart!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

This Project14 blog is about turning a BBC micro:bit into a test instrument. I call this a micro:bit of sense system or µBOSS.

The micro:bit already has a nice set of sensors but they aren't very easy to read on the built in LED display, so I thought I would display all the sensor readings on an LCD, turning it into a test instrument that has the following capabilities:

  • Thermometer
  • Volt Meter
  • Compass
  • Digital Level

Additional features include a lithium-polymer battery and a rectangular 3D printed case that allows flat surfaces to be measured for levelness.

The electronic design is based on a custom interconnect PCB that hosts a micro:bit connector, an LCD footprint, a power switch, a analog input connector and a charging connector.

The main parts look like this:

The micro:bit is programmed to display 6 sensed parameters on 6 lines of text.

Here is a video demonstrating the completed system:

 

The LCD really allows the micro:bit built-in sensors to be fully displayed.

I have been perfecting the the connection and programming of an LCD with a micro:bit and this project is a good way to demonstrate the potential of an LCD to enhance a micro:bit.

There is a deceptive amount of work involved in getting everything connected properly, programmed properly and fit properly in a slim package, but that also makes it more satisfying when it all works.

 

This short video shows the charging module in action:

 

beacon_dave made cool suggestion to use the LEDs as a bubble level - so here is single axis level with LEDs ....

 

 

This is the schematic for those that would like to make one of these for themselves:

 

 

Note there are 2 different pinouts for Nokia 5110 LCDs - I have an adapter card that allows either to be used, but the pinout should be checked if you are going to try this.

Here is the code to display all the sensors on the LCD:

 

from microbit import *
# Program to display BBC micro:bit sensor data on a Nokia 5110 LCD
# by Doug Wong
# 2018


spi.init(baudrate=1000000, bits=8, mode=0, sclk=pin13, mosi=pin15, miso=pin14) # setup for SPI communication with LCD
#lcdinit = [33, 184, 4, 20, 32, 12]  # HEX 21 B8 04 14 20 0C


pin8.write_digital(1)   # disable LCD
pin1.write_digital(0)  # reset LCD
pin1.write_digital(1)  # release reset pin
pin8.write_digital(0)   # enable LCD
pin2.write_digital(0)  # select command mode
spi.write(b'\x21\xb8\x04\x14\x20\x0c')  #LCD init
pin2.write_digital(1)  # select data mode


display.scroll ("BOSS")  #splash screen


def lcd(kb):            # funtion to convert ascii characters to 56 pixel LCD representations and display
                        # each character is made up of 7 bytes where each byte is 8 vertical pixels
    if kb >= " ":
            if kb < "[":
                if kb < "!":
                    spi.write(b'\x00\x00\x00\x00\x00\x00\x00')  #space
    if kb > " ":
        if kb < "[":
            if kb < "#":
                spi.write(b'\x00\x00\x00\xbe\x00\x00\x00')  #!
            elif kb < "$":
                spi.write(b'\x00\x48\xfe\x48\xfe\x48\x00')  ##
            elif kb < "%":
                spi.write(b'\x00\x048\x54\xfe\x54\x24\x00')  #$
            elif kb < "&":
                spi.write(b'\x00\x46\x26\x10\xc8\xc4\x00')  #%
            elif kb < "'":
                spi.write(b'\x00\x6c\x92\xaa\x44\xc0\x00')  #&
            elif kb < ")":
                spi.write(b'\x00\x00\x38\x44\x82\x00\x00')  #(
            elif kb < "*":
                spi.write(b'\x00\x00\x82\x44\x38\x00\x00')  #)
            elif kb < "+":
                spi.write(b'\x00\x28\x10\x2c\x10\x28\x00')  #*
            elif kb < "-":
                spi.write(b'\x00\x00\xa0\x60\x00\x00\x00')  #,
            elif kb < ".":
                spi.write(b'\x00\x10\x10\x10\x10\x00\x00')  #-
            elif kb < "/":
                spi.write(b'\x00\x00\x60\x60\x00\x00\x00')  #.
            elif kb < "1":
                spi.write(b'\x00\x78\xa2\x92\x8a\x74\x00')  #0
            elif kb < "2":
                spi.write(b'\x00\x00\x84\xfe\x80\x00\x00')  #1
            elif kb < "3":
                spi.write(b'\x00\x44\xc2\xa0\x92\x8c\x00')  #2
            elif kb < "4":
                spi.write(b'\x00\x44\x82\x92\x92\x6e\x00')  #3
            elif kb < "5":
                spi.write(b'\x00\x30\x28\x24\xfe\x20\x00')  #4
            elif kb < "6":
                spi.write(b'\x00\x4e\x8a\x8a\x8a\x70\x00')  #5
            elif kb < "7":
                spi.write(b'\x00\x78\x94\x92\x92\x40\x00')  #6
            elif kb < "8":
                spi.write(b'\x00\x02\xc2\x12\x0a\x06\x00')  #7
            elif kb < "9":
                spi.write(b'\x00\x6c\x92\x92\x92\x6c\x00')  #8
            elif kb < ":":
                spi.write(b'\x00\x0c\x92\x92\x52\x3c\x00')  #9
            elif kb < ";":
                spi.write(b'\x00\x00\x6c\x6c\x00\x00\x00')  #:
            elif kb < "@":
                spi.write(b'\x00\x04\x02\xa2\x12\x0c\x00')  #?
            elif kb < "A":
                spi.write(b'\x00\x44\xa2\xc2\x82\x7c\x00')  #@
            elif kb < "B":
                spi.write(b'\x00\xfc\x12\x12\x12\xfc\x00')  #A
            elif kb < "C":
                spi.write(b'\x00\xfe\x92\x92\x92\x6c\x00')  #B
            elif kb < "D":
                spi.write(b'\x00\x7c\x82\x82\x82\x44\x00')  #C
            elif kb < "E":
                spi.write(b'\x00\xfe\x82\x82\x82\x7c\x00')  #D
            elif kb < "F":
                spi.write(b'\x00\xfe\x92\x92\x92\x82\x00')  #E
            elif kb < "G":
                spi.write(b'\x00\xfe\x12\x12\x12\x02\x00')  #F
            elif kb < "H":
                spi.write(b'\x00\x7c\x82\x82\xa2\x64\x00')  #G
            elif kb < "I":
                spi.write(b'\x00\xfe\x10\x10\x10\xfe\x00')  #H
            elif kb < "J":
                spi.write(b'\x00\x00\x82\xfe\x82\x00\x00')  #I
            elif kb < "K":
                spi.write(b'\x00\xe0\x82\x82\xfe\x02\x00')  #J
            elif kb < "L":
                spi.write(b'\x00\xfe\x10\x28\x44\x82\x00')  #K
            elif kb < "M":
                spi.write(b'\x00\xfe\x80\x80\x80\x80\x00')  #L
            elif kb < "N":
                spi.write(b'\x00\xfe\x02\x3c\x02\xfe\x00')  #M
            elif kb < "O":
                spi.write(b'\x00\xfe\x04\x38\x40\xfe\x00')  #N
            elif kb < "P":
                spi.write(b'\x00\x7c\x82\x82\x82\x7c\x00')  #O
            elif kb < "Q":
                spi.write(b'\x00\xfe\x22\x22\x22\x1c\x00')  #P
            elif kb < "R":
                spi.write(b'\x00\x7c\x82\xa2\x42\x7c\x00')  #Q
            elif kb < "S":
                spi.write(b'\x00\xfc\x22\x22\x52\x8c\x00')  #R
            elif kb < "T":
                spi.write(b'\x00\x4c\x92\x92\x92\x64\x00')  #S
            elif kb < "U":
                spi.write(b'\x00\x02\x02\xfe\x02\x02\x00')  #T
            elif kb < "V":
                spi.write(b'\x00\x7e\x80\x80\x80\x7e\x00')  #U
            elif kb < "W":
                spi.write(b'\x00\x3e\x40\x80\x40\x3e\x00')  #V
            elif kb < "X":
                spi.write(b'\x00\x7e\x80\x70\x80\x7e\x00')  #W
            elif kb < "Y":
                spi.write(b'\x00\xc6\x28\x10\x28\xc6\x00')  #X
            elif kb < "Z":
                spi.write(b'\x00\x06\x08\xf0\x08\x06\x00')  #Y
            elif kb < "[":
                spi.write(b'\x00\xc2\xa2\x92\x8a\x86\x00')  #Z
            elif kb < "_":
                spi.write(b'\x00\x10\x08\x04\x08\x10\x00')  #^
            else:
                spi.write(b'\x00\x00\x00\x00\x00\x00\x00')  #.


def dl():                                                   # funtion to display a line
    for i in range(0, 12):                                  # loop through 1 line of characters
        c = l[i]                                            # get next character in the line
        lcd(c)                                              # display the character
    
while True:
    
    l = "TEMP : " + str(temperature() - 4) + "           "          # compose temperature line
    dl()                                                            # display line of text
    l = "VOLT : " + str(pin0.read_analog() * .0031) + "           " # compose voltage line
    dl()                                                            # display line of text
    l = "HEAD : " + str(compass.heading()) + "            "         # compose compass heading line
    dl()                                                            # display line of text
    l = "X ACC: " + str(accelerometer.get_x()) + "           "      # compose X acceleration line
    dl()                                                            # display line of text
    l = "Y ACC: " + str(accelerometer.get_y()) + "           "      # compose Y acceleration line
    dl()                                                            # display line of text
    l = "Z ACC: " + str(accelerometer.get_z()) + "           "      # compose Z acceleration line
    dl()                                                            # display line of text


    sleep(350)                                                  # wait 350 ms before displaying another set of readings

 

 

Relevant Links:

Test Instrumentation

Project14 | Test Instrumentation: Tool Kit Prizes: micro:bits for Testing Tool: bits!