Skip to content

Instantly share code, notes, and snippets.

@nicholas-gh
Last active March 6, 2017 22:28
Show Gist options
  • Save nicholas-gh/852c26cd0142787976383b981026c4a5 to your computer and use it in GitHub Desktop.
Save nicholas-gh/852c26cd0142787976383b981026c4a5 to your computer and use it in GitHub Desktop.
# http://www.waveshare.com/wiki/4.3inch_e-Paper
# Using FTDI cable - screen Green to FTDI Orange; screen White to FTDI Yellow
import serial
import binascii
import epd
# epd is from https://github.com/yy502/ePaperDisplay/blob/master/epd.py
# Note, using my FTDI USB serial cable - couldn't get rpi UART on 14/15 to work - writes always hung
rate = 115200
#rate = 9600
ser = serial.Serial(port='/dev/ttyUSB0',baudrate=rate,xonxoff = False,rtscts = False,dsrdtr = False,writeTimeout = 3)
if ser.isOpen():
print "Writing"
print epd._cmd_handshake
ser.write(epd.H2B(epd._cmd_handshake))
print "Reading"
print repr(ser.read(2))
ser.write(epd.H2B(epd._cmd_read_baud))
print "Reading"
print ser.read(4)
print "Done"
# set baud rate to 9600 in case this helps stop hanging the pi (but it didn't)
ser.write(binascii.unhexlify("A5 00 0D 01 00 00 25 80 CC 33 C3 3C 0C".replace(" ","")))
ser.close()
ser = serial.Serial(port='/dev/ttyUSB0',baudrate=9600,xonxoff = False,rtscts = False,dsrdtr = False,writeTimeout = 3)
if ser.isOpen():
#ser.write(binascii.unhexlify("A5 00 0B 10 00 03 CC 33 C3 3C BD".replace(" ","")))
#ser.write(binascii.unhexlify("A5 00 11 24 00 0A 00 0A 00 FF 00 FF CC 33 C3 3C 90".replace(" ","")))
#print "Done"
#ser.write(binascii.unhexlify("A5 00 17 30 00 0A 00 0A C4 E3 BA C3 57 6F 72 6C 64 00 CC 33 C3 3C 9E".replace(" ","")))
#print "Done"
hex_txt = epd.A2H("Hello World")
x0, y0 = 10, 10
hex_x0 = ("000"+hex(x0)[2:])[-4:]
hex_y0 = ("000"+hex(y0)[2:])[-4:]
hex_size = ("000"+hex(13+len(hex_txt)/2)[2:])[-4:]
_cmd = epd.FRAME_BEGIN+hex_size+epd.CMD_DRAW_STRING+hex_x0+hex_y0+hex_txt+epd.FRAME_END
ser.write(epd.H2B(_cmd))
# This updates the screen; I used to find it also hung the rpi, but that was due to underpowered PSU (0.7a not enough!)
print ser.write(epd.H2B(epd._cmd_update))
print "Done update"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment