Title:Raspberry PI Model B+ (LCD显示CPU温度)  --2015-01-29 17:44

买了块连接Raspberry PI Model B+的LCD显示器,上面没写CPU温度,就加工了下。

https://github.com/binerry/RaspberryPi/tree/master/libraries/c/PCD8544

修改后的pcd8544_rpi.c:

https://github.com/Teaing/Raspberrypi/tree/master/PCD8544

/*
=================================================================================
Name : pcd8544_rpi.c
Version : 0.1 Copyright (C) 2012 by Andre Wussow, 2012, desk@binerry.de Description :
A simple PCD8544 LCD (Nokia3310/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 connection (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/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser 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 32 // pin setup
int _din = 1;
int _sclk = 0;
int _dc = 2;
int _rst = 4;
int _cs = 3; // lcd contrast
int contrast = 50; 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, 10, 83, 10, BLACK);
LCDdrawstring(0, 12, uptimeInfo);
LCDdrawstring(0, 20, cpuInfo);
LCDdrawstring(0, 28, ramInfo);
LCDdrawstring(0, 36, cputemperature);
LCDdisplay(); delay(10000);
} //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]; // 打开/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;
} // 读取内容
if (read(fd, buf, MAX_SIZE) < 0) {
fprintf(stderr, "failed to read temp\n");
return -1;
} // 转换为浮点数打印
temp = atoi(buf) / 1000.0; // 关闭文件
close(fd);
return temp;
}

  

编译执行下:

cc -o cpushow pcd8544_rpi.c PCD8544.c  -L/usr/local/lib -lwiringPi

./cpushow

因为℃跟°C显示有问题,就用^代替那个点了。

Raspberry PI Model B+ (LCD显示CPU温度)的更多相关文章

  1. 树莓派3代B型 Raspberry Pi Model 3 B 安装 centos7系统

    板子类型: Raspberry Pi Model 3 B 搭配 32G的SD卡: 下载支持树莓派版本的centos7系统 https://buildlogs.centos.org/centos/7/i ...

  2. raspberry pi 如何汉化显示中文

    1 树莓派初装系统之后,首次启动会出现“raspi-config”工具,如下图:(若不是初次启动,在命令模式下,请输入 sudo raspi-config 命令,即可调出此界面.若在图形桌面下,打开桌 ...

  3. 树莓派2代 B型 4核 1G内存 raspberry pi 2 model B

    树莓派技术交流群:318799602 期盼已久的PI2 已经到货,Element14版,非RS版本.诚信卖家如期发货,不会像某些淘宝卖家一样,没有货还标注现货,发货时间一拖再拖. 树莓派的最新力作!! ...

  4. 让你的Ubuntu也能像Windows那样显示网速和CPU温度

    致力于Linux桌面操作系统的平民化,一直强迫自己完全在Ubuntu系统下进行日常的电脑使用,但是用长了时间的Windows,还是有些习惯改不过来,比如只要在下载或者看在线视频的时候就会不自觉关注网速 ...

  5. LCD显示GPS时钟[嵌入式系统]

    夏任务102:做一个GPS钟 实验要求 用RPi的串口连接一个GPS模块,从GPS得到实时时间,在7段数码管或LCD上显示 实验工具: Raspberry Pi Model B主机, 8G c10 S ...

  6. Adding an On/Off switch to your Raspberry Pi

    http://www.raspberry-pi-geek.com/Archive/2013/01/Adding-an-On-Off-switch-to-your-Raspberry-Pi#articl ...

  7. Raspberry Pi Kernel Compilation 内核编译官方文档

    elinux.org/Raspberry_Pi_Kernel_Compilation#Use_the_provided_compiler Software & Distributions: S ...

  8. Arduino VS. Raspberry Pi VS. Beaglebone Black

    The Arduino is a small Atmel-based microcontroller development board easily integrated into many dif ...

  9. 【嵌入式开发】Raspberry Pi 树莓派性能测试

    Raspberry Pi 树莓派性能测试 目录: CPU Linpack基准测试 源码 编译/运行 结果 Whetstone/Dhrystone综合基准测试 源码 编译/运行 结果 OpenSSL安全 ...

随机推荐

  1. 每一个web开发者都应该了解的HTTP/2

    我认为每一个 web 开发者都应该对这个支撑了整个 Web 世界的 HTTP 协议有所了解,这样才能帮助你更好的完成开发任务.在这篇文章中,我将讨论什么是 HTTP,它是怎么产生的,它的地位,以及我们 ...

  2. 一个美国小券商的生存之道Tradestation

    转自:证券时报记者 张欣然 桂衍民 中国互联网金融的口号喊了十几年,众多证券公司仍然苦于找不到新的蓝海,研究大西洋彼岸的美国TradeStation公司的业务模式,也许对国内的证券公司会有一些启迪. ...

  3. Spring Boot 启动原理分析

    https://yq.aliyun.com/articles/6056 转 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启 ...

  4. Linux下tomcat使用

    http://tomcat.apache.org/download-70.cgi这里下载 放到Linux目录下,解压开, 默认port:8080能够直接使用 经常使用启动命令catalina.sh   ...

  5. Eclipse导入Gradle时报错:SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable

    百度查到http://stackoverflow.com/questions/19794200/gradle-android-and-the-android-home-sdk-location 按照其 ...

  6. ExtJS4.2学习(6)——基础知识之proxy篇

    本次讨论下数据代理,其实个人第一次听到这个短语的时候,并不是特别的适应,在英语中的含义是proxy,其实如若大家也觉得不适应的话,就直接称呼proxy吧. 在ExtJS中,proxy是进行数据读写的主 ...

  7. Android中为图标加上数字--用于未读短信数提醒,待更新应用数提醒等

    本文属于原创,转载请著名出处:http://flysnow.iteye.com/blog/906770 写道 在我们开发一些如短消息.应用商店等应用时,会考虑在短消息的图标上加上未读短信的数量,在应用 ...

  8. CALayer的基本操作

     CALayer简介:   CALayer又称为层. 在每一个UIView内部都有一个Layer这样的属性. UIView之所以能够显示,就是因为它里面有这个一个层,才具有显示的功能. 我们通过操作C ...

  9. Day4 - Python基础4 迭代器、装饰器、软件开发规范

    Python之路,Day4 - Python基础4 (new版)   本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 ...

  10. 【开源java游戏框架libgdx专题】-15-系统控件-Button类

    Button类继承与Actor类,可以在舞台中使用,但是它也继承了许多Actor的子类,如Group.Table.WidgetGroup灯. 常用构造方法: Button():创建按钮对象,不设置其样 ...