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 #229 background imageLoading...
Page #229 background image
229
Chapter 20 LCD1602
www.freenove.com
support@freenove.com
According to the circuit connection, port 3 of PCF8574 is connected to positive pole of LCD1602 backlight.
Then in the loop () function, use of mcp.output(3,1) to turn on LCD1602 backlight, and set number of LCD
lines and columns.
def loop():
mcp. output(3,1) # turn on the LCD backlight
lcd. begin(16,2) # set number of LCD lines and columns
In the next while cycle, set the cursor position, and display the CPU temperature and time.
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)
CPU temperature is stored in file “/sys/class/thermal/thermal_zone0/temp. Open the file and
read content of the file, and then convert it to Celsius degrees and return. Subfunction used to
get CPU temperature is shown below:
def get_cpu_temp(): # get CPU temperature and store it into file
“/sys/class/thermal/thermal_zone0/temp”
tmp = open('/sys/class/thermal/thermal_zone0/temp')
cpu = tmp.read()
tmp. close()
r eturn '{:.2f}'.format( float(cpu)/1000 ) + ' C'
Subfunction used to get time:
def get_time_now(): # get the time
r eturn datetime.now().strftime(' %H:%M:%S')
Details about PCF8574.py and Adafruit_LCD1602.py:
Module PCF8574
This module provides two classes PCF8574_I2C and PCF8574_GPIO.
Class PCF8574_I2Cprovides reading and writing method for PCF8574.
Class PCF8574_GPIOprovides a standardized set of GPIO functions.
More information can be viewed through opening PCF8574.py.
Adafruit_LCD1602 Module
Module Adafruit_LCD1602
This module provides the basic operation method of LCD1602, including class Adafruit_CharLCD. Some
member functions are described as follows:
def begin(self, cols, lines): set the number of lines and columns of the screen.
def clear(self): clear the screen
def setCursor(self, col, row): set the cursor position
def message(self, text): display contents
More information can be viewed through opening Adafruit_CharLCD.py.

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