无法运行MCP4725示例的默认python代码

2024-04-29 06:20:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在与MCP4725合作。我在这方面做了相当长的时间,没有任何问题,但目前甚至在GitHUb Repository中给出的默认示例也不断抛出此错误

Press Ctrl-C to quit...
Setting voltage to 0!
Traceback (most recent call last):
File "simpletest.py", line 21, in <module>
    dac.set_voltage(0)
File "build/bdist.linux-armv7l/egg/Adafruit_MCP4725/MCP4725.py", line 68, in set_voltage
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 129, in writeList
File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 306, in 
write_i2c_block_data
IOError: [Errno 121] Remote I/O error

我尝试了这个命令i2cdetect -y 1

    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 

我检查了连接,一切都很好。我能得到一些帮助吗


Tags: toinpybuildadafruitegglinuxline
3条回答

问题在于I2C地址。当您使用示例代码时,示例代码中的地址是(0x62),但在您的情况下是(0x60)。所以只需更改此地址,它就会正常工作。 为了您的方便,我提供的代码与我的硬件完美配合

import Adafruit_MCP4725
import time
dac=Adafruit_MCP4725.MCP4725(address=0x60)
try:
  while True:
     for x in range(0,4096,1):
        dac.set_voltage(x)
        vlt=x/4096*5.0
        print(x,vlt)
        time.sleep(1)
except Exception:
  print("issue")
  pass

卸载smbus,然后再次安装Adafruitgpio,然后重试, 不要简单地使用dac。设置电压(0)并尝试使用

for i in range (0,100,1)
  dac.set_voltage(i)

我能够解决这个问题。我将地址更改为0x60,并且用于连接的跳线也有问题。谢谢你的帮助

相关问题 更多 >