2024-10-16 20:39:13 发布
网友
我在这里重复一个问题的简化版本,我没有得到答复: 我在RaspberryPi 3 Python 3.4上安装了wiringpi。 我可以在raspberrypi命令行下运行wiring命令(如i2cdetect),但无法在Python shell中运行。 我尝试过各种安装和导入,但它似乎没有成为pythonshell认可的模块。 有人能帮忙吗?你知道吗
经过两天的搜索和测试,我找到了最终的解决方案,如here所示。你知道吗
#!/usr/bin/python import smbus bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1) DEVICE_ADDRESS = 0x15 #7 bit address (will be left shifted to add the read write bit) DEVICE_REG_MODE1 = 0x00 DEVICE_REG_LEDOUT0 = 0x1d #Write a single register bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x80) #Write an array of registers ledout_values = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff] bus.write_i2c_block_data(DEVICE_ADDRESS, DEVICE_REG_LEDOUT0, ledout_values) bus.read_byte(DEVICE_ADDRESS)
非常感谢JTech Engineering的贡献!你知道吗
经过两天的搜索和测试,我找到了最终的解决方案,如here所示。你知道吗
问题是python3似乎不支持SMBus(反之亦然),这是标准的Rasbian I2C工具,需要进行复杂的调整才能使其在python3下运行,如所附链接所示。 一旦我完成调整,所有的运行都很好。 SMBus有相对大量的I2C命令用于各种数据类型。 以下是SMBus站点的代码示例:非常感谢JTech Engineering的贡献!你知道吗
相关问题 更多 >
编程相关推荐