Micropython:ESP32 I2C。 SRF10传感器不返回值

发布于 2025-02-10 09:31:37 字数 573 浏览 1 评论 0原文

我使用的是连接到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文