def backlight(status): """ control backlight """ #wiringPy.digital_write(pin_LIGHT, 1 - status) if status==0: GPIO.output(pin_LIGHT, GPIO.HIGH) else: GPIO.output(pin_LIGHT, GPIO.LOW)
def init(CLK = 11, DIN = 10, DC = 23, RST = 24, LIGHT = 18, CE = 8, contrast = default_contrast): """ init screen, clearscreen """ #wiringPy.debug(0) #if wiringPy.setup_gpio() != 0: # raise IOError("Failed to initialize wiringPy properly") #fd = wiringPy.setup_bitbang(CE, DIN, CLK, 0) #if fd == -1: # raise IOError("Failed to initialize bitbang properly") GPIO.init() #pins = [CLK, DIN, DC, RST, LIGHT, CE] pins = [pin_CLK, pin_DIN, pin_DC, pin_RST, pin_LIGHT, pin_CE] #pin_CLK, pin_DIN, pin_DC, pin_RST, pin_LIGHT, pin_CE = pins for pin in pins: GPIO.setcfg(pin, GPIO.OUTPUT) GPIO.output(pin,GPIO.HIGH) #map(lambda p: , pins) # Reset the device GPIO.output(pin_RST, GPIO.LOW) time.sleep(0.1) GPIO.output(pin_RST, GPIO.HIGH) set_contrast(contrast) #command([0x26]) cls()
def send(cmd,type): GPIO.output(pin_CS, GPIO.LOW) if(type == SEND_CHR): GPIO.output(pin_DC, GPIO.HIGH) else: GPIO.output(pin_DC, GPIO.LOW) SPIsendByte(cmd) GPIO.output(pin_CS, GPIO.HIGH)
def SPIsendByte(byteTosend): i = 0 for i in range(1,9): if (byteTosend & 0x80): GPIO.output(pin_MOSI, GPIO.HIGH) else: GPIO.output(pin_MOSI, GPIO.LOW) #sleep(0.00001) GPIO.output(pin_CLK, GPIO.LOW) #sleep(0.00001) GPIO.output(pin_CLK, GPIO.HIGH) byteTosend = byteTosend << 1 return
def bitmap(arr, dc): """ write a sequence of bytes, either as data or command""" #wiringPy.digital_write(pin_DC, dc) #wiringPy.digital_write(pin_DC, dc) if dc==ON: GPIO.output(pin_DC, GPIO.HIGH) else: GPIO.output(pin_DC, GPIO.LOW) #str=struct.pack('B'*len(arr), *arr) #print(str) #print(arr); #for item in arr: # writeonebyte(item) #wiringPy.digital_write_serial_array(0, ) GPIO.bitbang(pin_CLK,pin_DIN,pin_CE,struct.pack('B'*len(arr), *arr))
def init(): # SET CS HIGH GPIO.output(pin_CS, GPIO.HIGH) #Reset LCD GPIO.output(pin_RST, GPIO.LOW) sleep(1) GPIO.output(pin_RST, GPIO.HIGH) sleep(1) send(0x21,SEND_CMD) send(0xC8,SEND_CMD) send(0x04,SEND_CMD) send(0x40,SEND_CMD) send(0x12,SEND_CMD) send(0xE4,SEND_CMD)# Set Display offset line 1 send(0x45,SEND_CMD)# Set Display offset line 2: shiftet 5 pixels up and then use lines 1 to 6 send(0x20,SEND_CMD) send(0x08,SEND_CMD) send(0x0C,SEND_CMD) setContrast(DEFAULT_CONTRAST) clear() update()
#!/usr/bin/env python #import pcd8544.lcd as lcd import lcd import time import A20_GPIO as GPIO def demo(): lcd.locate(0,0) lcd.text("TEST") if __name__ == "__main__": lcd.init() lcd.backlight(1) demo() GPIO.cleanup()
import struct # Some constants / parameter SEND_CHR = 1 SEND_CMD = 2 X_RANGE = 84 Y_RANGE = 48 DEFAULT_CONTRAST = 0xC0 LCD_CACHE_SIZE = X_RANGE*Y_RANGE/8 LCD_Memory = [0 for i in range(LCD_CACHE_SIZE)] LCD_TEMP = [0 for i in range(X_RANGE)],[0 for i in range(Y_RANGE)] GPIO.init(); pin_CS = GPIO.PIN_PI16 # SPI1-CS pin_MOSI = GPIO.PIN_PI18 #SPI1- MOSI pin_MISO = GPIO.PIN_PI19 #SPI1 MISO pin_CLK = GPIO.PIN_PI17 #SPI1 CLK pin_RST = GPIO.PIN_PB18 #UEXT PIN 5 LCD RESET pin_DC = GPIO.PIN_PB19 #UEXT PIN 6 LCD DC GPIO.setcfg(pin_CS,GPIO.OUTPUT) # SPI1-CS GPIO.setcfg(pin_MOSI,GPIO.OUTPUT) #SPI1- MOSI GPIO.setcfg(pin_MISO,GPIO.INPUT) #SPI1 MISO GPIO.setcfg(pin_CLK,GPIO.OUTPUT) #SPI1 CLK GPIO.setcfg(pin_RST,GPIO.OUTPUT) #UEXT PIN 5 LCD RESET GPIO.setcfg(pin_DC,GPIO.OUTPUT) #UEXT PIN 6 LCD DC def send(cmd,type):
def getProcessId(processName): ps = subprocess.Popen("ps ax -o pid= -o args= ", shell=True, stdout=subprocess.PIPE) ps_pid = ps.pid output = ps.stdout.read() ps.stdout.close() ps.wait() for line in output.split("\n"): res = re.findall("(\d+) (.*)", line) if res: pid = int(res[0][0]) if processName in res[0][1] and pid != os.getpid() and pid != ps_pid: return pid return -1 print "Init monitor" GPIO.init() GPIO.setcfg(GPIO.PIN3_39, GPIO.INPUT) GPIO.setcfg(GPIO.PIN3_40, GPIO.INPUT) screenState=False motionStatus = True os.system("echo 1 > /sys/class/gpio/gpio27_pb2/value") infile_path = "/dev/input/event3" #long int, long int, unsigned short, unsigned short, unsigned int FORMAT = 'llHHI' EVENT_SIZE = struct.calcsize(FORMAT) #open file in binary mode in_file = open(infile_path, "rb") try: event = in_file.read(EVENT_SIZE) while event: (tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)
def writeonebyte(data): GPIO.output(pin_CE, GPIO.LOW) #data=bit_reverse(data) for i in range(0,8): if testBit(data,i)!=0: GPIO.output(pin_DIN, GPIO.HIGH) #print("1") else: GPIO.output(pin_DIN, GPIO.LOW) #print("0") GPIO.output(pin_CLK, GPIO.LOW) #time.sleep(0.01) GPIO.output(pin_CLK, GPIO.HIGH) GPIO.output(pin_CE, GPIO.HIGH)