From 2f0a32e71fd763f101cd0ffe4c4c3814e28fd699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Mon, 8 May 2017 19:57:33 +0200 Subject: [PATCH 1/3] split touch samples add LED pin to driver --- gfxlcd/demos/ili.py | 1 + gfxlcd/demos/ili_2.py | 9 ++---- gfxlcd/demos/ili_image.py | 8 ++--- gfxlcd/demos/touch.py | 7 ++-- gfxlcd/demos/touch_loop.py | 32 +++++++++++++++++++ gfxlcd/driver/ad7843/{ad7853.py => ad7843.py} | 0 gfxlcd/driver/ili9325/gpio.py | 9 ++++-- readme.md | 4 ++- 8 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 gfxlcd/demos/touch_loop.py rename gfxlcd/driver/ad7843/{ad7853.py => ad7843.py} (100%) diff --git a/gfxlcd/demos/ili.py b/gfxlcd/demos/ili.py index aa89fd6..15833f5 100644 --- a/gfxlcd/demos/ili.py +++ b/gfxlcd/demos/ili.py @@ -31,6 +31,7 @@ def draw_net(o): drv = GPIO() +drv.pins['LED'] = 6 o = ILI9325(240, 320, drv) o.init() diff --git a/gfxlcd/demos/ili_2.py b/gfxlcd/demos/ili_2.py index 4d8d91d..a253b60 100644 --- a/gfxlcd/demos/ili_2.py +++ b/gfxlcd/demos/ili_2.py @@ -37,14 +37,11 @@ def draw_net(o): o.draw_line(0, s, o.width-1, s) s += 10 - -lcd_tft = ILI9325(240, 320, ILIGPIO()) +drv = ILIGPIO() +drv.pins['LED'] = 6 +lcd_tft = ILI9325(240, 320, drv) lcd_tft.init() -# bypass of missing +3v line to power backlight -LED = 6 -RPi.GPIO.setup(LED, RPi.GPIO.OUT) -RPi.GPIO.output(LED, 1) lcd_tft.background_color = (255, 255, 255) lcd_tft.fill_rect(0, 0, 240, 320) lcd_tft.color = (0, 255, 1) diff --git a/gfxlcd/demos/ili_image.py b/gfxlcd/demos/ili_image.py index 93afdc0..a3f4e6a 100644 --- a/gfxlcd/demos/ili_image.py +++ b/gfxlcd/demos/ili_image.py @@ -7,13 +7,11 @@ from gfxlcd.driver.ili9325.ili9325 import ILI9325 RPi.GPIO.setmode(RPi.GPIO.BCM) -lcd_tft = ILI9325(240, 320, ILIGPIO()) +drv = ILIGPIO() +drv.pins['LED'] = 6 +lcd_tft = ILI9325(240, 320, drv) lcd_tft.init() -# bypass of missing +3v line to power backlight -LED = 6 -RPi.GPIO.setup(LED, RPi.GPIO.OUT) -RPi.GPIO.output(LED, 1) image_file = Image.open("assets/japan_temple_240x320.jpg") lcd_tft.draw_image(0, 0, image_file) diff --git a/gfxlcd/demos/touch.py b/gfxlcd/demos/touch.py index 2f42150..a63dd56 100644 --- a/gfxlcd/demos/touch.py +++ b/gfxlcd/demos/touch.py @@ -4,7 +4,7 @@ import time sys.path.append("../../") from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO from gfxlcd.driver.ili9325.ili9325 import ILI9325 -from gfxlcd.driver.ad7843.ad7853 import AD7843 +from gfxlcd.driver.ad7843.ad7843 import AD7843 RPi.GPIO.setmode(RPi.GPIO.BCM) @@ -21,10 +21,7 @@ touch.init() while True: try: - time.sleep(0.05) - # ret = touch.get_position() - # if ret: - # print(ret[0], ret[1]) + time.sleep(1) except KeyboardInterrupt: touch.close() diff --git a/gfxlcd/demos/touch_loop.py b/gfxlcd/demos/touch_loop.py new file mode 100644 index 0000000..a0bb1de --- /dev/null +++ b/gfxlcd/demos/touch_loop.py @@ -0,0 +1,32 @@ +import RPi.GPIO +import sys +import time +sys.path.append("../../") +from gfxlcd.driver.ili9325.gpio import GPIO as ILIGPIO +from gfxlcd.driver.ili9325.ili9325 import ILI9325 +from gfxlcd.driver.ad7843.ad7843 import AD7843 +RPi.GPIO.setmode(RPi.GPIO.BCM) + + +lcd_tft = ILI9325(240, 320, ILIGPIO()) +lcd_tft.init() + + +def callback(position): + print('(x,y)', position) + +touch = AD7843(240, 320) + +touch.init() + +while True: + try: + time.sleep(0.05) + ret = touch.get_position() + if ret: + print(ret[0], ret[1]) + + except KeyboardInterrupt: + touch.close() + RPi.GPIO.cleanup() + diff --git a/gfxlcd/driver/ad7843/ad7853.py b/gfxlcd/driver/ad7843/ad7843.py similarity index 100% rename from gfxlcd/driver/ad7843/ad7853.py rename to gfxlcd/driver/ad7843/ad7843.py diff --git a/gfxlcd/driver/ili9325/gpio.py b/gfxlcd/driver/ili9325/gpio.py index 4da591b..dff3fd2 100644 --- a/gfxlcd/driver/ili9325/gpio.py +++ b/gfxlcd/driver/ili9325/gpio.py @@ -20,6 +20,8 @@ class GPIO(Driver): 'DB14': 20, 'DB15': 21, 'RST': 25, + 'LED': None, + 'CS': None } self.data_pins = [ 'DB8', 'DB9', 'DB10', 'DB11', 'DB12', 'DB13', 'DB14', 'DB15', @@ -28,11 +30,14 @@ class GPIO(Driver): def init(self): """initialize pins""" for pin in self.pins: - RPi.GPIO.setup(self.pins[pin], RPi.GPIO.OUT) - RPi.GPIO.output(self.pins[pin], 0) + if self.pins[pin] is not None: + RPi.GPIO.setup(self.pins[pin], RPi.GPIO.OUT) + RPi.GPIO.output(self.pins[pin], 0) def reset(self): """reset a display""" + if self.pins['LED']: + RPi.GPIO.output(self.pins['LED'], 1) RPi.GPIO.output(self.pins['RST'], 1) time.sleep(0.005) RPi.GPIO.output(self.pins['RST'], 0) diff --git a/readme.md b/readme.md index 26f56b1..e1c963f 100644 --- a/readme.md +++ b/readme.md @@ -98,6 +98,8 @@ Custom pins: 'DB14': 20, 'DB15': 21, 'RST': 25, + 'LED': None, + 'CS': None } o = ILI9325(240, 320, drv) o.init() @@ -233,4 +235,4 @@ Default: DB15 ------------------------ G21 CS ------------------------ GND (always selected) REST ------------------------ G25 - LED_A ------------------------ 3.3 + LED_A ------------------------ 3.3 (can be connected to GPIO pin) From 70a450ba741fe42c6dfe251af6336d1c65f0890d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Mon, 8 May 2017 20:45:50 +0200 Subject: [PATCH 2/3] ili CS pin --- gfxlcd/demos/ili.py | 1 + gfxlcd/demos/ili_2.py | 1 + gfxlcd/demos/ili_image.py | 1 + gfxlcd/driver/ili9325/gpio.py | 6 ++++++ readme.md | 2 +- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gfxlcd/demos/ili.py b/gfxlcd/demos/ili.py index 15833f5..23ee492 100644 --- a/gfxlcd/demos/ili.py +++ b/gfxlcd/demos/ili.py @@ -32,6 +32,7 @@ def draw_net(o): drv = GPIO() drv.pins['LED'] = 6 +drv.pins['CS'] = 18 o = ILI9325(240, 320, drv) o.init() diff --git a/gfxlcd/demos/ili_2.py b/gfxlcd/demos/ili_2.py index a253b60..49957d6 100644 --- a/gfxlcd/demos/ili_2.py +++ b/gfxlcd/demos/ili_2.py @@ -39,6 +39,7 @@ def draw_net(o): drv = ILIGPIO() drv.pins['LED'] = 6 +drv.pins['CS'] = 18 lcd_tft = ILI9325(240, 320, drv) lcd_tft.init() diff --git a/gfxlcd/demos/ili_image.py b/gfxlcd/demos/ili_image.py index a3f4e6a..7c58fc6 100644 --- a/gfxlcd/demos/ili_image.py +++ b/gfxlcd/demos/ili_image.py @@ -9,6 +9,7 @@ RPi.GPIO.setmode(RPi.GPIO.BCM) drv = ILIGPIO() drv.pins['LED'] = 6 +drv.pins['CS'] = 18 lcd_tft = ILI9325(240, 320, drv) lcd_tft.init() diff --git a/gfxlcd/driver/ili9325/gpio.py b/gfxlcd/driver/ili9325/gpio.py index dff3fd2..9d06f5d 100644 --- a/gfxlcd/driver/ili9325/gpio.py +++ b/gfxlcd/driver/ili9325/gpio.py @@ -38,6 +38,8 @@ class GPIO(Driver): """reset a display""" if self.pins['LED']: RPi.GPIO.output(self.pins['LED'], 1) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS'], 1) RPi.GPIO.output(self.pins['RST'], 1) time.sleep(0.005) RPi.GPIO.output(self.pins['RST'], 0) @@ -59,12 +61,16 @@ class GPIO(Driver): def send(self, char, enable): """send 16bit as 2*8bit""" + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS'], 0) self._set_pins(char >> 8) RPi.GPIO.output(self.pins['W'], 0) RPi.GPIO.output(self.pins['W'], 1) self._set_pins(char) RPi.GPIO.output(self.pins['W'], 0) RPi.GPIO.output(self.pins['W'], 1) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS'], 1) def data(self, data, enable): """send data to display""" diff --git a/readme.md b/readme.md index e1c963f..18c87b4 100644 --- a/readme.md +++ b/readme.md @@ -233,6 +233,6 @@ Default: DB13 ------------------------ G16 DB14 ------------------------ G20 DB15 ------------------------ G21 - CS ------------------------ GND (always selected) + CS ------------------------ GND (always selected) (or connect to GPIO pin) REST ------------------------ G25 LED_A ------------------------ 3.3 (can be connected to GPIO pin) From 95629d36efa732b5a52b83eb3f3347260215c1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Mon, 8 May 2017 20:46:50 +0200 Subject: [PATCH 3/3] docs --- CHANGELOG.txt | 2 ++ setup.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5bd8c75..1e2fcfe 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,5 @@ +0.2.1 + - CS & LED pin do ILI drv 0.2.0 - add AD7843 touch panel driver 0.1.0 diff --git a/setup.py b/setup.py index f90fe63..57f673b 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def read(*paths): setup( name='gfxlcd', - version='0.2.0', + version='0.2.1', description='gfxlcd is a handler for graphical lcds: ILI9328, SSD1306, NJU6450, touch panel: AD7843 @ Raspberry Pi.', keywords=['gfxlcd', 'raspberry pi' ,'ili9328' ,'ssd1306', 'nju6450', 'lcd', 'graphical lcd', 'touch panel', 'ad7843'], long_description=(read('readme.md')),