Skip to content
Buy 10+ on select items — save 10% auto-applied
Free US shipping on orders $35+
Order by 3pm ET — ships same-day from the US
Worldwide shipping via DHL
Skip to main content

RP2040 Zero HX711 Scale: OLED One-Button Control

November 21, 2026 11 views

RP2040 Zero HX711 Scale: OLED One-Button Control | ShillehTek
Project

Build an RP2040 Zero HX711 digital scale with an SSD1306 OLED and one-button tare, calibration, grams/ounces, and parts counting using ShillehTek parts.

1.5 hr Beginner to Intermediate6 parts

Project Overview

RP2040 Zero Digital Scale with HX711 and OLED: Build a 5 kg kitchen or workbench scale around the RP2040 Zero, an HX711 load cell amplifier, and a 0.96 inch OLED, using the board's BOOT button for the whole interface. A click tares, a double-click switches between grams, ounces, and parts counting, and a long press walks you through calibration that is saved in flash.

  • Time: 1.5 to 2 hours, including the mechanical mount
  • Skill level: Beginner to Intermediate
  • What you will build: A scale with a stable indicator, one-button tare and calibration, grams and ounces, and a counting mode that estimates how many screws, beads, or coins are in a pile based on the weight of ten.
Compact 3D printed electronic scale with a 5 kg load cell under a round platter and a small OLED display
The reference build: a compact 3D-printed scale with a 5 kg load cell under a round acrylic platter, an HX711, and a small OLED, run by one button. This version uses the same one-button idea on an RP2040 Zero.

Parts List

From ShillehTek

External

  • A base and a platter (plywood, acrylic, or 3D-printed), plus screws to fit the load cell's threaded holes and two spacers
  • A known weight for calibration: a 500 g calibration weight, or anything you have weighed on another scale
  • USB-C data cable

Note: The load cell's 5 kg rating is its maximum load, not a promise of accuracy. Expect about a gram of resolution after calibration, and calibrate with a weight close to what you will measure.

Step-by-Step Guide

Step 1 - Mount the load cell

Goal: Let the bar bend only under the load you want to measure.

What to do: Bolt one end of the load cell to the base on a spacer and the other end to the platter on a spacer, so the bar sits in a Z shape and its middle (where the strain gauges are) touches nothing.

Point the arrow on the end of the cell in the direction of the load (down) and use screws short enough that they cannot bottom out against the other plate.

Expected result: Pressing the platter flexes the bar slightly, and nothing rubs or rocks.

Step 2 - Wire the electronics

Goal: Connect the load cell, the HX711, and the OLED to the RP2040 Zero.

What to do: Make these connections:

  • Load cell to HX711: red to E+, black to E-, white to A-, green to A+ (if weights read negative, swap white and green)
  • HX711 VCC to 3V3, GND to GND, DT to GP2, SCK to GP3
  • OLED VCC to 3V3, GND to GND, SDA to GP4, SCL to GP5
Wiring schematic showing an HX711 load cell amplifier and an I2C OLED display connected to a microcontroller
The reference scale's schematic: an HX711 header, one push button, and an I2C OLED. The RP2040 Zero replaces the microcontroller, and its BOOT button replaces the separate switch.

Expected result: Everything runs from the RP2040 Zero's 3.3 V pin, and no extra button is needed.

Step 3 - Set up the RP2040 board package and libraries

Goal: Prepare the Arduino IDE for the RP2040 Zero.

What to do: Add the Raspberry Pi Pico/RP2040 board package by Earle Philhower (add its URL under File → Preferences → Additional boards manager URLs, then install it from the Boards Manager) and select Waveshare RP2040 Zero.

Install HX711 by Bogdan Necula, Adafruit SSD1306, and Adafruit GFX from the Library Manager. This core provides the BOOTSEL keyword for reading the BOOT button and an EEPROM library that stores data in flash.

Expected result: The board appears as a serial port when plugged in. If it does not, hold BOOT while plugging it in and upload once to the drive that appears.

Step 4 - Upload the firmware

Goal: Read the load cell and drive the one-button interface.

What to do: Upload this sketch with the platter empty. It tares itself at power-up, averages eight readings (0.8 s at the HX711's 10 readings per second) for a steady display, and marks the reading STABLE when those eight agree within a gram.

// ShillehTek RP2040 Zero digital scale: HX711 + 5 kg load cell + OLED, run entirely from the BOOT button
// Click = tare, double-click = grams / ounces / piece counting, hold 2 s = calibrate
#include <Wire.h>
#include <EEPROM.h>
#include <HX711.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

const int HX_DT = 2, HX_SCK = 3;            // HX711 data and clock
const int OLED_SDA = 4, OLED_SCL = 5;
const float CAL_WEIGHT_G = 500.0f;          // the known weight you calibrate with
const int SAMPLE_PIECES = 10;               // pieces you place to start counting mode
const unsigned long LONG_PRESS_MS = 2000;
const int AVG = 8;                          // readings averaged for the display (0.8 s)

HX711 scale;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

struct Settings { uint32_t magic; float factor; };
const uint32_t MAGIC = 0x5CA1E24;
Settings cfg = { MAGIC, 420.0f };            // counts per gram, replaced by your calibration

enum Mode { GRAMS, OUNCES, PIECES };
enum State { RUN, CAL_EMPTY, CAL_LOAD, COUNT_SETUP };
enum Btn { NONE, CLICK, DOUBLE, HOLD };
Mode mode = GRAMS;
State state = RUN;
float buf[AVG];
int bufCount = 0, bufHead = 0;
float grams = 0, pieceWeight = 0;
bool stable = false;
unsigned long msgUntil = 0;
const char *msg = "";

Btn readButton() {                           // BOOTSEL is the RP2040 Zero's BOOT button
  static bool down = false, holdSent = false;
  static unsigned long downAt = 0, upAt = 0;
  static int clicks = 0;
  bool pressed = BOOTSEL;
  unsigned long now = millis();
  if (pressed && !down && now - upAt > 30) { down = true; downAt = now; holdSent = false; }
  else if (!pressed && down && now - downAt > 30) { down = false; upAt = now; if (!holdSent) clicks++; }
  if (down && !holdSent && now - downAt >= LONG_PRESS_MS) { holdSent = true; clicks = 0; return HOLD; }
  if (!down && clicks > 0 && now - upAt > 350) { int c = clicks; clicks = 0; return c >= 2 ? DOUBLE : CLICK; }
  return NONE;
}

void flash(const char *text) { msg = text; msgUntil = millis() + 1200; }

void clearAverage() { bufCount = 0; bufHead = 0; }

void doTare() {
  scale.tare(10);
  clearAverage();
  flash("TARE");
}

void saveSettings() {
  EEPROM.put(0, cfg);
  EEPROM.commit();                           // RP2040 keeps "EEPROM" in flash
}

void calibrate(float knownGrams) {
  float counts = scale.get_value(20);        // average of 20 readings, tare removed
  float f = counts / knownGrams;
  if (fabsf(f) < 1.0f) { flash("CAL FAILED"); return; }
  cfg.factor = f;
  scale.set_scale(f);
  saveSettings();
  clearAverage();
  flash("SAVED");
  Serial.printf("New calibration factor: %.3f counts per gram\n", f);
}

void handleButton(Btn b) {
  if (b == NONE) return;
  if (state == RUN) {
    if (b == CLICK) doTare();
    else if (b == DOUBLE) {
      if (mode == GRAMS) mode = OUNCES;
      else if (mode == OUNCES) state = COUNT_SETUP;     // counting needs a sample first
      else mode = GRAMS;
    } else if (b == HOLD) state = CAL_EMPTY;
  } else if (state == CAL_EMPTY && b == CLICK) {
    doTare();
    state = CAL_LOAD;
  } else if (state == CAL_LOAD && b == CLICK) {
    calibrate(CAL_WEIGHT_G);
    state = RUN;
  } else if (state == COUNT_SETUP && b == CLICK) {
    if (grams / SAMPLE_PIECES >= 0.2f) { pieceWeight = grams / SAMPLE_PIECES; mode = PIECES; }
    else { flash("TOO LIGHT"); mode = GRAMS; }
    state = RUN;
  } else if (b == HOLD) {
    state = RUN;                             // hold cancels a setup screen
  }
}

void readScale() {
  if (!scale.is_ready()) return;
  buf[bufHead] = scale.get_units(1);
  bufHead = (bufHead + 1) % AVG;
  if (bufCount < AVG) bufCount++;
  float sum = 0, lo = 1e9, hi = -1e9;
  for (int i = 0; i < bufCount; i++) { sum += buf[i]; lo = min(lo, buf[i]); hi = max(hi, buf[i]); }
  grams = sum / bufCount;
  stable = bufCount == AVG && (hi - lo) < 1.0f;
}

void handleSerial() {                        // optional: t = tare, c 500 = calibrate, ? = status
  if (!Serial.available()) return;
  String line = Serial.readStringUntil('\n');
  line.trim();
  if (line == "t") doTare();
  else if (line.startsWith("c ")) calibrate(line.substring(2).toFloat());
  else if (line == "?") Serial.printf("%.2f g, factor %.3f, %s\n", grams, cfg.factor, stable ? "stable" : "settling");
}

void drawScreen() {
  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setTextSize(1);
  oled.setCursor(0, 0);
  if (state == CAL_EMPTY) { oled.print("CALIBRATE 1/2"); oled.setCursor(0, 24); oled.print("Empty the platform,"); oled.setCursor(0, 36); oled.print("then click"); }
  else if (state == CAL_LOAD) { oled.print("CALIBRATE 2/2"); oled.setCursor(0, 24); oled.print("Place "); oled.print(CAL_WEIGHT_G, 0); oled.print(" g,"); oled.setCursor(0, 36); oled.print("then click"); }
  else if (state == COUNT_SETUP) { oled.print("COUNT MODE"); oled.setCursor(0, 24); oled.print("Place "); oled.print(SAMPLE_PIECES); oled.print(" pieces,"); oled.setCursor(0, 36); oled.print("then click"); }
  else {
    oled.print(mode == GRAMS ? "GRAMS" : mode == OUNCES ? "OUNCES" : "COUNT");
    oled.setCursor(92, 0);
    oled.print(stable ? "STABLE" : "");
    float shown = fabsf(grams) < 0.3f ? 0.0f : grams;    // hide tiny noise around zero
    oled.setTextSize(3);
    oled.setCursor(0, 22);
    if (mode == GRAMS) oled.print(shown, fabsf(shown) < 1000 ? 1 : 0);
    else if (mode == OUNCES) oled.print(shown / 28.3495f, 2);
    else oled.print((long)lroundf(shown / pieceWeight));
    oled.setTextSize(1);
    oled.setCursor(110, 36);
    oled.print(mode == GRAMS ? "g" : mode == OUNCES ? "oz" : "pc");
  }
  if (millis() < msgUntil) { oled.setCursor(0, 56); oled.print(msg); }
  oled.display();
}

void setup() {
  Serial.begin(115200);
  Wire.setSDA(OLED_SDA);
  Wire.setSCL(OLED_SCL);
  Wire.begin();
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("OLED not found at 0x3C");
  EEPROM.begin(256);
  Settings saved;
  EEPROM.get(0, saved);
  if (saved.magic == MAGIC && fabsf(saved.factor) > 1.0f && fabsf(saved.factor) < 1e7f) cfg = saved;
  scale.begin(HX_DT, HX_SCK);
  scale.set_scale(cfg.factor);
  scale.tare(20);                            // start at zero with an empty platform
  Serial.printf("Ready, calibration factor %.3f\n", cfg.factor);
}

void loop() {
  handleButton(readButton());
  handleSerial();
  readScale();
  static unsigned long lastDraw = 0;
  if (millis() - lastDraw >= 100) { lastDraw = millis(); drawScreen(); }
}

Expected result: The OLED shows GRAMS and 0.0 g. The weight is not right yet, because the sketch starts with a default calibration factor.

Step 5 - Calibrate with the BOOT button

Goal: Teach the scale how many HX711 counts make a gram.

What to do: Set CAL_WEIGHT_G to your reference weight before uploading if it is not 500 g. Then:

  • Hold BOOT for two seconds. The screen shows CALIBRATE 1/2.
  • Empty the platform and click. The scale tares.
  • At CALIBRATE 2/2, place the reference weight and click. The sketch averages 20 readings, divides by the weight, applies the new factor and saves it in flash, then shows SAVED.

Prefer typing? Open the Serial Monitor at 115200 baud: t tares, c 500 calibrates with 500 g on the platter, and ? prints the reading and factor.

Because the factor is stored in flash, the scale stays calibrated after power cycles. Keep the BOOT button released while plugging in, or the RP2040 starts in its USB bootloader instead.

Expected result: The reference weight reads its true value, and a second known object confirms it.

Step 6 - Weigh, convert, and count

Goal: Use all three modes.

What to do:

  • Tare: Put a bowl on the platter and click. The display returns to zero.
  • Ounces: Double-click from GRAMS to switch to ounces (1 oz = 28.35 g).
  • Counting: If you use a dish, tare it in grams first. Double-click from OUNCES to start COUNT MODE, place ten identical pieces and click. The scale divides their weight by ten and then shows how many pieces are on the platter. The heavier each piece, the more reliable the count.
  • Double-click once more to return to grams. Holding BOOT on any setup screen cancels it.

Expected result: A scale that switches modes quickly and can count a pile of identical parts based on their weight.

Conclusion

You built an RP2040 Zero digital scale using a 5 kg load cell through an HX711, an averaged and stability-checked reading on the OLED, and a complete interface on the board's BOOT button with tare, units, parts counting, and flash-stored calibration.

Photos and schematic in this tutorial are credited to John Bradnam on Hackster.io, whose Electronic Scales project served as the reference for this version.

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.

Credits

All photos and images in this tutorial are credited to John Bradnam on Hackster.io. The original Electronic Scales project by John Bradnam served as the reference for this ShillehTek version. We thank them for their excellent work in the maker community.

Parts for this build

Everything used in this tutorial. Uncheck what you already have.

4 of 6 in stock
0 parts selected $0.00