# Example for micropython.org device, gpio mode
# Connections:
# Pin # | HX711
# ------|-----------
# 12 | data_pin
# 13 | clock_pin
#
from gpio_lcd import GpioLcd
from hx711_gpio import HX711
from machine import Pin
import time
pin_OUT = Pin(26, Pin.IN, pull=Pin.PULL_DOWN)
pin_SCK = Pin(27, Pin.OUT)
pin_yellow = Pin(7, Pin.IN, Pin.PULL_UP) #latch switch side 1
pin_white = Pin(4, Pin.IN, Pin.PULL_UP) #latch switch side
lcd = GpioLcd(rs_pin=Pin(16),
enable_pin=Pin(17),
d4_pin=Pin(18),
d5_pin=Pin(19),
d6_pin=Pin(20),
d7_pin=Pin(21),
num_lines=2, num_columns=16)
hx711 = HX711(pin_SCK, pin_OUT)
hx711.tare(10)
#start serial
print("switch_y, switch_w, raw value")
#loop load cell value read and display
while True:
#value = hx711.read()
#print(value)
raw_value = hx711.get_value()
#Print na and -99 when neither 5kg or 50kg load cell is selected
if pin_yellow.value() == True and pin_white.value() == True:
weight_value_g = -99
raw_value = -99
cell_type = "NA"
#If 5kg load cell is selected, use 5kg calibration coefficient
elif pin_yellow.value() == True and pin_white.value() == False:
#weight_value_g = round((raw_value+2319.4)/418.06, 1)
weight_value_g = round(raw_value/417, 1)
cell_type = "5kg"
#If 50kg load cell is selected, use 50kg calibration coefficient
elif pin_yellow.value() == False and pin_white.value() == True:
#weight_value_g = round((raw_value+567.93)/96.2, 1)
weight_value_g = round(raw_value/97, 1)
cell_type = "50kg"
print(pin_yellow.value(), " , ", pin_white.value(), " , ", raw_value)
#display on lcd
lcd.move_to(0,0)
lcd.clear()
lcd.putstr("(" + cell_type + f")raw: {round(raw_value, 1)}")
lcd.move_to(0,1)
lcd.putstr(f"weight: {weight_value_g} g")
time.sleep(0.5) #pause for lcd refresh