A digital scale has at least three different questions to answer: where is zero, how much signal represents one gram, and how stable is the answer while the load stays unchanged? Pressing tare answers only the first. This experiment keeps tare, span calibration and later drift separate so a convenient zero does not hide a changing sensor.
Use a SparkFun HX711 Load Cell Amplifier SEN-13879, revision v11, a TAL220B 5 kg straight-bar load cell sold as SparkFun SEN-14729, and an original Raspberry Pi Pico RP2040 with official MicroPython 1.26.0. A load cell converts elastic deformation into a small electrical signal. The HX711 integrated circuit contains an amplifier and an analog-to-digital converter (ADC), which converts that small voltage difference into a signed digital count. Twenty-four output bits do not imply twenty-four useful bits of mass accuracy.
Keep the capacity and board revision attached to the setup
The current SparkFun product page associates SEN-14729 with the 5 kg TAL220B. The linked cell-family datasheet also lists other capacities; that does not make every TAL220B a 5 kg device. Check the order and actual cell marking. Its manufacturer document identifies HTC Sensor and gives four wire functions. Use those exact functions rather than a generic colour convention from another bridge.
A strain gauge changes resistance slightly when stretched. Four gauges form a Wheatstone bridge, two parallel voltage dividers whose midpoint difference changes with strain. Excitation powers the bridge; the ADC observes its differential signal, meaning the voltage of one signal node relative to the other. This is different from connecting a sensor output directly to a Pico analog input.
Obtain a stable mounting base, spacers, a light platform and a documented 200 g reference mass. The demonstration uses loads no greater than 500 g, comfortably below the selected capacity, but mounting stress still matters. Follow the cell’s end markings and mechanical drawing: one mounting end is fixed and the intended loading end can deflect slightly. Bolting the entire beam flat or pulling on its cable bypasses the intended force path.
The cell-family sheet specifies operating excitation of 3–10 V, nominal sensitivity 1 mV/V and a compensated temperature region of −10 to +40°C. The full operating region is wider. Its safe and ultimate overload figures describe mechanical limits, not suggested experiments. Stay with small stationary bench loads and do not drop a mass onto the platform.
Separate analog supply from digital logic

| Pico net | Exact SparkFun board net | Purpose |
|---|---|---|
| USB VBUS, physical 40 | VCC | About 5 V analog/regulator input from the same USB supply. |
| 3V3 OUT, physical 36 | VDD | 3.3 V digital logic supply. |
| GND, physical 38 | GND | Common reference and return. |
| GP2, physical 4, input | DAT | Data-ready and serial data from HX711 DOUT, pin 12. |
| GP3, physical 5, output | SCK | Clock/power-down control to PD_SCK, pin 11. |
USB means Universal Serial Bus. VBUS is its supply rail; it is not a Pico general-purpose signal pin. The selected board’s VDD and VCC are separate nets. Its manufacturer specifically uses VDD to set the controller-side digital level. Do not copy this split-supply connection to a module that joins those rails internally, and never connect the approximately 5 V VCC rail to a Pico input.
Connect the exact cell’s red excitation-positive wire to E+/RED, black excitation-negative to E−/BLK, green signal-positive to A+/GRN and white signal-negative to A−/WHT. The older generic repository colour example differs; the TAL220B datasheet’s named functions control this connection. There is no yellow shield wire on this four-wire cell. Leave the board’s unused shield and channel-B input terminals unconnected.
The board already contains its transistor regulator, supply capacitors, input filtering and clock-rate strap. Its schematic shows 100 nF bypass parts, 10 µF bulk parts, 100 Ω input resistors and a 3.3 µH supply filter. Keep those fitted parts. Leave the rate jumper in its factory closed 10-samples-per-second configuration; opening it changes rate and noise and is not part of this experiment.
Make every connection with USB disconnected. Use short strain-relieved sensor leads and route them away from power switching or moving cables. The wiring picture shows named electrical nodes and chip-pin functions; it does not invent the breakout header’s physical ordering. Check the actual silkscreen and board revision.
Understand the small signal and the available range
The Avia Semiconductor HX711 uses a small-outline, 16-lead package, designated SOP-16L. At gain 128, the operating differential range is ±0.5×AVDD/128. For a conditional 4.3 V analog rail that is approximately ±16.8 mV. The selected cell’s nominal full-load signal would be about 4.3 mV at 1 mV/V excitation sensitivity; at 500 g on a 5 kg cell it would be only about 0.43 mV. Measure the actual excitation rather than treating the regulator arithmetic as a reading.
These signal levels fit the nominal range, but supply range, common-mode limits and mechanical offsets still apply. Common-mode voltage is the shared average voltage of both signal inputs. The datasheet requires both bridge midpoints to remain in its permitted region, not merely their difference to be small. A disconnected bridge can produce plausible counts; software calibration is not proof of electrical integrity.
The manufacturer’s combined-error figure of ±0.05% of full scale corresponds to ±2.5 g for a 5 kg capacity. That arithmetic is not a complete system uncertainty budget or an accuracy guarantee for a breadboard. Likewise, the listed creep bound of ±0.1% full scale per three minutes corresponds to ±5 g under the stated characterization. ADC count resolution cannot erase cell, mounting, reference-mass and temperature errors.
Zero and gain are independent operations
Tare stores the current empty-platform count as an offset. Span calibration then compares that offset with a known applied mass to establish counts per gram. If the empty mean is C0 and the known-mass mean is C1 for mass M, calculate k=(C1−C0)/M and estimated grams=(C−C0)/k. The sign of k can be negative when the mechanical direction or differential polarity reverses; forcing it positive would hide information.

For a synthetic example, C0=1000 counts and C1=201000 counts with M=200 g produce k=1000 counts/g. A later value of 301000 counts would imply 300 g under that calibration. These are deliberately simple arithmetic values. They are not the expected output of the selected physical cell and must not be copied into the observation sheet as measurements.
Each calibration window contains 32 samples and must span no more than 2000 raw counts. That is an application screening criterion, not a manufacturer stability specification or a universal number of grams. The calibration span must have magnitude at least 10000 counts. A failed tare invalidates both old offset and gain; a failed new span invalidates the old gain. The program refuses to keep producing apparently current mass from a failed recalibration.
Complete reader and experiment
Save the listing as scale_lab.py and run its main function on the pinned Pico firmware. The default reference mass is 200 g. If using another documented 20–500 g mass, deliberately change the experiment argument to its actual value before calibration; a software label cannot establish that value for you.
Download the full application (ZIP; file: tricky-circuit-batch007-campaigns63-68/code/pico-hx711-tare-creep.py) · Blank calibration and drift sheet (ZIP; file: tricky-circuit-batch007-campaigns63-68/code/pico-hx711-tare-creep-observations-blank.csv)
"""SparkFun SEN-13879 / TAL220B5kg / original Pico / MicroPython1.26.0.
Host tests verify logic and injected calls, not GPIO pulse timing or calibration.
"""
import math
def signed24(word):
if type(word) is not int or not 0 <= word <= 0xffffff:
raise ValueError('Need a 24-bit word')
if word in (0x800000, 0x7fffff):
raise ValueError('ADC saturation; not a valid weighing result')
return word-(1 << 24) if word & 0x800000 else word
def stable_mean(values):
if len(values) != 32 or any(type(x) is not int or not -8388607 <= x <= 8388606 for x in values):
raise ValueError('Need 32 nonsaturated signed samples')
if max(values)-min(values) > 2000:
raise ValueError('Window is unstable by the chosen 2000-count criterion')
return sum(values)/32
class Scale:
def __init__(self):
self.zero = self.counts_per_g = None
def tare(self, values):
self.zero = self.counts_per_g = None
self.zero = stable_mean(values)
def calibrate(self, values, known_g):
self.counts_per_g = None
if self.zero is None or isinstance(known_g, bool) or not isinstance(known_g, (int,float)) or not math.isfinite(known_g) or not 20 <= known_g <= 500:
raise ValueError('Tare first; use a documented20..500g reference mass')
span = stable_mean(values)-self.zero
if abs(span) < 10000:
raise ValueError('Calibration span too small; inspect mechanics and wiring')
self.counts_per_g = span/known_g
def grams(self, raw):
if self.zero is None or self.counts_per_g is None:
raise ValueError('Mass is unknown until tare and span calibration succeed')
if type(raw) is not int or not -8388607 <= raw <= 8388606:
raise ValueError('Invalid raw count')
return (raw-self.zero)/self.counts_per_g
class HX711:
def __init__(self, data, clock, ticks_us, ticks_diff, sleep_us, sleep_ms,
disable_irq, enable_irq):
self.data,self.clock,self.ticks,self.diff = data,clock,ticks_us,ticks_diff
self.us,self.ms,self.disable,self.enable = sleep_us,sleep_ms,disable_irq,enable_irq
self.failed = False
self.clock(0)
def read(self):
if self.failed:
raise ValueError('ADC session faulted; inspect before restart')
try:
start=self.ticks()
for _ in range(1001):
age=self.diff(self.ticks(),start)
if not 0 <= age <= 1000000:
raise OSError('Ready timeout or clock order')
if self.data()==0:
break
self.ms(1)
else:
raise OSError('Ready sample cap')
word=0
irq=self.disable()
try:
self.us(1)
for n in range(25):
before=self.ticks()
self.clock(1)
try:
self.us(1)
bit=self.data() if n<24 else 0
finally:
self.clock(0)
high_bound=self.diff(self.ticks(),before)
if not 1 <= high_bound <= 50 or bit not in (0,1):
raise OSError('Clock-high timing/read invalid; discard conversion')
if n<24:
word=(word << 1)|bit
self.us(1)
finally:
try:self.clock(0)
finally:self.enable(irq)
if self.data()!=1:
raise OSError("DOUT did not return busy after 25 clocks")
return signed24(word)
except BaseException:
self.failed=True
self.clock(0)
raise
def collect(adc):
adc.read() # Discard a possibly held value from before an operator changed load.
return [adc.read() for _ in range(32)]
def experiment(adc, sleep_ms, ask=input, emit=print, known_g=200):
scale=Scale()
sleep_ms(500)
for _ in range(4):adc.read() # FixedA128 startup discards, not mechanical settling.
ask('Unload the supported platform; wait until still, then press Enter: ')
scale.tare(collect(adc))
ask('Place the documented '+str(known_g)+' g reference mass; wait until still, then press Enter: ')
scale.calibrate(collect(adc),known_g)
emit({'state':'CALIBRATED_BY_ENTERED_MASS','known_g':known_g,
'zero':scale.zero,'counts_per_g':scale.counts_per_g,'hardware_accuracy_verified':False})
ask('Leave the same mass untouched; press Enter for 120 one-second observations: ')
for second in range(120):
adc.read() # Discard held conversion before requesting the next fresh conversion.
raw=adc.read()
emit({'observation':second,'raw':raw,'estimated_g':scale.grams(raw),
'elapsed_time_measured':False})
sleep_ms(1000)
return scale
def main():
from machine import Pin,disable_irq,enable_irq
from time import ticks_us,ticks_diff,sleep_us,sleep_ms
clock=Pin(3,Pin.OUT,value=0)
data=Pin(2,Pin.IN)
adc=HX711(data.value,clock.value,ticks_us,ticks_diff,sleep_us,sleep_ms,disable_irq,enable_irq)
try:
experiment(adc,sleep_ms)
except (OSError,ValueError) as error:
print({'state':'SESSION_FAULT','estimated_g':None,'error':str(error)})
finally:
clock.value(0)
if __name__=='__main__':main()
DOUT stays high while conversion is not ready. The reader waits with a one-second elapsed-time policy and a finite sample cap. Once ready it clocks 24 data bits and one additional pulse, selecting channel A, gain 128 for the next conversion. The signed result is two’s-complement: codes with the highest bit set represent negative values. Both saturation endpoints are refused.
PD_SCK has a documented high-time range of 0.2–50 µs; keeping it high longer than 60 µs powers the chip down. The code requests one-microsecond pauses, suppresses ordinary interrupts during the transfer, bounds the observed software interval around each high pulse and always attempts to return clock low and restore interrupt state. These host-tested calls do not establish a real GPIO waveform. Verify timing on actual hardware before depending on it; an overlong measured interval causes a latched session fault and discarded conversion.
An interrupted or otherwise unknown partial transfer also latches a session fault, including a keyboard interruption. Do not construct another Python object and assume that driving the clock low resets the converter’s bit position. For this lab, disconnect USB so both board supplies power down, inspect the fixture, then reconnect and repeat startup settling and calibration. A deliberately implemented manufacturer power-down/reset sequence is an alternative design; it is not performed by this constructor.
At 10 samples per second, the datasheet gives 400 ms settling after power-up, reset or a channel/gain change. The program allows 500 ms and discards four initial conversions while keeping A128 fixed. Mechanical settling is separate. It also discards a held conversion after each operator pause and before each drift observation, then requests the next conversion. Otherwise a value acquired before placing the mass could contaminate the new calibration window.
The observation index is not an exact elapsed second: the one-second delay is additional to conversion and software work. Record a stopwatch time for any timed creep comparison. The program never automatically tares during those observations. A changed load, thermal drift and mechanical creep can all change the estimate, so name the recorded setup rather than assigning every trend to the chip.
A repeatable sequence
- Record the actual capacity label, board revision, wiring, fixed/load ends, platform mass, room conditions and reference-mass provenance. Inspect the unpowered circuit, then verify separate VCC and VDD rails before running.
- Start with the unloaded supported platform and let it settle. Confirm the prompt refers to the empty setup, then accept tare. Do not hold the platform by hand while it samples.
- Place the documented 200 g mass gently, wait for motion to stop and collect the calibration window. If the span or stability check fails, investigate mounting and wiring instead of repeatedly changing the threshold until a number appears.
- Keep the same mass untouched for the observation run. Record real elapsed time independently and compare the first and last accepted estimates. Do not press tare halfway through to make the drift disappear.
- Remove the mass and inspect the return toward the earlier zero. Then use a different known mass to check the span independently. A two-point fit alone cannot verify a third mass or expose all nonlinearity.
- Repeat after moving only the cable or touching only the base. Record the action and wait for settling. These trials reveal how a scale can be sensitive to the mechanical arrangement as well as the electronics.
The 27 actual-code host tests include signed decoding, clock-count selection, timing-fault cleanup, readiness timeout, stuck-low busy check, wrap-aware clocks, failed calibration invalidation and the full operator/observation sequence. Synthetic values exercise the algorithms; they are not a firmware build or a mass calibration.
Challenge: the 200 g reading drifts upward, so you tare it back to zero. Have you repaired the scale?
No. You changed the offset while the reference mass was still present, erasing the evidence and changing what zero means. Record the original trend, remove the load, inspect the return and repeat a controlled setup. Tare is a declared reference operation, not a diagnosis of creep or gain error.
Primary sources and status
- Exact SparkFun SEN-13879 board and manufacturer revision-v11 schematic.
- Exact SEN-14729 5 kg product and HTC TAL220B family specifications and wire functions.
- Avia HX711 datasheet: operating input conditions, timing, settling, gain selection and saturation.
- Pinned MicroPython machine interface and Pico physical pinout.
Documentation was checked on 20 October 2026. The supplied HX711 PDF is undated; no separate applicable errata notice was located, and a silicon revision was not physically established. Generic colour examples are not a substitute for the selected cell’s documentation. The electronics lessons explain voltage dividers and common ground; this project adds differential strain sensing, a bounded conversion interface and a calibration record.



