from machine import Pin
import time
from hx711 import HX711 # Wokwi's built-in HX711 library
# Initialize HX711 (GPIO5 = DT, GPIO6 = SCK in Wokwi)
hx = HX711(dout_pin=5, pd_sck_pin=6)
# Calibration variables (adjust these in simulation)
zero_offset = 0
calibration_factor = -1000 # Negative because load cells give negative values
def calibrate():
global zero_offset
print("Calibrating... Remove all weight from the load cell")
zero_offset = hx.read()
print(f"Zero offset set to: {zero_offset}")
time.sleep(1)
def read_weight():
raw = hx.read() - zero_offset
weight = raw / calibration_factor # Convert to grams/kg