Raspberry Pi 4 ADS1115 (scl,sda)=(3, 2) 上没有硬件 I2C

问题描述 投票:0回答:1

我正在尝试使用 RPi 4 B 型、ADS1115 和电压传感器进行电压测量。 RPi 运行默认的 Raspbian 系统。系统上安装了Python 3.11。我已经使用 python -m venv ~/.env 创建了虚拟 python 环境(因为否则 adafruit- Circuitpython-ads1x15 不会安装),使用 source ~/.env/bin/activate 激活它,然后安装 adafruit-circlepython- ads1x15 软件包,带有 pip install adafruit- Circuitpython-ads1x15。当我尝试运行这个程序时(真正的程序更大,但这是出现错误的最小程序):

from numpy import interp
import board
import time
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

# Initialize the I2C interface
i2c = busio.I2C(board.SCL, board.SDA)

我收到错误:

(.env) 原型@raspberrypi:~ $ python "/home/prototype/Downloads/RaspberryPiVoltageReporter/TestADS1115Main.py" 回溯(最近一次调用最后一次): 文件“/home/prototype/Downloads/RaspberryPiVoltageReporter/TestADS1115Main.py”,第 9 行,位于 i2c =busio.I2C(板.SCL,板.SDA) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件“/home/prototype/.env/lib/python3.11/site-packages/busio.py”,第 38 行,在 init 中 self.init(scl, sda, 频率) 文件“/home/prototype/.env/lib/python3.11/site-packages/busio.py”,第 168 行,在 init 中 引发值错误( ValueError:(scl,sda)=(3, 2) 上没有硬件 I2C 有效 I2C 端口:((1, 3, 2), (0, 1, 0), (10, 45, 44)) (.env) 原型@raspberrypi:~ $

RPi 和 ADS1115 接线如下:

enter image description here enter image description here

RPi(左)到ADS1115(右)的连接如下: (1)3.3V——电源电压 (3)SDA-SDA (5)SCL——SCL (9)接地-接地

所有电线均经过连续性测试,所有电线均良好。 ADS1115 的 VDD 和 GND 引脚之间有电压。电压为2.4V。据我了解,我们使用 1.5A USB-C 充电器作为电源,因此这就是为什么 3.3V 引脚上只有 2.4V。系统还会向我们发出低电压警告,有时 RPi 会重新启动。这可能是问题所在吗?明天我们将获得足够强大的电源,我们将看看这是否是问题所在,但我觉得不是。我们还使用电池进行了测试,结果相同。根据在线指南,一切似乎都是正确的。像这样的,例如:https://how2 electronics.com/how-to-use-ads1115-16-bit-adc-module-with-raspberry-pi/

另外,我注意到错误中显示:(scl,sda)=(3, 2) 上没有硬件 I2C,但 SCL 和 SDA 引脚分别为 5 和 3:

enter image description here

但我猜它是针对 GPIO 3 和 GPIO 2 的。这里有什么问题吗?是ADS1115坏了还是什么?我可以尝试什么来进一步解决此问题?谢谢你。

raspberry-pi raspberry-pi4
1个回答
0
投票

好的,明白了。我必须在 Raspberry Pi 上启用 I2C 接口,默认情况下禁用该接口:开始 > 首选项 > Raspberry Pi 配置 > 接口选项卡 > I2C > 启用,然后

sudo raspi-config
> 接口选项 > I2C > Enter > 是启用。

这里有一些展示如何做到这一点:

https://www.raspberrypi-spy.co.uk/2014/11/enabling-the-i2c-interface-on-the-raspberry-pi/

https://youtu.be/GSmq8ZH01Sg

我之前查过的一些教程都忽略了这一点。

© www.soinside.com 2019 - 2024. All rights reserved.