Optimize I2C LCD1602

Adapt for pcf8574A.
This commit is contained in:
Suhayl
2017-04-18 14:12:38 +08:00
parent 447a8b2091
commit e658b7d1fd
4 changed files with 16 additions and 6 deletions
+3 -2
View File
@@ -2,7 +2,7 @@
* Filename : I2CLCD1602.c
* Description : Use the LCD display data
* Author : freenove
* modification: 2016/06/25
* modification: 2017/04/18
**********************************************************************/
#include <stdlib.h>
#include <stdio.h>
@@ -11,7 +11,8 @@
#include <lcd.h>
#include <time.h>
#define pcf8574_address 0x27 // default I2C address of Pcf8574
//#define pcf8574_address 0x27 // default I2C address of Pcf8574
#define pcf8574_address 0x3F // default I2C address of Pcf8574A
#define BASE 64 // BASE is not less than 64
//////// Define the output pins of the PCF8574, which are directly connected to the LCD1602 pin.
#define RS BASE+0
@@ -3,7 +3,7 @@
# Filename : I2CLCD1602.py
# Description : Use the LCD display data
# Author : freenove
# modification: 2016/06/26
# modification: 2017/04/18
########################################################################
from PCF8574 import PCF8574_GPIO
from Adafruit_LCD1602 import Adafruit_CharLCD
@@ -33,9 +33,17 @@ def loop():
def destroy():
lcd.clear()
address = 0x27 # I2C address of the PCF8574 chip.
PCF8574_address = 0x27 # I2C address of the PCF8574 chip.
PCF8574A_address = 0x3F # I2C address of the PCF8574A chip.
# Create PCF8574 GPIO adapter.
mcp = PCF8574_GPIO(address)
try:
mcp = PCF8574_GPIO(PCF8574_address)
except:
try:
mcp = PCF8574_GPIO(PCF8574A_address)
except:
print 'I2C Address Error !'
exit(1)
# Create LCD, passing in MCP GPIO adapter.
lcd = Adafruit_CharLCD(pin_rs=0, pin_e=2, pins_db=[4,5,6,7], GPIO=mcp)
@@ -2,7 +2,7 @@
# Filename : PCF8574.py
# Description : PCF8574 as Raspberry GPIO
# Author : freenove
# modification: 2016/06/26
# modification: 2017/04/18
########################################################################
import smbus
import time
@@ -15,6 +15,7 @@ class PCF8574_I2C(object):
self.bus = smbus.SMBus(1)
self.address = address
self.currentValue = 0
self.writeByte(0) #I2C test.
def readByte(self):#Read PCF8574 all port of the data
#value = self.bus.read_byte(self.address)