def main(): GPIO.setmode(GPIO.BCM) hx = hx711.HX711(dout_pin=5, pd_sck_pin=6) zero_the_scale(hx) calibrate_scale(hx) (tare_weight, total_weight) = get_tare_and_full_weight(hx) plot_reading(hx, tare_weight, total_weight - tare_weight)
""" @file fu.py This file contains a test program for an HX711 Force Unit. """ import hx711 fubar = hx711.HX711(19, 5) fubar.tare() value = fubar.read() value = fubar.get_value() print(value)
from adafruit_pn532.i2c import PN532_I2C # Constants REFERENCE_UNIT = -2053.4638810934416 NFC_PIN_1 = 5 NFC_PIN_2 = 6 NR_SCALE_READS = 5 API_URL = 'ws://89.212.198.159:8000/ws/' # Setup nfc reader i2c = busio.I2C(board.SCL, board.SDA) pn532 = PN532_I2C(i2c) pn532.SAM_configuration() # Setup scale sensor. hx = hx711.HX711(NFC_PIN_1, NFC_PIN_2) hx.set_reading_format("MSB", "MSB") hx.reset() hx.tare() hx.set_reference_unit(REFERENCE_UNIT) # Connect to server with socket async def loop(): async with websockets.connect(API_URL) as sock: while True: # Read tag and weight. uid = pn532.read_passive_target(timeout=0.5) weight = hx.get_weight(NR_SCALE_READS) print(uid, weight)
import sys import hx711 DT = 23 #dt pino no hx711 clk = 24 #clk pino no hx711 GPIO.setwarnings(False) def cleanAndExit(): GPIO.cleanup() sys.exit() hx = hx711.HX711(DT, clk) hx.set_reading_format("LSB", "MSB") hx.set_reference_unit(-57100.26666666644 / 9.45) hx.reset() hx.tare() def getvalue(): val = hx.get_weight(2) hx.power_down() hx.power_up() if (val < 0):
import hx711 as hx import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) num_readings = 10000 hx = hx.HX711( dout_pin=13, pd_sck_pin=19, gain_channel_A=128, select_channel='A') # Get readings def getreadings(nr): readings = [] for i in range(nr): readings.append(hx._read()) print(i) return readings print('reading..') readings = getreadings(num_readings) # Save to textfile f = open("dataset5_totang.py", "a") f.write('data = [') for val in readings: f.write('{}, '.format(val)) f.write(']') f.close()