Skip to main content

serial_weighing_scale: Python API for serial weighing scales based on Arduino+HX711

Project description

Serial Weighing Scale

Arduino-based cheap precision weighing scale for readout via serial communication.


Version: "2.0.4"

Precision weighing scales that include serial port communication usually come at considerable cost. This project showcases an affordable alternative. Using readily available electronics parts, the scale's measurements can be read via serial communication by a simple Python class.

Note: The design could easily be extended with an Arduino display to show the measurements.

Bill of Materials

  • Arduino Uno (including USB-A to USB-B cable)
  • Load cell amplifier HX711 (Sparkfun), e.g. from mouser.co.uk: 474-SEN-13879
  • Load cell (100g and 500g cells used), e.g. from mouser.co.uk: 474-SEN-14727 or 474-SEN-14728
  • Jumper wires, pin headers, nylon spacers for electronics
  • Acrylic or other material of choice for case and load cell mount
  • HX711 arduino library from olkal/HX711_ADC

Build

  1. Load .ino onto Arduino (via Arduino IDE or commandline like arduino --board arduino:avr:uno --port /dev/ttyACM0 --upload serial_scale.ino)
  2. Assemble electronics, e.g. as described in this HX711 wiring tutorial
  3. Print 3D components from drawings (Drawings named model are only for design, no need to print these)
  4. Move electronics into case
  5. Calibrate scale via Arduino IDE serial monitor commands. See below for communication protocol for calibration.

Usage

  1. Connect scale via USB to machine that is going to read the measurements from the scale
  2. Interact via python SerialScale object:
Open connection with SerialWeighingScale object & perform standard operations on it
import numpy as np
import time

from serial_weighing_scale import SerialWeighingScale

serial_port = "/dev/ttyACM0"  # for Unix systems. "COM1" on Windows systems
scale = SerialWeighingScale(serial_port=serial_port)
scale.connect()

while not scale.is_ready:
    time.sleep(.1)

# Perform standard operations
scale.tare()  # Tare scale
scale.read_weight()  # Take single measurement
scale.read_weight_repeated(n_readings=5, inter_read_delay=.1)  # Get n readings
scale.read_weight_reliable(n_readings=5, inter_read_delay=.1, measure=np.mean)  # Get statistic of n readings
Open connection by testing specific serial ports sequentially
from serial_weighing_scale import connect_serial_scale

scale = connect_serial_scale(serial_port_list=["/dev/ttyACM0", "/dev/ttyACM1"])

# ...

Communication protocol for messages between python and Arduino

  • Tare scale: send "t" -> Tare scale & Arduino confirms with "t"

  • Read scale: send "w" -> Arduino returns latest reading

  • Read calibration factor: send "f" -> Arduino returns calibration factor

  • Calibrate scale: send "c" + weight of known mass

    • Arduino confirms by sending known mass value back
    • Send "a" once known mass was placed on scale -> Arduino performs calibration & returns new calibration factor that needs to be added to serial_scale.ino

TODO

  • Add calibration routine to .ino & .py
  • Add test curve to .py

NOTES

  • calibration for first scale with 28.22g weight: -3150
  • calibration for second scale with 28.22g weight: -2894

Contributors

Code & electronics by Lars Rollik. Scale 3D printing drawings by Simon Townsend (Advanced Manufacturing FabLabs, Sainsbury Wellcome Centre). Thanks to Benjamin Hahl for useful input on the design.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serial_weighing_scale-2.0.4.tar.gz (5.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serial_weighing_scale-2.0.4-py3-none-any.whl (5.7 MB view details)

Uploaded Python 3

File details

Details for the file serial_weighing_scale-2.0.4.tar.gz.

File metadata

  • Download URL: serial_weighing_scale-2.0.4.tar.gz
  • Upload date:
  • Size: 5.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for serial_weighing_scale-2.0.4.tar.gz
Algorithm Hash digest
SHA256 514ed7e2bcca0cbcdbe5c1f29480254cbc072bdc56a251dd9b71bcd01abffb11
MD5 217de833f647a77ec9c247e7d97f2a80
BLAKE2b-256 5351c46bf0dd279ad8ee87a5b0972c12306ede8813d17e48c2798bd3cb1b0de7

See more details on using hashes here.

File details

Details for the file serial_weighing_scale-2.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for serial_weighing_scale-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 acdc6a435d84076fd4103299c1b83b57eb9fe43d1b3883938e884f27e6f9094d
MD5 234c7332dcda2dacf9390418856f6d39
BLAKE2b-256 00ccb13d9154d73696a8b2e7b7e7295a795d87914e37360b469af7ec528f230f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page