Micropython:ESP32 I2C。 SRF10传感器不返回值
我使用的是连接到ESP32-KIT的SRF10传感器。而使用它来获取数据,仅在给定的电源时才在开始时仅在开始时闪烁。我的代码为以下:
from machine import I2C, Pin
import time
#Distance units
unit_cm = 0x51
i2c = I2C(freq=100000,scl=Pin(18), sda=Pin(19))
address = 0x70 # from the scan
#Sensor range
range_mm = 255
i2c.writeto_mem(address, range_mm, bytearray(2))
#Begin reading
i2c.writeto_mem(address,unit_cm, bytearray(0))
#Reading after measurement
data = i2c.readfrom_mem(address, 0,4)
print(data)
并且印刷的数据为b'\ x05 \ x80 \ x80 \ x00 \ \ x00 \ \ x00 x00。前两个值是有道理的,但是另外两个值应该是距离的数据,总是为零。有什么问题?
I am using a SRF10 sensor connected to a esp32-kit.While using it to acquire data the light only flashes at the beginning when given power.My code is the following:
from machine import I2C, Pin
import time
#Distance units
unit_cm = 0x51
i2c = I2C(freq=100000,scl=Pin(18), sda=Pin(19))
address = 0x70 # from the scan
#Sensor range
range_mm = 255
i2c.writeto_mem(address, range_mm, bytearray(2))
#Begin reading
i2c.writeto_mem(address,unit_cm, bytearray(0))
#Reading after measurement
data = i2c.readfrom_mem(address, 0,4)
print(data)
And the data printed is b'\x05\x80\x00\x00 . The first two values make sense, but the other two, which should be the data of the distances, are always zero. What could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论