Raspberry Pi&5110

网上驱动5110的教程还是蛮多的,我选择的是adafruit官网上提供的教程(主要是移植adafruit了的驱动),由于是在Raspbmc上装,搞了好久发现没spi的驱动- -汗。所以只好用Software SPI了。此次主要使用5510来显示CPU的使用情况、CPU温度、内存使用、环境温度等等。

PS:代码太多,就直接最后附上文件吧。

1. CPU&MEMORY信息:sys_info.py
2. 载入DS18B20所需的驱动:w1.py
3. 环境温度:temperature.py
4. 主程序:lcd_info.py
5. 添加开机启动:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          python
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# X-Start-Before:    rmnologin
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Provide limited super user privileges to specific users
# Description: Provide limited super user privileges to specific users.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting lcd_info"
    # run application you want to start
    # replace it with your file path
    python /home/pi/raspctl/lcd_info.py &
    ;;
  stop)
    echo "Stopping lcd_info"
    # kill application you want to stop
    killall python
    ;;
  *)
    echo "Usage: /etc/init.d/lcd_info {start|stop}"
    exit 1
    ;;
esac

exit 0

(1)启动与关闭服务:

sudo /etc/init.d/lcd_info start
sudo /etc/init.d/lcd_info stop

(2)添加开机启动:

sudo update-rc.d lcd_info defaults

(3)取消开机启动

sudo update-rc.d -f lcd_info remove

待解决问题:第一次运行py刷屏时老是没显示,需要运行下其它的py程序才会有显示,不知道是不是Software SPI的问题,不知道用Hardware SPI是否会有此类问题。
代码下载:Download

参考链接:
Nokia 5110/3310 LCD Python Library
树莓派 python获取硬件信息
python -> Commands模块 -> 使用方法
树莓派 —— DS18B20温度传感器测试
树莓派开机启动程序及启动脚本的制作
Start python script from init.d

Leave a Reply

Your email address will not be published. Required fields are marked *