因此,我刚开始使用python,并从连接到覆盆子圆周率的称重传感器上改进了我的读数。代码如下:
hx = HX711(5, 6)
hx.set_reading_format("LSB", "MSB")
hx.set_reference_unit(26.978)
hx.reset()
hx.tare()
while True:
for i in range (15):
val = int(hx.get_weight(5))
newval = abs(round((float(val/1000)),1))
X = []
X.append (newval)
print ([X])
hx.power_down()
hx.power_up()我想我会在这个时间范围内得到一个读数列表,也许是4个?但我总能得到一个。数据的出现频率肯定足以构成一个列表,但我的列表始终只有一个数据。
我肯定我做错了什么,请多多指教。
发布于 2018-04-26 23:40:56
我注意到的两件事是错误的:
如果您使用了循环,但没有在任何指令中使用索引,则此for循环位于while循环内。这是没有意义的,所以删除它。
例如:
hx = HX711(5, 6)
hx.set_reading_format("LSB", "MSB")
hx.set_reference_unit(26.978)
hx.reset()
hx.tare()
while True:
X = []
for i in range (15):
val = int(hx.get_weight(5))
newval = abs(round((float(val/1000)),1))
X.append (newval)
hx.power_down()
hx.power_up()
print ([X])将显示一组包含15个值的列表
https://stackoverflow.com/questions/50036292
复制相似问题