Chapter 20 LCD1602
226
Details about lcdInit():
int lcdInit (int rows, int cols, int bits, int rs, int strb,
int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) ;
This is the main initialization function and must be called before you use any other LCD functions.
Rows
and
cols
are the rows and columns on the display (e.g. 2, 16 or 4,20).
Bits
is the number of bits wide
on the interface (4 or 8). The
rs
and
strb
represent the pin numbers of the displays RS pin and Strobe (E)
pin. The parameters
d0
through
d7
are the pin numbers of the 8 data pins connected from the Pi to the
display. Only the first 4 are used if you are running the display in 4-bit mode.
The return value is the ‘handle’ to be used for all subsequent calls to the lcd library when dealing with that
LCD, or -1 to indicate a fault. (Usually incorrect parameters)
For more details about LCD Library, please refer to:
https://projects.drogon.net/raspberry-pi/wiringpi/lcd-
In the next “while”, two subfunctions are called to display the CPU temperature and the time. First look at
subfunction
printCPUTemperature().
The
CPU
temperature
data
is
stored
in
the
"
/sys/class/thermal/thermal_zone0/temp
" file. We need read contents of the file, and converts it to
temperature value stored in variable CPU_temp, and use lcdPrintf() to display it on LCD.
void
printCPUTemperature
(){//subfunction used to print CPU temperature
FILE
*
fp
;
char
str_temp
[
15
];
float
CPU_temp
;
// CPU temperature data is stored in this directory .
fp
=
fopen
(
"/sys/class/thermal/thermal_zone0/temp"
,
"r"
);
fgets
(
str_temp
,
15
,
fp
);
// read file temp
CPU_temp
=
atof
(
str_temp
)/
1000.0
;
// convert to Celsius degrees
printf
(
"CPU's temperature : %.2f \n"
,
CPU_temp
);
lcdPosition
(
lcdhd
,
0
,
0
);
// set the LCD cursor position to (0,0)
lcdPrintf
(
lcdhd
,
"CPU:%.2fC"
,
CPU_temp
);// Display CPU temperature on LCD
fclose
(
fp
);
}
Details about lcdPosition() and lcdPrintf():
lcdPosition (int handle, int x, int y);
Set the position of the cursor for subsequent text entry.
lcdPutchar (int handle, uint8_t data)
lcdPuts (int handle, char *string)
lcdPrintf (int handle, char *message, …)
These output a single ASCII character, a string or a formatted string using the usual printf formatting
commands.
Next is subfunction printDataTime() used to print system time. First, got the standard time and store it into
variable rawtime, and then converted it to the local time and tore it into timeinfo, and finally display the time
information on LCD1602.
void
printDataTime
(){//used to print system time
time_t
rawtime
;
struct
tm
*
timeinfo
;
Содержание Ultimate Starter Kit
Страница 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Страница 116: ...Chapter 9 Potentiometer RGBLED 116 www freenove com support freenove com Circuit Schematic diagram ...
Страница 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Страница 136: ...Chapter 12 Joystick 136 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Страница 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Страница 182: ...Chapter 17 74HC595 LEDBar Graph 182 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 197: ...197 Chapter 18 74HC595 7 segment display www freenove com support freenove com Circuit Schematic diagram ...
Страница 198: ...Chapter 18 74HC595 7 segment display 198 www freenove com support freenove com Hardware connection ...
Страница 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Страница 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...
Страница 270: ...Chapter 26 WebIOPi IOT 270 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...