EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #228 background imageLoading...
Page #228 background image
Chapter 20 LCD1602
228
www.freenove.com
support@freenove.com
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def loop():
mcp. output(3,1) # turn on LCD backlight
lcd. begin(16,2) # set number of LCD lines and columns
w hile(True):
#lcd.clear()
lcd.setCursor(0,0) # set cursor position
lcd.message( 'CPU: ' + get_cpu_temp()+'\n' )# display CPU temperature
lcd.message( get_time_now() ) # display the time
sleep(1)
def destroy():
lcd. clear()
PCF8574_address = 0x27 # I2C address of the PCF8574 chip.
PCF8574A_address = 0x3F # I2C address of the PCF8574A chip.
# Create PCF8574 GPIO adapter.
try:
mcp = PCF8574_GPIO(PCF8574_address)
ex cept:
try:
mcp = PCF8574_GPIO(PCF8574A_address)
e xcept:
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)
if __name__ == '__main__':
p rint ('Program is starting ... ')
try:
loop()
e xcept KeyboardInterrupt:
destroy()
Two modules are used in the code, PCF8574.py and Adafruit_LCD1602.py. These two documents and the
code file are stored in the same directory, and neither of them is dispensable. Please do not delete. PCF8574.py
is used to provide I2C communication mode and operation method of some port for RPi and PCF8574 chip.
Adafruit module Adafruit_LCD1602.py is used to provide some function operation method for LCD1602.
In the code, first get the object used to operate PCF8574 port, then get the object used to operate LCD1602.
address = 0x27 # I2C address of the PCF8574 chip.
# Create PCF8574 GPIO adapter.
mcp = PCF8574_GPIO(address)
# Create LCD, passing in MCP GPIO adapter.
lcd = Adafruit_CharLCD(pin_rs=0, pin_e=2, pins_db=[4,5,6,7], GPIO=mcp)

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish