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-
library/
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;