Title:raspberry PI Model B + (LCD display CPU temperature)--2015-01-29 17:44
Bought a block connected to the raspberry PI Model B + LCD display, the above does not write CPU temperature, processing the next.
Modified PCD8544_RPI.C:
/*================================================================================= NAME:PCD8544_RPI.C Version : 0.1 Copyright (C) by Andre Wussow, (+), [email protected] description:a simple PCD8544 LCD (Nokia33 10/5110) for Raspberry Pi for displaying some system informations. Makes use of wiringpi-library of Gordon Henderson (https://projects.drogon.net/raspberry-pi/wiringpi/) Recommended Co Nnection (http://www.raspberrypi.org/archives/384): LCD pins Raspberry Pi lcd1-gnd p06-gnd LCD2- VCC p01-3.3v lcd3-clk p11-gpio0 lcd4-din p12-gpio1 lcd5-d/c P13-gpio2 Lcd6-cs P15-gpio3 lcd7-rst P16-gpio4 lcd8-led p01-3.3v ============================================== ==================================this Library is free software; You can redistribute it and/ormodify it under the terms of the GNU Lesser General Publiclicense as published by the free S Oftware FoUndation; Eitherversion 2.1 of the License, or (at your option) any later version. This library was distributed in the hope that it'll be useful,but without any WARRANTY; Without even the implied warranty ofmerchantability or FITNESS for A particular PURPOSE. See the Gnulesser general public License for more details.============================================================ ==================== */#include <wiringPi.h> #include <stdint.h> #include <stdio.h> #include < stdlib.h> #include <string.h> #include <sys/sysinfo.h> #include "PCD8544.h" #include <sys/types.h > #include <sys/stat.h> #include <fcntl.h> #define TEMP_FILE_PATH "/sys/class/thermal/thermal_zone0/ Temp "#define MAX_SIZE//pin Setupint _din = 1;int _SCLK = 0;int _dc = 2;int _rst = 4;int _cs = 3; LCD Contrast//may is need modify to fit your screen! NORMAL:30-90, default IS:45!!! Maybe modify this value!int contrast = 55; int main (void) {//print infos printf("Raspberry Pi PCD8544 sysinfo display\n"); printf ("========================================\n"); Check WIRINGPI Setup if (wiringpisetup () = = 1) {printf ("wiringpi-error\n"); Exit (1); }//init and Clear LCD Lcdinit (_SCLK, _din, _DC, _cs, _rst, contrast); Lcdclear (); Show logo Lcdshowlogo (); Delay (2000); for (;;) {//Clear LCD lcdclear (); Get system usage/info struct SysInfo sys_info; if (SysInfo (&sys_info)! = 0) {printf ("sysinfo-error\n"); }//Uptime char uptimeinfo[15]; unsigned long uptime = SYS_INFO.UPTIME/60; sprintf (Uptimeinfo, "Uptime%ld min.", Uptime); CPU info char cpuinfo[10]; unsigned long avgcpuload = sys_info.loads[0]/1000; sprintf (CpuInfo, "CPU%ld%%", avgcpuload); Ram info char raminfo[10]; unsigned long totalram = sys_info.freeram/1024/1024; sprintf (Raminfo, "RAM%ld MB", TotaLram); CPU temperature char cputemperature[15]; float Cpu_temperature_result = Get_cpu_temperature (); sprintf (Cputemperature, "TEMP%.2f ^c", Cpu_temperature_result); Build screen lcddrawstring (0, 0, "Raspberry Pi:"); Lcddrawline (0, ten,----); Lcddrawstring (0, Uptimeinfo); Lcddrawstring (0, CpuInfo); Lcddrawstring (0, Raminfo); Lcddrawstring (0, cputemperature); Lcddisplay (); Delay (1000); }//for (;;) {//printf ("LED on\n"); Digitalwrite (PIN, 1); Delay (250); printf ("LED off\n"); Digitalwrite (PIN, 0); Delay (250); } return 0;} int get_cpu_temperature (void) {int fd; Double temp = 0; Char Buf[max_size]; Open/sys/class/thermal/thermal_zone0/temp fd = open (Temp_file_path, o_rdonly); if (FD < 0) {fprintf (stderr, "failed to open thermal_zone0/temp\n"); return-1; }//Read content if (Read (FD, buf, max_size) < 0) {fprintf (stderr, "failed to read temp\n"); return-1; }//Convert to floating-point number Print temp = atoi (buf)/1000.0; Closes file close (FD); return temp;}
Under Compile execution:
Cc-o cpushow pcd8544_rpi.c PCD8544.C-L/USR/LOCAL/LIB-LWIRINGPI
./cpushow
Because ℃ and °c show a problem, we use ^ instead of that point.
Raspberry PI Model B + (LCD display CPU temperature)