树莓派通过I2C接口,用的Python语言。
Python LCD1602驱动下载:
http://pan.baidu.com/s/1bnpj3Zp


一般LCD1602需要11个GPIO,但是树莓派的GPIO口有限,所以需要串转并的方式来节省GPIO口。下图为一般LCD1602的接法。

强烈推荐此款i2c转LCD1602的转接板

在网上有LCD1602的驱动程序。此Python程序用了LCD1602的四线模式,以及用P3口来控制LCD的背光灯。
当时网上的Python程序,默认关闭了LCD的背光,导致驱动LCD时一下子就黑屏,还以为LCD坏了呢!我将背光默认打开,并添加了,turn_light函数来控制LCD的背光的开光。版权归原作者Jerry。

1、首先我们需要修改树莓派的配置文件使能I2C,通过nano编辑器修改raspi-blacklist.conf 文件内容
pi@raspberrypi ~ $ sudo nano /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
blacklist spi-bcm2708
blacklist i2c-bcm2708
2、打开/etc/modules ,在文件结尾加上 i2c-dev、i2c-bcm2708
pi@raspberrypi ~ $ sudo nano /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
i2c-bcm2708
i2c-dev
3、更新一次包列表
pi@raspberrypi ~ $ sudo apt-get update
4、安装 i2c-tools工具与python-smbus
pi@raspberrypi ~ $ sudo apt-get install i2c-tools python-smbus
5、重启后,pi@raspberrypi ~ $ sudo i2cdetect -y 1

你的I2c设备地址就是0x27,即转接板上的I2C地址。
Python LCD1602驱动下载:
http://pan.baidu.com/s/1bnpj3Zp
最后测试一下:
nupt@raspberrypi:~/1602$ ls
LCD1602.py LCD1602.pyc LCD1602.zip test.py test.zip
nupt@raspberrypi:~/1602$ sudo python test.py
[sudo] password for nupt:
LCD init over
Turn on BLight
wait 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
Python LCD1602驱动下载:
http://pan.baidu.com/s/1bnpj3Zp


一般LCD1602需要11个GPIO,但是树莓派的GPIO口有限,所以需要串转并的方式来节省GPIO口。下图为一般LCD1602的接法。

强烈推荐此款i2c转LCD1602的转接板

在网上有LCD1602的驱动程序。此Python程序用了LCD1602的四线模式,以及用P3口来控制LCD的背光灯。
当时网上的Python程序,默认关闭了LCD的背光,导致驱动LCD时一下子就黑屏,还以为LCD坏了呢!我将背光默认打开,并添加了,turn_light函数来控制LCD的背光的开光。版权归原作者Jerry。

1、首先我们需要修改树莓派的配置文件使能I2C,通过nano编辑器修改raspi-blacklist.conf 文件内容
pi@raspberrypi ~ $ sudo nano /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
blacklist spi-bcm2708
blacklist i2c-bcm2708
2、打开/etc/modules ,在文件结尾加上 i2c-dev、i2c-bcm2708
pi@raspberrypi ~ $ sudo nano /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
i2c-bcm2708
i2c-dev
3、更新一次包列表
pi@raspberrypi ~ $ sudo apt-get update
4、安装 i2c-tools工具与python-smbus
pi@raspberrypi ~ $ sudo apt-get install i2c-tools python-smbus
5、重启后,pi@raspberrypi ~ $ sudo i2cdetect -y 1

你的I2c设备地址就是0x27,即转接板上的I2C地址。
Python LCD1602驱动下载:
http://pan.baidu.com/s/1bnpj3Zp
最后测试一下:
nupt@raspberrypi:~/1602$ ls
LCD1602.py LCD1602.pyc LCD1602.zip test.py test.zip
nupt@raspberrypi:~/1602$ sudo python test.py
[sudo] password for nupt:
LCD init over
Turn on BLight
wait 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds
turn on background light 2 seconds
turn off background light 2 seconds