buzzkillb Posted March 10, 2019 Report Share Posted March 10, 2019 First install InkyPhat on Raspbian on your pi. Pi Zero W might look amazing doing this if you are only pulling info from other places. For now I am only pulling the data from coinexplorer to show a proof of concept. I got the yellow one, but forgot to get the GPIO header for my pi zero w, so its stuck on the Pi3 for now. IMPORTANT: I had to use this line on the pi zero w and reboot after installing the software. curl https://get.pimoroni.com/i2c | sudo bash I got mine from amazon here -> https://amzn.to/2NTI8FAhttps://shop.pimoroni.com/products/inky-phat?variant=12549254905939 https://github.com/buzzkillb/InkyPhat curl https://get.pimoroni.com/inky | bash As a test run use this code to show the Denarius Burn Address Balance. denariusbalance.py #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.WHITE) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius displays blockchain information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne font = ImageFont.truetype(FredokaOne, 22) daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw" url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress response = urllib.urlopen(url) data = json.loads(response.read()) dbalance = ("D balance=" + data['result'][daddress]) w, h = font.getsize(dbalance) x = (inky_display.WIDTH / 2) - (w / 2) y = (inky_display.HEIGHT / 2) - (h / 2) draw.text((x, y), dbalance, inky_display.YELLOW, font) inky_display.set_image(img) inky_display.show() w, h = font.getsize(daddress) x = (inky_display.WIDTH / 2) - (w / 2) y = (inky_display.HEIGHT / 2) - (h / 2) draw.text((x, y), daddress, inky_display.YELLOW, font) inky_display.set_image(img) inky_display.show() To run type python2 denariusbalance.py Cronjob every 15 minutes crontab -e */15 * * * * (cd /home/user/whereever/this/is/located; python2 denariusbalance.py) This is the version I am playing around with to display more than a one liner balance. #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.WHITE) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius displays blockchain information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne font16 = ImageFont.truetype(FredokaOne, 16) font8 = ImageFont.truetype(FredokaOne, 8) daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw" url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress response = urllib.urlopen(url) data = json.loads(response.read()) dbalance = ("D balance=" + data['result'][daddress]) w, h = font16.getsize(dbalance) w1, h1 = font8.getsize(daddress) x = (inky_display.WIDTH / 2) - (w / 2) y = (inky_display.HEIGHT / 4) - (h / 4) x1 = (inky_display.WIDTH / 2) - (w1 / 2) y1 = (inky_display.HEIGHT / 2) - (h1 / 2) draw.text((x, y), dbalance, inky_display.YELLOW, font16) draw.text((x1, y1), daddress, inky_display.YELLOW, font8) inky_display.set_image(img) inky_display.show() Â 1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 10, 2019 Author Report Share Posted March 10, 2019 Line by line breakdown of this so you can abuse any explorer for your favorite cryptocurrency. I just learned basic python about an hour ago, so anyone wants to throw info in here, please do. Sets the address using daddress as the variable. daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw" Sets the URL. %s heads on over to stick that daddress variable from above into the complete block explorer API address. url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress This does something. response = urllib.urlopen(url) This loads the JSON from that URL variable of the complete address. data = json.loads(response.read()) Stores the text D balance= and puts the data from the JSON next to the = sign. dbalance = ("D balance=" + data['result'][daddress]) This would print the line to the command line. But we want InkyPhat to do its thing so we get the rest of the gobbly gook from the code above. print dbalance  1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 10, 2019 Author Report Share Posted March 10, 2019 The idea is that if the e-ink takes 20 seconds to refresh, why not pull different stats in every 15 minutes or so running cronjobs. This example I show pulling in JSON data, rounding to get 3 decimal place precision, then multiplying the POW/POS decimals by 100 to get a percentage (probably did this backwards). I am converting floats and strings like this because I have no clue how to one liner and compact each variable. Then I print all one line with line break '\n' between variable and this time I am not centering the text and instead starting from point 5,20, all at a nice font size of 20. Data wise I am thinking this goes on a pi zero w still, so no running the daemon to pull stats from yet. If you end up using denarius.win, donate Denarius please to the site owner. @KawaiiCrypto denariusstats.py #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.WHITE) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius displays blockchain information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne font = ImageFont.truetype(FredokaOne, 20) url = "http://denarius.win/stats.json" response = urllib.urlopen(url) data = json.loads(response.read()) winpow2 = round(data['pow'],3) winpowresult = float(winpow2) * 100 winpos2 = round(data['pos'],3) winposresult = float(winpos2) * 100 winblocktime2 = round(data['blocktime'],2) winpow = ("POW: " + str(winpowresult) + "%") winpos = ("POS: " + str(winposresult) + "%") winblocktime = ("Blocktime: " + str(winblocktime2) + " sec") winstats = (winpow + '\n' + winpos + '\n' + winblocktime) draw.text((5, 20), winstats, inky_display.YELLOW, font) inky_display.set_image(img) inky_display.show() Â Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 Kind of silly how it works to add an image, but basically follow their own guide how to create this in GIMP. Also be aware the canvas size has to be 212x104 pixels. Make it woooork. https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-inky-phat from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.WHITE) from PIL import Image, ImageFont, ImageDraw img = Image.open("/home/pi/inkyD.png") inky_display.set_image(img) inky_display.show() Sample GIMP png for testing. 1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 Some sample cronjobs and resulting files that can be thrown into this. Any coin daemon can be done in a similar way. Below takes the output and throws into a file every 60 seconds. Then pull want you want from a cronjob and your InkyPhat python file. Example: post fortunastake count every hour, while the fscount.txt file is constantly updating every minute. gentle hint, you need to run the denariusd daemon for below to work * * * * * /usr/local/bin/denariusd fortunastake count > /home/pi/fscount.txt * * * * * /usr/local/bin/denariusd getblockcount > /home/pi/height.txt * * * * * /usr/local/bin/denariusd getinfo > /home/pi/getinfo.json * * * * * /usr/local/bin/denariusd getmininginfo > /home/pi/getmininginfo.json * * * * * /usr/local/bin/denariusd getpeerinfo > /home/pi/getpeerinfo.json 1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 Now you want to throw Bitcoin Price into your new Cryptocurrency scroller? Pulling API info from coindesk. btcprice.py #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.YELLOW) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Bitcoin Price information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne font = ImageFont.truetype(FredokaOne, 24) url = "https://api.coindesk.com/v1/bpi/currentprice.json" response = urllib.urlopen(url) data = json.loads(response.read()) chartname = data['chartName'] btcusd = data['bpi']['USD']['rate_float'] btceur = data['bpi']['EUR']['rate_float'] bitcoinprice = (chartname + '\n' + "$ " + str(btcusd) + '\n' + "E " + str(btceur)) # Load our backdrop image img = Image.open("/home/pi/btc_yellow.png") draw = ImageDraw.Draw(img) draw.text((10, 10), bitcoinprice, inky_display.YELLOW, font) inky_display.set_image(img) inky_display.show() Sample yellow bitcoin logo I am using. 1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 One last one pulling stats from coinpaprika API. The idea is I have changed a thing or two each go around. This pulls the high, low, volume, and for some reason missing marketcap in $USD terms with one of the D logos from the visual guide, https://github.com/carsenk/denarius/wiki/Denarius-Visual-Guide dprice.py #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.YELLOW) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius Price information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne font = ImageFont.truetype(FredokaOne, 22) url = "https://api.coinpaprika.com/v1/coins/d-denarius/ohlcv/latest" response = urllib.urlopen(url) data = json.loads(response.read()) dhigh = data[0]['high'] dlow = data[0]['low'] dvol = data[0]['volume'] dmc = data[0]['market_cap'] denariusprice = ("$ " + str(dhigh) + '\n' + "$ " + str(dlow) + '\n' + "$ " + str(dvol) + '\n' + "$ " + '\n' + str(dmc)) # Load our backdrop image img = Image.open("/home/pi/d-logo.png") draw = ImageDraw.Draw(img) #img = Image.open("/home/pi/btc_yellow.png") draw.text((10, 0), denariusprice, inky_display.BLACK, font) inky_display.set_image(img) inky_display.show() included png for Denarius logo 1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 I edit the logo in GIMP by first resizing the image to 54x54 pixels, then adjust canvas size to 212x104 pixels and drag the logo to where I want it located. 1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 Personal Favorite combining all the above into showing the Denarius Logo+Text with Balance and Address below. Since the D is too big, the address cuts off, but no big deal. dbalance.py #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.YELLOW) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius displays blockchain information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne font = ImageFont.truetype(FredokaOne, 16) daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw" url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress response = urllib.urlopen(url) data = json.loads(response.read()) dbalance = ("D Balance=" + data['result'][daddress] + '\n' + daddress) # Load our backdrop image img = Image.open("/home/pi/d-text-logo.png") draw = ImageDraw.Draw(img) draw.text((10, 60), dbalance, inky_display.BLACK, font) inky_display.set_image(img) inky_display.show() sample logo used  Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 If you have a fortunastake (masternode), you could scroll some info on yours, or even cycle through all of them if you have more than 1. Just chose a random D addy on this one. fortuna.py #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.YELLOW) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius displays blockchain information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne font = ImageFont.truetype(FredokaOne, 18) daddress = "DSSziJxk6bvz5aX3LyCTQoiHGkXi8RA1bV" url = "https://www.coinexplorer.net/api/v1/D/masternode?address=%s" % daddress response = urllib.urlopen(url) data = json.loads(response.read()) urlbalance = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress responsebalance = urllib.urlopen(urlbalance) databalance = json.loads(responsebalance.read()) fs_status = (data['result'][0]['pubkey'] + '\n' + data['result'][0]['status'] + '\n' + data['result'][0]['ip'] + '\n' + databalance['result'][daddress] + "D") # Load our backdrop image img = Image.open("/home/pi/fs-logo.png") draw = ImageDraw.Draw(img) draw.text((10, 5), fs_status, inky_display.BLACK, font) inky_display.set_image(img) inky_display.show() FS logo attached Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 11, 2019 Author Report Share Posted March 11, 2019 To change fonts I will use Denarius official font selection of Open Sans - Semibold. Go to https://github.com/google/fonts/tree/master/apache/opensans And download https://github.com/google/fonts/blob/master/apache/opensans/OpenSans-SemiBold.ttf I send files to the PI3 using winscp, and made a directory called fonts to store these. Or you could cd ~ mkdir fonts cd fonts wget https://github.com/google/fonts/blob/master/apache/opensans/OpenSans-SemiBold.ttf cd ~ If your original line looks like this font = ImageFont.truetype(FredokaOne, 20) Change to the new font. font = ImageFont.truetype("/home/pi/fonts/OpenSans-SemiBold.ttf", 20) Â 1 Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 15, 2019 Author Report Share Posted March 15, 2019 Looks like the image can't be downloaded from here. Not even sure the image can wget from my github. Here is an example of flipping the screen 180 degrees on the pi zero w. #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.WHITE) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius displays blockchain information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne #font = ImageFont.truetype("/home/pi/fonts/OpenSans-SemiBold.ttf", 20) font = ImageFont.truetype(FredokaOne, 20) url = "http://denarius.win/stats.json" response = urllib.urlopen(url) data = json.loads(response.read()) winpow2 = round(data['pow'],3) winpowresult = float(winpow2) * 100 winpos2 = round(data['pos'],3) winposresult = float(winpos2) * 100 winblocktime2 = round(data['blocktime'],2) winpow = ("POW " + str(winpowresult) + "%") winpos = ("POS " + str(winposresult) + "%") winblocktime = ("Blocktime: " + str(winblocktime2) + " sec") winstats = (winpow + winpos + '\n' + winblocktime) # Load our backdrop image img = Image.open("/home/pi/d-text-logo.png") draw = ImageDraw.Draw(img) #w, h = font.getsize(winstats) #x = (inky_display.WIDTH / 2) - (w / 2) #y = (inky_display.HEIGHT / 2) - (h / 2) draw.text((5, 50), winstats, inky_display.BLACK, font) flipped = img.rotate(180) inky_display.set_image(flipped) inky_display.show() Â Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 16, 2019 Author Report Share Posted March 16, 2019 Now for a block height and total supply screen. latest.py #!/usr/bin/env python # -*- coding: utf-8 -*- import urllib, json from inky import InkyPHAT inky_display = InkyPHAT("yellow") inky_display.set_border(inky_display.WHITE) from PIL import Image, ImageFont, ImageDraw print("""Inky pHAT: Denarius displays blockchain information. """) img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) from font_fredoka_one import FredokaOne #font = ImageFont.truetype("/home/pi/fonts/OpenSans-SemiBold.ttf", 20) font = ImageFont.truetype(FredokaOne, 19) url = "https://www.coinexplorer.net/api/v1/D/block/latest" response = urllib.urlopen(url) data = json.loads(response.read()) height = data['result']['height'] heighttext = ("Height: " + str(height)) supply = data['result']['supplyOnBlock'] supplytext = ("Supply: " + str(supply)) stats = (heighttext + '\n' + supplytext) # Load our backdrop image img = Image.open("/home/pi/d-text-logo.png") draw = ImageDraw.Draw(img) #w, h = font.getsize(winstats) #x = (inky_display.WIDTH / 2) - (w / 2) #y = (inky_display.HEIGHT / 2) - (h / 2) draw.text((5, 55), stats, inky_display.BLACK, font) flipped = img.rotate(180) inky_display.set_image(flipped) inky_display.show() Â Quote Link to comment Share on other sites More sharing options...
buzzkillb Posted March 16, 2019 Author Report Share Posted March 16, 2019 Then to combine 2 screens for a cronjob. denarius.sh #!/bin/bash python2 stats.py sleep 200 python2 latest.py chmod +x denarius.sh crontab -e and insert */5 * * * * /home/pi/denarius.sh Seems like an easy way to scroll through different screens. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.