I have been tracking Bitcoin and Ethereum prices for a long time on my phone with the blockfolio app. I really try to refrain from checking my portfolio every 15 minutes but still some days I find myself looking at it all day long. Especially on days where the prices sky rocket. I also wanted to eventually build myself something to track the price in a new way.

I was browsing on reddit in January 2021 in the middle of the Gamestop frenzy and I noticed a post by a user that had built a Led board to track the price of the $GME stock.

This inspired me to go and do the same thing with Bitcoin, fortunately there is a really nice tutorial to do exactly that ! Here

So if you want to build one for yourself, you can find the main steps described below:

You will first need to buy the following items :

  • Adafruit Matrix Portal – CircuitPython Powered Internet Display : link
  • 64×32 RGB LED Matrix – 4mm pitch : link
  • USB Type A to Type C Cable : link

The whole package costs about 70$ and was delivered to my place in Switzerland in about 3 days with the express delivery option.

Here are all the items after outboxing :

First thing to do will be to install CircuitPython on our board. CircuitPython enables easy interaction with your low-cost microcontrollers via python scripts. It makes it super easy to prototype and develop small python applications without any desktop software.

You basically just have to download the UF2 file from here. You then have to copy this file on your MatrixPortal (the small board).

To do so, you have to connect your MatrixPortal to your PC via the USB-C cable and the click two times on the reset button. Green arrow shows where is the reset button and pink shows the NeoPixel RGB LED that should turn green.

led_matrices_matrixportal_install_cp.jpg

Once properly connected your computer will recognize the board and a new disk drive will appear called MATRIXBOOT, next to your regular drives. It is exactly the same as plugging a USB key.

Then drag and drop the uf2 file that you previously downloaded directly into the MATRIXBOOT drive.

The LED will flash then and then the MATRIXBOOT drive will disapear and a new disk drive will appear, it will be called CIRCUITPY.

There you go, you are done. You can now copy there your librarires and your python code in order to pilot what will be displayed on the board !

But first let’s setup the hardware.

The MatrixPortal is your power supply for your board, you need to connect it via 2 standoffs. The first step is to remove the protective orange tape on both standoffs :

Then connect the power terminals. Screw in the spade connectors to the correct standoff:

  • Red wire goes to +5V
  • black wire goes to GND

Then plug one of the four-conductors power plugs into the power connector on the board. There is only one and it is clearly written “POWER” so it should not be too confusing.

Finally connect your board with the MatrixPortal. There is a specific 8×2 connector on the left side of your board, pay attention to the orientation it is has to be plugged in the right direction.

All done with the hardware !

Next we tackle the code. You can find everything on my github : link

Simply copy directly at the root into your CircuitPython drive :

  • the fonts folder : self explanatory
  • the lib folder : containing all the python libraries that will be used by your board
  • The bitcoin image: background display on your board
  • bitcoin_matrix.py: containing the code to connect to the API, retrive the bitcoin price and manage the display on the board
  • secrets.py: containing the connection info to your wifi

To connect to internet simply put the connection information in the secrets.py file :

secrets = {
        'ssid' : 'YOUR WIFI NAME',
        'password' : 'wifi password',
        'aio_username': 'NOT NECESSARY',
        'aio_key': 'NOT NECESSARY',
        'stonks_key': 'NOT NECESSARY'
    }

Done, your board is connected to your wifi and is updating the bitcoin price displayed !

If you want to have a glance at the code in the bitcoin_matrix.py file here it is :

# Run on Metro M4 Airlift w RGB Matrix shield and 64x32 matrix display
# show current value of Bitcoin in USD
 
import time
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal
 
# You can display in 'GBP', 'EUR' or 'USD'
CURRENCY = "USD"
# Set up where we'll be fetching data from
DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
DATA_LOCATION = ["bpi", CURRENCY, "rate_float"]
 
 
def text_transform(val):
    if CURRENCY == "USD":
        return "$%d" % val
    if CURRENCY == "EUR":
        return "€%d" % val
    if CURRENCY == "GBP":
        return "£%d" % val
    return "%d" % val
 
 
# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit("/", 1)[0]
 
matrixportal = MatrixPortal(
    url=DATA_SOURCE,
    json_path=DATA_LOCATION,
    status_neopixel=board.NEOPIXEL,
    default_bg=cwd + "/bitcoin_background.bmp",
    debug=False,
)
 
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(27, 16),
    text_color=0x3d1f5c,
    text_transform=text_transform,
)
matrixportal.preload_font(b"$012345789")  # preload numbers
matrixportal.preload_font((0x00A3, 0x20AC))  # preload gbp/euro symbol
 
while True:
    try:
        value = matrixportal.fetch()
        print("Response is", value)
    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
 
    time.sleep(3 * 60)  # wait 3 minutes

If you want to change the currency being displayed simply change it in the code (CURRENCY = “USD”)

The Bitcoin price is retrived from the coin desk API :

DATA_SOURCE = “https://api.coindesk.com/v1/bpi/currentprice.json”

And from this Json file, we take the “rate_float” data key, for the selected currency (USD/GBP/EUR) in the bpi data hierarchy.

The text_transform() function will just transform the float value of the price into a string that will be then display 9972.6787 -> $9972

Then the MatrixPortal object takes over and manages the display on the board. The main loop will simply run the MatrixPortal.fetch() every 3 minutes : grabbing the json file from the API, parsing it and updating the display value.

Simple as that !