Interfacing Loadcell and Sparkfun's Qwiic Scale NAU7802 with ESP32

610 Views Asked by At

I am currently working on a IOT Project in which I am trying to interface Loadcell and Sparkfun's Qwiic Scale NAU7802 so that I can read Weight and Show it on Seven Segment Display.

For this I connected Following Pins :-

ESP32 Pin Qwiic Scale Pin
36 (GPIO 22) SCL
33 (GPIO 21) SDA
2 (3V3) 3V3
38 (GND) GND

First I Calibrated my Loadcell with 5 Kg Weight. After that I tried Fetching Weight From Qwiic Scale And Showing it on Seven Segment Display simultaneously using threading.
After Calibrating I placed same 5 kg weight on Loadcell to check readings, But I am getiing variable readings. I tried this loop of calibration and checking the output many many times but my output is still variable. Readings are very Fluctuating, around 50grams for 5kg.

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

Code I used >>

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)))

My Output without using threading >

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

Why does my output is variable, If I implement threading ?

Any Suggestion or help is much appreciated .....
Thanks in Advance...

2

There are 2 best solutions below

2
On

That's quite normal. Load cells create tiny changes in voltage, which get amplified by the chip measuring the H-bridge output. The amplification creates noise which gives you a slightly different reading each time. A fluctuation of less than 0.5% is a rather clean result, by the way. Welcome to measuring things in the real world.

Anyway, round it to about 1% and you're done. The measurement accuracy of cheap bathroom scale load cells won't give you much more resolution anyway.

0
On

I came across this conversation while researching a different problem. I am going to suggest that the noise you see during multi-threading is due to small fluctuations in the supply voltage on the i2c bus to the QwiicScale board which, in turn, would cause a similar variation in V+ to the load cell. Thread switching on your ESP32 may cause a load condition that pushes the limits of the on-board voltage regulator. Digital circuits don't care about a 1% voltage swing but analog circuits would be quite sensitive to that! Try adding a capacitor to the load cell supply voltage line to see if that improves your results.