Skip to content

Instantly share code, notes, and snippets.

@greg76
Last active March 14, 2018 22:06
Show Gist options
  • Save greg76/a5e87e0b1e982812a732523d67caf2b3 to your computer and use it in GitHub Desktop.
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
#!/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