def main(): epd = epd1in54b.EPD() epd.init() # clear the frame buffer frame_black = [0xFF] * (epd.width * epd.height / 8) frame_red = [0xFF] * (epd.width * epd.height / 8) # For simplicity, the arguments are explicit numerical coordinates epd.draw_rectangle(frame_black, 10, 60, 50, 110, COLORED) epd.draw_line(frame_black, 10, 60, 50, 110, COLORED) epd.draw_line(frame_black, 50, 60, 10, 110, COLORED) epd.draw_circle(frame_black, 120, 80, 30, COLORED) epd.draw_filled_rectangle(frame_red, 10, 130, 50, 180, COLORED) epd.draw_filled_rectangle(frame_red, 0, 6, 200, 26, COLORED) epd.draw_filled_circle(frame_red, 120, 150, 30, COLORED) # write strings to the buffer font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18) epd.display_string_at(frame_black, 30, 30, "e-Paper Demo", font, COLORED) epd.display_string_at(frame_red, 28, 10, "Hello world!", font, UNCOLORED) # display the frame epd.display_frame(frame_black, frame_red) # display images frame_black = epd.get_frame_buffer(Image.open('black.bmp')) frame_red = epd.get_frame_buffer(Image.open('red.bmp')) epd.display_frame(frame_black, frame_red) epd.sleep()
def display_filename(filename): epd = epd1in54b.EPD() epd.init() blackimage = Image.new('1', (epd1in54b.EPD_WIDTH, epd1in54b.EPD_HEIGHT), 255) # 255: clear the frame redimage = Image.new('1', (epd1in54b.EPD_WIDTH, epd1in54b.EPD_HEIGHT), 255) # 255: clear the frame drawblack = ImageDraw.Draw(blackimage) drawred = ImageDraw.Draw(redimage) font18 = ImageFont.truetype( '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 18) font22 = ImageFont.truetype( '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 22) # filename starting_line = 10 print(filename) filename = os.path.basename(filename) print(filename) lines = textwrap.wrap(filename, width=17) for i in range(len(lines)): drawred.text((5, starting_line + i * 20), lines[i], font=font18, fill=0) starting_line += (i + 1) * 20 epd.display(epd.getbuffer(blackimage), epd.getbuffer(redimage)) time.sleep(1) epd.sleep()
def clear(): epd = epd1in54b.EPD() epd.init() blackimage = Image.new('1', (epd1in54b.EPD_WIDTH, epd1in54b.EPD_HEIGHT), 255) # 255: clear the frame redimage = Image.new('1', (epd1in54b.EPD_WIDTH, epd1in54b.EPD_HEIGHT), 255) # 255: clear the frame epd.display(epd.getbuffer(blackimage), epd.getbuffer(redimage)) time.sleep(1) epd.sleep()
def main(): epd = epd1in54b.EPD() epd.init() # clear the frame buffer frame_black = [0xFF] * (epd.width * epd.height / 8) frame_red = [0xFF] * (epd.width * epd.height / 8) humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) if humidity is not None and temperature is not None: print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format( temperature, humidity)) #draw background epd.draw_horizontal_line(frame_red, 0, 65, 1000, COLORED) epd.draw_horizontal_line(frame_red, 0, 66, 1000, COLORED) epd.draw_horizontal_line(frame_red, 0, 130, 1000, COLORED) epd.draw_horizontal_line(frame_red, 0, 131, 1000, COLORED) epd.draw_vertical_line(frame_red, 100, 65, 65, COLORED) epd.draw_vertical_line(frame_red, 101, 65, 65, COLORED) font = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18) font_big = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 30) font_huge = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 40) epd.display_string_at(frame_black, 10, 20, time.strftime("%a %d %b"), font_big, COLORED) epd.display_string_at(frame_black, 10, 70, "T", font_big, COLORED) epd.display_string_at(frame_black, 20, 80, str(int(temperature)) + "C", font_huge, COLORED) epd.display_string_at(frame_black, 110, 70, "H", font_big, COLORED) epd.display_string_at(frame_black, 120, 80, str(int(humidity)) + "%", font_huge, COLORED) epd.display_string_at(frame_black, 30, 160, "Last watered : ", font, COLORED) epd.display_frame(frame_black, frame_red) epd.sleep() else: print('Failed to get reading. Try ')
from requests.auth import HTTPBasicAuth from xml.dom.minidom import parse, parseString from slugify import slugify username = "******" password = os.environ.get('ABPASS') endpoint = os.environ.get("ABURL") COLORED = 1 UNCOLORED = 0 font_b = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 32) font_b2 = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 24) font_b3 = ImageFont.truetype( '/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf', 18) epd = epd1in54b.EPD() epd.init() print("epd init") key = os.environ.get('KEY') def readtemp(): data = {} try: url = "http://wareh.local/arduino/gettemp" response = requests.request("GET", url) data = response.json() return (data['temperature']) except: pass
pycom.heartbeat(False) from machine import Pin import epd1in54b import imagedata import font12 import font20 reset = Pin('P19') dc = Pin('P20') busy = Pin('P18') cs = Pin('P4') clk = Pin('P21') mosi = Pin('P22') epd = epd1in54b.EPD(reset, dc, busy, cs, clk, mosi) epd.init() # initialize the frame buffer fb_size = int(epd.width * epd.height / 8) frame_black = bytearray(fb_size) frame_red = bytearray(fb_size) epd.clear_frame(frame_black, frame_red) # For simplicity, the arguments are explicit numerical coordinates epd.draw_rectangle(frame_black, 10, 60, 50, 110, epd1in54b.COLORED) epd.draw_line(frame_black, 10, 60, 50, 110, epd1in54b.COLORED) epd.draw_line(frame_black, 50, 60, 10, 110, epd1in54b.COLORED) epd.draw_circle(frame_black, 120, 80, 30, epd1in54b.COLORED) epd.draw_filled_rectangle(frame_red, 10, 130, 50, 180, epd1in54b.COLORED)
def get_epd1in54b(): return epd1in54b.EPD()
def display(artist, album, title, track, duration): epd = epd1in54b.EPD() epd.init() # Drawing on the image blackimage = Image.new('1', (epd1in54b.EPD_WIDTH, epd1in54b.EPD_HEIGHT), 255) # 255: clear the frame redimage = Image.new('1', (epd1in54b.EPD_WIDTH, epd1in54b.EPD_HEIGHT), 255) # 255: clear the frame print("drawing") drawblack = ImageDraw.Draw(blackimage) drawred = ImageDraw.Draw(redimage) font18 = ImageFont.truetype( '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 18) font22 = ImageFont.truetype( '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 22) width = 17 # artist starting_line = 10 i = 0 lines = textwrap.wrap(artist, width=width) for i in range(len(lines)): drawred.text((5, starting_line + i * 22), lines[i], font=font22, fill=0) starting_line += (i + 1) * 22 # album lines = textwrap.wrap(album, width=width) for i in range(len(lines)): drawblack.text((5, starting_line + i * 20), lines[i], font=font18, fill=0) starting_line += (i + 1) * 20 # track lines = textwrap.wrap(track, width=width) for i in range(len(lines)): drawred.text((5, starting_line + i * 20), lines[i], font=font18, fill=0) starting_line += (i + 1) * 20 + 20 # title lines = textwrap.wrap(title, width=width - 2) for i in range(len(lines)): drawblack.text((5, starting_line + i * 20), lines[i], font=font18, fill=0) starting_line += (i + 1) * 20 + 2 # duration lines = textwrap.wrap(duration, width=width) for i in range(len(lines)): drawblack.text((5, starting_line + i * 20), lines[i], font=font18, fill=0) starting_line += (i + 1) * 20 #newimage = Image.open('atari.bmp') #blackimage.paste(newimage, (0,0)) epd.display(epd.getbuffer(blackimage), epd.getbuffer(redimage)) blackimage.save('/tmp/b.png') redimage.save('/tmp/r.png') print("sleep") epd.sleep()