Raspberry Pi Bitcoin Monitor with OLED Ticker

Below is a python script to check the current bitcoin (BTC) value in USD and GBP, and it will output the values to a Raspberry Pi OLED, it will also round the values up to “2” and “3” decimal places. In addition, it monitors the value of my current bitcoin wallet–you have to change this value manually. If you search for “q” and change the value “0.026” to the amount of bitcoins you own, you can then monitor bitcoins more accurately and see if they’re increasing in value.

Raspberry Pi OLED Bitcoin Ticker Code

import subprocess
import time
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
import Image
import ImageDraw
import ImageFont
import json
import urllib2

# Raspberry Pi pin configuration:
RST = 24

# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

# Initialize library.

# Clear display.

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Load default font.
# font = ImageFont.load_default()
# font = ImageFont.truetype('Ubuntu-M.ttf', 14)
fontsmall = ImageFont.truetype('Ubuntu-M.ttf', 16)
fontmedium = ImageFont.truetype('Ubuntu-M.ttf', 14)
fontlarge = ImageFont.truetype('Ubuntu-M.ttf', 16)

# Display Image

# definitions
timerTime = time.time()

from time import sleep

# import requests, json

# def getBitcoinPrice():
#	URL = 'https://www.bitstamp.net/api/ticker/'
#	try:
#		r = requests.get(URL)
#		priceFloat = float(json.loads(r.text)['last'])
#		return priceFloat
#	except requests.ConnectionError:
#		print "Error querying Bitstamp API"

while True:

        draw.rectangle((0, 0, width, height), outline=0, fill=0)

	# now = time.time()

	p = 1
        q = 0.026
        # print getBitcoinPrice() / p * q
	# sleep(1)

	urlusd = 'http://api.coindesk.com/v1/bpi/currentprice/usd.json'


	bbl = jsonObjectusd['bpi']['USD']['rate']	
	bitbut = round(jsonObjectusd['bpi']['USD']['rate_float'], 3)
	bbc = round(bitbut / p * q, 2)




	pbl = jsonObject['bpi']['GBP']['rate']
	poundbit = round(jsonObject['bpi']['GBP']['rate_float'], 3)
	pbc = round(poundbit / p * q, 2) 

	# print 'USD Bitcoin Price'
        # print bbl
        # print 'USD Price Calculated'
        # print bbc

	# print 'GBP Bitcoin Price'
	# print pbl
	# print 'GBP Bitcoin Calculated'
	# print pbc


	draw.text((1,26), str('USD - ') + str(bitbut), font=fontsmall, fill=255)
	draw.text((1,1), str(bbc) + ' /', font=fontlarge, fill=255)
	draw.text((1,48), str('GBP - ') + str(poundbit), font=fontsmall, fill=255)
	draw.text((64,1), ' ' + str(pbc), font=fontlarge, fill=255)



The code is a bit messy, and I’ve been playing around with it for a while. You can tidy it up if you want, haha. It is functional though, just make sure you download the font and put it in the same directory as the python script.

  • nano scriptname.py
  • save
  • apt-get install screen
  • screen
  • python scriptname.py
  • Ctrl a + d

If you have any questions, feel free to ask.

CoinMama: Buy Bitcoins with Credit Card


Affiliate information.

Photochirp.com is a participant in the Amazon Services LLC Associates Program and eBay affiliate programme; these are affiliate advertising programmes designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com & eBay.com.

As an Amazon Associate I earn from qualifying purchases. I am also a Capture One Pro affiliate partner. Please read the Privacy Policy page.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.