Interfacing Qwiic Scale with ESP32

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 KgWeight. 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.

Output I got >>

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

Any Suggestion or help is much appreciated …

Thanks in Advance…

Try taking multiple readings and averaging them for a final result.

Output that I showed here is result of averaging it using 256 readings… but still it is variable…

Is it any more stable at no load?

Have you checked the NAU7802 Qwiic Scale with the Arduino library. I don’t own one of those (I have the other OpenScale and it would do what you want so I would believe this one would too), but looking at the https://learn.sparkfun.com/tutorials/qwiic-scale-hookup-guide the Arduino library should give better results than what you showed. My suggestion is to try it with an Arduino, and if you can match the results in the Hookup Guide but you can’t with the ESP and whatever library that is using, then you want to look at the library. One guess; perhaps the library you are using is sampling too fast.