Firmware flow
Independent tare routines for two channels
Separate tareChannelA() and tareChannelB() entry points; each selects and zeros its own HX711 channel.
The two tare routines are alternative function entry points. Each selects its own channel, performs the discard read and averages samples into its own stored offset. No runtime channel-selection decision is shown.
The acquisition loop has no timeout. The default scale factors do not establish calibrated weight accuracy.
Read the implementation
Selected firmware excerpt. The diagram explains the code; it is not a hardware test.
Selected source excerpt
// Helpers to select channel and discard the first sample (gain applies to next conversion)
void selectChannelA() {
hx.set_gain(128); // set next conversion to A, gain 128
hx.read(); // dummy read to apply
}
void selectChannelB() {
hx.set_gain(32); // set next conversion to B, gain 32
hx.read(); // dummy read to apply
}
// Read raw average on current channel
long readRawAverage(uint16_t samples) {
long sum = 0;
for (uint16_t i = 0; i < samples; i++) {
while (!hx.is_ready()) { /* wait */ }
sum += hx.read();
}
return (long)( (double)sum / samples );
}
// Per-channel tare
void tareChannelA() {
selectChannelA();
offsetA = readRawAverage(SAMPLES_PER_READ * 3);
}
void tareChannelB() {
selectChannelB();
offsetB = readRawAverage(SAMPLES_PER_READ * 3);
}Technical notes
Channel selection
Channel A is requested at gain 128 and channel B at gain 32. Each selector performs a discard read after changing the gain before the averaging routine is used.
Independent tare routines
tareChannelA() and tareChannelB() are separate entry points. Each selects its own channel, averages 30 samples under the configured sample count and stores the result in that channel's offset.
Acquisition limits
The sample loop waits for the HX711 to become ready without a timeout. Both scale factors remain at 1.0, so separate tare offsets do not establish calibrated weight accuracy.
