如何使用 raspi-config 在 Raspberry Pi 上启用 I2C 端口
enable_i2c_nonint.sh
sudo raspi-config nonint do_i2c 0现在加载相关模块:
load_i2c_modules.sh
sudo modprobe "i2c-bcm2835"
sudo modprobe "i2c-dev"
sudo modprobe "rtc-ds1307"现在使用 stat /dev/i2c-1 检查 I2C 设备文件是否存在:
output.txt
$ stat /dev/i2c-1
File: /dev/i2c-1
Size: 0 Blocks: 0 IO Block: 4096 character special file
Device: 5h/5d Inode: 169 Links: 1 Device type: 59,1
Access: (0660/crw-rw----) Uid: ( 0/ root) Gid: ( 998/ i2c)
Access: 2023-03-14 16:23:06.643999999 +0100
Modify: 2023-03-14 16:23:06.643999999 +0100
Change: 2023-03-14 16:23:06.643999999 +0100
Birth: -如果你看到的是
i2c_not_found_error.txt
ls: cannot access '/dev/i2c-1': No such file or directory要么驱动程序没有正确加载,要么 I2C 被禁用。尝试重启系统并重复上述命令,可能还需要检查 dmesg 中的任何错误消息。
Check out similar posts by category:
Raspberry Pi
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow