Back to engineering archive

Record 092 / Sensing and instrumentation

Dual channel HX711 load cell interface

Two-channel HX711 firmware with separate channel selection and raw tare offsets.

Firmware module
HX711Load cellsChannel selectionTare
Project design or interface view — Dual channel HX711 load cell interface
Project design or interface view — Dual channel HX711 load cell interface

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);
}
ActionRequest A at gain 128 and perform a discard read
ActionRequest B at gain 32 and perform a discard read
ActionWait for and average 30 samplesThe averaging routine waits for readiness before each read.
ActionWait for and average 30 samplesThe averaging routine waits for readiness before each read.
ResultStore the result in offsetA
ResultStore the result in offsetB

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.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project