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 #227 background imageLoading...
Page #227 background image
227
Chapter 20 LCD1602
www.freenove.com
support@freenove.com
time(&rawtime);// get system time
timeinfo = localtime(&rawtime);// convert to local time
printf("%s \n",asctime(timeinfo));
lcdPosition(lcdhd,0,1);// set the LCD cursor position to (0,1)
lcdPrintf(lcdhd,"Time:%d:%d:%d",timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
//Display system time on LCD
}
Python Code 20.1.1 I2CLCD1602
First observe the project result, and then analyze the code.
1. Use cd command to enter 20.1.1_ I2CLCD1602 directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/20.1.1_I2CLCD1602
2. Use python command to execute python code “I2CLCD1602.py”.
python I2CLCD1602.py
After the program is executed, LCD1602 screen will display current CPU temperature and system time.
If there is no display or the display is not clear, rotate white knob in back of LCD to adjust the contrast
of LCD1602 until the screen can display clearly.
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fr om PCF8574 i m port PCF8574_GPIO
fr om Adafruit_LCD1602 import Adafruit_CharLCD
fr om time i m port sleep, strftime
fr om datetime i m port datetime
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'
def get_time_now(): # get system time
r eturn datetime.now().strftime(' %H:%M:%S')

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