准备好
- 一个正常运行的 Pi
- 适配 Pi 的 PCD8544 屏幕(之前从马云家买的,现已下架)
需要显示
- IP,没分到或拔掉网线时显示
Link Down
- 系统 uptime
- CPU 的使用率和温度
- 内存的使用情况
- 每隔 4 秒刷新一次
安装 WiringPi
根据官网的描述,
WiringPi is a GPIO access library written in C for the BCM2835 used in the Raspberry Pi.
简单理解,WiringPi 是一个用 C 写的控制 GPIO 的库。
$ git clone git://git.drogon.net/wiringPi |
装完测试一下,可以看到类似下面的输出。
pi@raspberrypi:~ $ gpio readall |
找个例子
搜到这篇文章,贴出重要部分的截图。
模仿作者 GitHub 仓库中的三个例子,最终撸出的代码如下,其中,
// monitor8544.c |
添加开机启动
直接在/etc/rc.local
里加一句话:
sudo /full/path/to/your/executable/file & |
不要少了最后的&
,否则 Pi 无法启动。
If your command runs continuously (perhaps runs an infinite loop) or is likely not to exit, you must be sure to fork the process by adding an ampersand to the end of the command, like so:
python /home/pi/myscript.py &
Otherwise, the script will not end and the Pi will not boot. The ampersand allows the command to run in a separate process and continue booting with the process running.