Bitcoin Clock

  • Hey Onioneers,
    Today I wanted to share a project : the Bitcoin Clock.

    This Omega2+ based project displays Bitcoin price on a LCD. A strip of LEDs blinks red when price drops, and green when it goes up.

    You'll need a LCD i2c display (1602), an Onion Omega 2+ with a dock (I've got a Power Dock so I'll be able to power it with a LiPo battery), and a LED strip.
    I used to make projects with addressable LEDs (like WS2811…) but this time, I choose a simple RGB strip working like a RGB LED.

    I installed FireI2CLCD :
    As the i2cdetect command doesn’t work well, I tried a few i2c addresses, mine was 0x27

    When everything was ok, I just put my python file in /etc/rc.local to run my command on boot.

           # Put your custom commands here that should be executed once
           # the system init finished. By default this file does nothing.
           python /root/
           python /root/
           exit 0

    The command displays "Bitcoin Clock" on boot before the principal command.

           import time 
           import omega_gpio
           import lcddriver
           import i2c_lib
           lcd = lcddriver.lcd(0x27)
           lcd.lcd_display_string(" BITCOIN CLOCK ",1)

    Here is the idea : (Don't pay attention to the scale, I drew this with Paint)

    0_1504791124314_Projet 2.png

    First try (without LCD) :

    0_1504790760094_LEDS Proto 1.jpg

    Laser Cutting :


    And it works !!


    Here is the code :

    # BITCOIN CLOCK - A Dorize - OnionIoT - Powered by API 
    import time							
    import urllib                                                                                                         
    import json                                                                                                                  
    import omega_gpio
    import lcddriver
    import i2c_lib
    lcd = lcddriver.lcd(0x27)			# Init LCD
    omega_gpio.initpin(3,'out')			# Init LEDs
    omega_gpio.setoutput(3, 1)
    omega_gpio.setoutput(2, 1)
    prevprice = 4500.000                      	# Nevermind, first blinking
    while True:
    	x = 0
    	site="" # JSONrequest
    	price=a['bpi']['USD']['rate'] 	      # need number in bpi>USD>rate
    	price=price.replace(",","")	# Some cleaning
    	info="1 BTC = " + str(price) + " USD"		# Serial info
    	print info
    	lcd.lcd_display_string("1 BTC =",1)		# LCD info
    	lcd.lcd_display_string(str(price)+" USD",2)
    	if float(price)>prevprice:			# Green blinking
    		for x in range(0, 7):
    			omega_gpio.setoutput(3, 0)
    			omega_gpio.setoutput(3, 1)
    			x +=1
    	elif float(price)<prevprice:			# Red blinking
    		for x in range(0, 7):
    			omega_gpio.setoutput(2, 0)
    			omega_gpio.setoutput(2, 1)
    			x += 1
    	elif float(price)==prevprice:		# backlightOff can be removed
    	infoEUR="1 BTC = " + str(priceEUR) + " EUR"     # EUR Serial info
    	print infoEUR
    	lcd.lcd_display_string("1 BTC = ",1)		# EUR LCD info
    	lcd.lcd_display_string(str(priceEUR)+" EUR",2)	
    	prevprice = float(price)			# Price update

    It's a prototype yet, but it works. Next step I will build another "clock" for Litecoin, maybe 3D printed.

    I hope you enjoyed this tutorial :)

    BTC Tips : 3JRf2GaHsGs9c1naxAn8TN3HN4S1y5hUoG

    Have a nice day Onioneers :)

  • Very nice! I wouldn't mind having one of these. I think it would be cool if you made the face of the 'bitcoin' a pie chart, and had different crypto currencies with their own LEDs under each piece of the pie. Then you could use one omega to report a bunch of different crypto currency rates.

    How many watts is your laser cutter? That looks like its gotta be pretty powerful, 100 watts?

  • @James-Harding Good idea ! :) Thank you, I'll think about it.
    It's not my laser cutter, I use a Trotec Speedy 400 so it's very powerful ;)

  • Don't need to do all that cleaning...

    you should be able to just select the first item in the list to get clean JSON data which is recognised as a dictionary.


    should work... have only been using python for 2 hours tho!

  • @Rongomai-Bailey Cleaning is just to translate a X,XXX.XXXX price into a float XXXX.XXXX

  • @Antoine-Dorize oh yes now I see!

    my bad - was thinking of the stock ticker example

Log in to reply

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.