我目前正在做一个 IOT 项目,我正在尝试连接Loadcell 和 Sparkfun 的 Qwiic Scale NAU7802,以便我可以读取重量并在七段显示器上显示。
为此,我连接了以下引脚:-
ESP32 引脚 | Qwiic 刻度别针 |
---|---|
36 (GPIO 22) | SCL |
33 (GPIO 21) | SDA |
2(3V3) | 3V3 |
38(接地) | 接地 |
首先,我用5 公斤的重量校准了我的称重传感器。之后我尝试从 Qwiic Scale 获取重量并使用线程同时在七段显示器上显示它。
校准后,我在称重传感器上放置了相同 的5 kg重量以检查读数,但我正在获取可变读数。我尝试了这个校准循环并多次检查输出,但我的输出仍然是可变的。读数波动很大,5公斤约50克。
4.985
5.015
4.965
4.99
5.025
5.04
5.025
5.025
5.025
4.995
5.025
5.01
4.99
5.01
5.01
5.05
4.99
5.03
4.985
5.015
5.015
5.015
4.995
4.96
5.01
5.01
4.995
4.995
4.995
4.995
4.995
5.015
4.985
5.0
5.0
5.025
5.04
4.985
5.01
5.025
5.025
5.045
5.03
5.005
5.005
5.005
5.005
5.025
5.005
5.005
4.975
5.025
5.045
5.005
我使用的代码>>
scale = QwiicScale() # Created Qwiic Scale Object
s = SevenSegment(scale) # Created Seven Segment Object
# Calibration code
OF = scale.getZeroOffsetFromQwiic() # Get Offset From Loadcell without putting any weight
# Place Known Weight
KnownWeight = float(input('Enter Known Weight : ')) # Take input known Weight
cal = scale.getCalibrationFactorFromQwiic(KnownWeight) # Calculate Calibration Factor
#Created Thread for showing weight on Seven Segment Display
SevenSegmentThread = Thread(target=s.ShowOnSevenSegment)
SevenSegmentThread.start() #ran that thread here
# Loop continuously running to get weight and setting it to Seven Segment
while KeyboardInterrupt:
Weight = float(scale.getWeightFromQwiicScale())
print(Weight)
Weight = str(int(Weight*1000))
s.SetWeight(''.join(reversed(Weight)))
我的输出没有使用线程 >
4.995
4.995
4.995
4.995
4.995
4.995
4.995
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
5.01
如果我实现线程,为什么我的输出是可变的?
非常感谢任何建议或帮助......
在此先感谢......