Last active
March 14, 2018 22:06
-
-
Save greg76/a5e87e0b1e982812a732523d67caf2b3 to your computer and use it in GitHub Desktop.
simple script to display either the arguments or the first lines of whatever is being piped into it to an SSD1306 driven oled screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
import Adafruit_GPIO.SPI as SPI | |
import Adafruit_SSD1306 | |
from PIL import Image | |
from PIL import ImageDraw | |
from PIL import ImageFont | |
disp = Adafruit_SSD1306.SSD1306_128_32(rst=None) | |
disp.begin() | |
#disp.clear() | |
if len(sys.argv)>1 : | |
lines = [ ' '.join(sys.argv[1:]) ] | |
elif not sys.stdin.isatty() : | |
lines = sys.stdin.readlines() | |
if len(lines)>3 : lines = lines[:3] | |
else: | |
lines = None | |
if lines: | |
width = disp.width | |
height = disp.height | |
image = Image.new('1', (width, height)) | |
draw = ImageDraw.Draw(image) | |
font = ImageFont.load_default() | |
for y, line in enumerate(lines): | |
draw.text( | |
(0, y*8+2), | |
line, | |
font=font, fill=255 | |
) | |
disp.image(image) | |
disp.display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment