Skip to content

Instantly share code, notes, and snippets.

@alopresto
Created March 25, 2019 20:20
Show Gist options
  • Save alopresto/311ac74a251c1f91a9ace533cbb9476e to your computer and use it in GitHub Desktop.
Save alopresto/311ac74a251c1f91a9ace533cbb9476e to your computer and use it in GitHub Desktop.
Python script to display Sense HAT readings on Inky pHAT.
from inky import InkyPHAT
inky_display = InkyPHAT("red")
inky_display.set_border(inky_display.WHITE)
#inky_display.set_rotation(180)
inky_display.v_flip=True
inky_display.h_flip=True
#inky_display.rotation=2
from PIL import Image, ImageFont, ImageDraw
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)
import sys, json
data = json.load(sys.stdin)
# print data
#for key in data:
# print key + " " + data[key]
line1 = "T: " + data["temperature_c"] + " | " + data["temperature_f"]
line2 = "P: " + data["pressure"].split()[0] + "mb | H: " + data["humidity"].split()[0] + "%"
line_padding = 6
w1, h1 = font.getsize(line1)
x = (inky_display.WIDTH / 2) - (w1 / 2)
y = (inky_display.HEIGHT / 2) - h1 - (line_padding / 2)
draw.text((x, y), line1, inky_display.RED, font)
w2, h2 = font.getsize(line2)
x = (inky_display.WIDTH / 2) - (w2 / 2)
y = (inky_display.HEIGHT / 2) + (line_padding / 2)
draw.text((x, y), line2, inky_display.BLACK, font)
inky_display.set_image(img)
inky_display.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment