AT: Bitcoin Price Demo

One of the powers of Python is the built-in data parsing capabilities. Stuff that's really hard in C, like json parsing, comes with the larger builds of CircuitPython, making it really easy to get IoT projects going.

For example, we can connect to internet API's and parse out the data we want very fast.

In this demo, we'll use the coinbase API for the current Bitcoin pricing. This is one of the few API's we found that doesn't require a key, so it's very fast to test and use.

You can check the output by visiting and seeing the output, which will look something like

{"time":{"updated":"Dec 16, 2018 22:43:00 UTC","updatedISO":"2018-12-16T22:43:00+00:00","updateduk":"Dec 16, 2018 at 22:43 GMT"},"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from","chartName":"Bitcoin","bpi":{"USD":{"code":"USD","symbol":"$","rate":"3,227.6983","description":"United States Dollar","rate_float":3227.6983},"GBP":{"code":"GBP","symbol":"£","rate":"2,561.0302","description":"British Pound Sterling","rate_float":2561.0302},"EUR":{"code":"EUR","symbol":"€","rate":"2,855.5609","description":"Euro","rate_float":2855.5609}}}

You can explore this data to see exactly where the info you want is, using tools like (there's plenty of these kinds of sites, just search for a 'json viewer' or 'json explorer')

After pasting in the JSON data

You can navigate through it.

So for example, the USD conversion data is in bpi->USB->rate_float

In our code, once we get the URL data response, we can parse it and extract that entry with bitcoin = json["bpi"]["USD"]["rate_float"]

Here's the full example. Note we use a try block for json parsing in case the data comes back to us weird or its somehow not valid json data.

Temporarily unable to load content:

To display it, we use a 7-segment display hooked up to the I2C port, such as this one:

Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack - Green

What's better than a single LED? Lots of LEDs! A fun way to make a small display is to use an 8x8 matrix or a

Or the all-in-one FeatherWing:

Adafruit 0.56" 4-Digit 7-Segment FeatherWing Display - Green

One segment? No way dude! 7-Segments for life!This is the Green Adafruit 0.56" 4-Digit 7-Segment Display w/ FeatherWing Combo Pack! We also have these...
This guide was first published on Dec 16, 2018. It was last updated on Dec 16, 2018. This page (AT: Bitcoin Price Demo) was last updated on Apr 01, 2020.