Introduction: Micro:bit: Displaying Values Like an Abacus
The Micro:bit is a nifty micro-controller unit for beginners learning about physical computing. It is rather simple to connect different sensors to one of its analog pins and use it to control an output. However, for those familiar with this device, debugging sensor values (particularly analog sensors like photoresistors) can be quite tricky. Establishing a USB serial connection between the micro:bit and a laptop is not straightforward; and using Bluetooth to transmit messages to a mobile app can be rather finicky too. Perhaps the most common way to debug sensor values when using the Micro:bit is to print the values onto the 5x5 on-board LED matrix. Waiting for the numbers to scroll across the screen can be frustratingly slow, and difficult to read (for me at least!).
This Instructables covers a small hack that I made to display a value between 0 to 99,999 on the 5x5 LED matrix (just one screen, no scrolling involved!). It takes inspiration from the abacus (or soroban) to render large values with a small number of moving parts (or LEDs in our case).
If you are already familiar with how an abacus works skip to step 2. If not step 1 offers a crash course how to read an abacus.
Step 1: Crash Course: Reading an Abacus
For this Instructable, you will only need to understand how to read an abacus; you will not need to know how to perform arithmetic operations (although I highly recommend trying it out if you have never used it before!).
An abacus consists of two row of beads strung vertically across a number of columns (the number of columns vary, the more columns, the larger a value it can use for calculation). The top row consist of one bead with a value of 5, while the bottom row consists of four beads, each with a value of one. To begin, all beads are pushed away from the row divider (this also represents the value 0).
Just like the decimal system, the columns increase by a factor of 10 as they move toward the left, and decrease by a factor of 10 as they move towards the right. The middle column typically represents the 1s, followed by 10s, 100s, 1000s as you move left.
Pushing beads towards the row divider assigns a value to its column. For example, pushing three bottom beads towards the row divider on the 1s column represents the value 3. See the images for different example values rendered with an abacus.
Step 2: Displaying Values on the Micro:bit, Abacus Style!
Now that you know how to read an abacus, we are going to use the same principle to display values on the 5x5 LED matrix on the Micro:bit!
Think of the Micro:bit's LED matrix as an abacus with 5 columns. That gives us a range of values between 0 to 99,999 to display. The images show the translation between moving beads on an abacus, to lighting LEDs on the Micro:bit.
Micro:bit's analog pins have a 10 bit resolution; that is, the signal from an analog input is converted to a value between 0 to 1023. The 5x5 matrix is thus capable of displaying this entire range (with just 4 columns in fact!). I have found it really useful for debugging homemade velostat pressure sensors for wearables and such.
Step 3: Micro:bit Code
Finally, here are two sample hex files for you to test on your Micro:bit. The key component in these files is the abacusDisplay function. Assign any value you want to the LED_value variable, and call the abacusDisplay function to display the value abacus style.
microbit-abacus_analog_read.hex: Displays pin 0's value.
microbit-abacus.hex: Displays a value that starts from zero and increases by one each loop.