下面我们需要修改树莓派的配置文件使能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
打开/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
更新一次包列表
pi@raspberrypi ~ $ sudo apt-get update
安装 i2c-tools工具与python-smbus
pi@raspberrypi ~ $ sudo apt-get install i2c-tools python-smbus
之后reboot,重启后千万记得打开i2c接口 否则无法找到i2c地址,出现如下错误:
Could not open file /dev/i2c-1' or
/dev/i2c/1’: No such file or directory
寻址:
pi@raspberrypi ~ $ sudo i2cdetect -y 1
打开i2c总线方法:
在终端输入 sudo raspi-config