def __init__(self, user, master=None, **kwargs): tk.Frame.__init__(self, master, **kwargs) self.master.title("POSTURE RIGHTING") #lbl = tk.Label(self, text="Please posture righting", height=5, font=("Migu 1M",20)) #lbl.pack() self.refUnit = [2.9, 1] self.f_hx = HX711(5, 6) self.f_hx.set_reading_format("MSB", "MSB") self.b_hx = HX711(23, 24) self.b_hx.set_reading_format("MSB", "MSB") self.f_hx.set_reference_unit(self.refUnit[0]) self.b_hx.set_reference_unit(self.refUnit[1]) self.f_hx.reset() self.b_hx.reset() self.f_hx.tare() self.b_hx.tare() self.posture = ["slouch", "warp"] self.keisu = 100 self.create_widget()
def startLoadCell(sensibilidad, mineral): if (mineral): hx = HX711(4, 17) else: hx = HX711(5, 6) hx.set_reading_format("LSB", "MSB") #Configura el modo de lectura hx.set_reference_unit(sensibilidad) hx.reset() hx.tare() return hx
def init(): global hx711 hx711 = HX711(dout_pin=5, pd_sck_pin=6, channel='A', gain=128) hx711.reset() print("Hey, Load Cell connected!") t_read = threading.Thread(target=read) t_read.start()
def __init__(self): # Set the pins for the scale. Pins are in GPIO.BCM mode self._hx = HX711(5, 6) # Set and initialize the pins for the 2 motors #GPIO.setmode(GPIO.BCM) GPIO.setup(L293D_ENB_PIN, GPIO.OUT) GPIO.setup(L293D_INPUT1_M1_PIN, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(L293D_INPUT2_M1_PIN, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(L293D_INPUT1_M2_PIN, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(L293D_INPUT2_M2_PIN, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(L293D_INPUT1_M3_PIN, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(L293D_INPUT2_M3_PIN, GPIO.OUT, initial=GPIO.LOW) # Set the read in format for first the Pi and then the Hx711 board (MSB/LSB most/least sig bit) self._hx.set_reading_format("MSB", "MSB") # HOW TO CALCULATE THE REFFERENCE UNIT # If 2000 grams is 184000 then 1 gram is 184000 / 2000 = 92. # hx.set_reference_unit(92) # hx.set_reference_unit(calibrateInGrams(self.weight)) self._hx.set_reference_unit(3038) # Reset and tare scale self._hx.reset() self._hx.tare()
def __init__(self, threadID, dispatch, updateDir, tapId=1, commandPin=7, responsePin=8, delay=1, updateVariance=.01, unit="lb", logger=None, scaleRatio=1, tareOffset=0): threading.Thread.__init__(self) self.threadID = threadID self.dispatch = dispatch self.updateDir = updateDir self.tapId = tapId self.commandPin = commandPin self.responsePin = responsePin self.delay = delay self.updateVariance = updateVariance self.unit = unit self.checkTare = False self.shutdown_required = False self.hx711 = HX711(name=threadID, dout_pin=responsePin, pd_sck_pin=commandPin, logger=logger, scale_ratio=scaleRatio, tare_offset=tareOffset)
def test_07_measure_count_validation(self): measure_count_borders = {"min": 3, "max": 10} mapping = { "negative_count": -10, "zero": 0, "to low": measure_count_borders["min"] - 1, "to high": measure_count_borders["max"] + 1 } hx711 = HX711(dout_pin=5, pd_sck_pin=6) hx711.min_measures = measure_count_borders["min"] hx711.max_measures = measure_count_borders["max"] for name, count in mapping.items(): with self.subTest(name): with self.assertRaises(ParameterValidationError): hx711._validate_measure_count(times=count) # randomly pick three valid values and test valid_measure_counts = list( range(measure_count_borders["min"], measure_count_borders["max"] + 1)) random.shuffle(valid_measure_counts) for index in range(1, 4): count = valid_measure_counts[index] with self.subTest( "valid measure count {count} should not raise an error". format(count=count)): try: hx711._validate_measure_count(count) except Exception as exception: self.fail( "{exception} was raised".format(exception=exception))
def __init__(self): # Set the pins for the scale. Pins are in GPIO.BCM mode self._hx = HX711(5, 6) # Set and initialize the pins for the 2 motors GPIO.setup(INPUT1, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(INPUT2, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(INPUT3, GPIO.OUT, initial=GPIO.HIGH) GPIO.setup(INPUT4, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(ENB12, GPIO.OUT) GPIO.setup(ENB34, GPIO.OUT) # Set the read in format for first the Pi and then the Hx711 board (MSB/LSB most/least sig bit) self._hx.set_reading_format("MSB", "MSB") # HOW TO CALCULATE THE REFFERENCE UNIT # If 2000 grams is 184000 then 1 gram is 184000 / 2000 = 92. # hx.set_reference_unit(92) # hx.set_reference_unit(calibrateInGrams(self.weight)) self._hx.set_reference_unit(14550) # Reset and tare scale self._hx.reset() self._hx.tare() print('Tare done!')
def set_tare(channel): hx = HX711(channel[0], channel[1]) hx.set_reading_format('LSB', 'MSB') tare = hx.get_tare() offset.append(tare) print 'initialize {} done!,offset is {}'.format(Channels.index(channel), tare)
def load(): while True: hx711 = HX711(dout_pin=5, pd_sck_pin=6, channel='A', gain=64) hx711.reset() measures = hx711.get_raw_data(num_measures=3) data = "\n".join(measures) params = urllib.urlencode({ 'field1': data, 'key': key }) #put your fieldnumber here headers = { "Content-typZZe": "application/x-www-form-urlencoded", "Accept": "text/plain" } conn = httplib.HTTPConnection("api.thingspeak.com:80") try: conn.request("POST", "/update", params, headers) response = conn.getresponse() print(data) print(response.status, response.reason) data = response.read() conn.close() except: print("connection failed") finally: gpio.cleanup() break
def loadIt(): # GPIO.setmode(GPIO.BCM) # set GPIO pin mode to BCM numbering # Create an object hx which represents your real hx711 chip # Required input parameters are only 'dout_pin' and 'pd_sck_pin' doutS = str(board.D14) pdS = str(board.D15) dout = int(doutS) pd = int(pdS) hx = HX711(dout_pin=dout, pd_sck_pin=pd) # measure tare and save the value as offset for current channel # and gain selected. That means channel A and gain 128 err = hx.zero() print(err) # check if successful if err: raise ValueError('Tare is unsuccessful.') reading = hx.get_raw_data_mean() if reading: # always check if you get correct value or only False # now the value is close to 0 print('Data subtracted by offset but still not converted to units:', reading) else: print('invalid data', reading) return hx
def __init__(self, name, gpio_clk, gpio_dat, scale_value, offset_value, *args, **kwargs): logger.debug(f'HX711 Sensor "{name}" just initialized') self.hx = HX711(gpio_dat, gpio_clk, 128) self.hx.set_scale(scale_value) self.hx.set_offset(offset_value) super().__init__(name, *args, **kwargs)
def init_pin(channel, offset, unit): init_hx = HX711(channel[0], channel[1]) init_hx.set_reading_format('LSB', 'MSB') init_hx.set_reference_unit(unit) init_hx.reset() init_hx.set_offset(offset) HX.append(init_hx)
def configureStrain(): GPIO.setmode(GPIO.BCM) # GPIO BCM numbering (Broadcom SOC channel) hx = HX711(dout_pin=21, pd_sck_pin=20, gain_channel_A=128) # Create an object hx which represents your real hx711 chip # Required input parameters are only 'dout_pin' and 'pd_sck_pin' # If you do not pass any argument 'gain_channel_A' then the default value is 128 # If you do not pass any argument 'set_channel' then the default value is 'A' # you can set a gain for channel A even though you want to currently select channel B err = hx.zero() if err: # you can check if the reset was successful print('not ready') else: print('Ready to use') # Read data several, or only one, time and return mean value # argument "readings" is not required default value is 30 data = hx.get_raw_data_mean(readings=30) if data: # always check if you get correct value or only False print('Raw data:', data) else: print('invalid data') # set scale ratio for particular channel ratio = -395 # data / value [mV/g] hx.set_scale_ratio(ratio) return hx
def CreateLoadSensor(pin1, pin2, refunit): hx = HX711(pin1, pin2) hx.set_reading_format("MSB", "MSB") hx.set_reference_unit(refunit) hx.reset() hx.tare() return hx
def weight_val(): hx = HX711(dout_pin=5, pd_sck_pin=6) # create an object val = hx.get_raw_data_mean() val = int((val + 206000.)/(-961.)) print(val) # get raw data reading from hx711 #GPIO.cleanup() return val
def init(pin1, pin2, id): hx[id] = HX711(pin1, pin2) unit_weight[id] = 0 recent_data[id] = [0] * 10 count[id] = 0 total[id] = 0 flag[id] = 0 # I've found out that, for some reason, the order of the bytes is not always the same between versions of python, numpy and the hx711 itself. # Still need to figure out why does it change. # If you're experiencing super random values, change these values to MSB or LSB until to get more stable values. # There is some code below to debug and log the order of the bits and the bytes. # The first parameter is the order in which the bytes are used to build the "long" value. # The second paramter is the order of the bits inside each byte. # According to the HX711 Datasheet, the second parameter is MSB so you shouldn't need to modify it. hx[id].set_reading_format("LSB", "MSB") # HOW TO CALCULATE THE REFFERENCE UNIT # To set the reference unit to 1. Put 1kg on your sensor or anything you have and know exactly how much it weights. # In this case, 92 is 1 gram because, with 1 as a reference unit I got numbers near 0 without any weight # and I got numbers around 184000 when I added 2kg. So, according to the rule of thirds: # If 2000 grams is 184000 then 1000 grams is 184000 / 2000 = 92. #hx.set_reference_unit(113) hx[id].set_reference_unit(100) hx[id].reset() hx[id].tare()
def startLoadCell(sensibilidad): hx = HX711(19,13) hx.set_reading_format("LSB","MSB") #Configura el modo de lectura hx.set_reference_unit(sensibilidad) hx.reset() hx.tare() return hx
def initialise_load_cell(): load_cell = HX711(loadCellPinDT, loadCellPinSCK) load_cell.set_reading_format("MSB", "MSB") load_cell.set_reference_unit(referenceUnit) load_cell.reset() load_cell.tare() return load_cell
def __init__(self, pin1, pin2, reference_unit): self.hx = HX711(pin1, pin2) self.hx.set_reading_format("LSB", "MSB") self.hx.set_reference_unit(reference_unit) self.hx.reset() self.hx.tare() self.parser = configparser.SafeConfigParser()
def __init__(self): self.powerPin = 17 self.pumpPin = 4 self.scalePin1 = 5 #subject to change. May have multiple scale pins self.scalePin2 = 6 self.timeButton = 19 self.weightButton = 13 self.manualButton = 18 self.powerStatus = False self.pumpStatus = False self.setTime(29) self.setWeight(36) #setup scale self.hx = HX711(self.scalePin1, self.scalePin2) self.hx.set_reading_format("LSB", "MSB") self.hx.set_reference_unit(4030) #Tweak this to tune the scale. self.hx.reset() self.hx.tare() #setup pins for input/output gpio.setWarnings(False) gpio.setup(self.powerPin, gpio.OUT) gpio.setup(self.pumpPin, gpio.OUT) gpio.setup(self.timeButton, gpio.IN, pull_up_down=gpio.PUD_UP) gpio.setup(self.weightButton, gpio.IN, pull_up_down=gpio.PUD_UP) gpio.setup(self.manualButton, gpio.IN, pull_up_down=gpio.PUD_UP) self.forceOff()
def __init__(self, source=None, samples=20, spikes=4, sleep=0.1): self.source = source or HX711() self.samples = samples self.spikes = spikes self.sleep = sleep self.history = []
def __init__(self): try: os.makedirs(tc.weight_raw_path) except FileExistsError: print("Scale raw data dir already exists") threading.Thread.__init__(self) self.running = True self.scale_arrived = False self.weigh_bins = [] self.raw_readings = [] self.min_weight = 1.5 self.max_weight = 5 self.threshold = tc.weight_threshold self.on_scale = False self.off_scale_count = 0 self.increment = (5 - 1.5) / 300 # Set up scale print("connect to scale") self.hx = HX711(5, 6) self.hx.set_reading_format("MSB", "MSB") self.hx.set_reference_unit(tc.reference) # Set reference unit self.hx.power_up() print("reset scale") self.hx.reset() print("tare scale") self.hx.tare() # done setting up scale self.reset_bins()
def main(): # Initialize parameters at t = 0 num_people = 4 # Initialize number of people weight_array = np.zeros(num_people) # Store weights in an array global weight_before weight_before = measure_sink() # Initial weight in sink faces = load_faces(num_people) # Stores template faces for each person names = ["Brooke", "Eric", "Francis", "Nithin"] # Stores names of each person # Initialize load cell hx = HX711(5, 6) hx.set_reading_format("LSB", "MSB") hx.set_reference_unit(92) # Calibrate reference unit to 1g hx.reset() hx.tare() # Initialize Display window = tk.Tk() window.title("Dirty dishes") window.configure(background="black") myFont = tkinter.font.Font(family='Helvetica', size=25, weight="bold") # Iterate for t > 0 update_display() # calls update_data as well window.mainloop()
def weight_initialize(): sensor = HX711(dout, sck) sensor.set_reading_format("MSB", "MSB") sensor.set_reference_unit(calib) sensor.reset() sensor.tare() return (0, sensor)
def init_loadcell(referenceUnit=1): global hx hx = HX711(HX711_DAT, HX711_CLK) hx.set_reading_format("MSB", "MSB") hx.set_reference_unit(referenceUnit) hx.reset()
def obtener(self): import pickle import os import RPi.GPIO as GPIO # import GPIO from hx711 import HX711 # import the class HX711 GPIO.setmode(GPIO.BCM) hx = HX711(dout_pin=5, pd_sck_pin=6) swap_file_name = '/home/pi/git/Raspberry-socket/swap_file.swp' try: if os.path.isfile(swap_file_name): with open(swap_file_name, 'rb') as swap_file: hx = pickle.load(swap_file) peso = int(hx.get_weight_mean(20)) GPIO.cleanup() return peso else: GPIO.cleanup() XD = int(-500) return XD except error: GPIO.cleanup() XD = int(-50) return XD
def pesa(self): led = 21 tempoAcesoLed = 0 LedControle.acende(led, tempoAcesoLed) hx = HX711(29, 31) #hx = HX711(5, 6) hx.set_reading_format("LSB", "MSB") hx.set_reference_unit(-46) hx.reset() hx.tare() try: val = hx.get_weight(5) valInteiro = int(val) print("Valor pego pelo sensor de Peso: ", valInteiro) print("-------------------") hx.power_down() hx.power_up() time.sleep(0.5) LedControle.apaga(led) #Determina quanto vale meio Quilo unidadeMeioQuilo = 180 valInteiro = ( (int(float(valInteiro / unidadeMeioQuilo))) * 500) / 1000 if valInteiro < 0: valInteiro = 0 return (valInteiro) except (KeyboardInterrupt, SystemExit): cleanAndExit()
def setGPIOofProduct(self, product): hx = HX711(int(product.DT), int(product.SCK)) hx.set_reading_format("LSB", "MSB") hx.set_reference_unit(1104) hx.reset() hx.tare() return hx
def initializeHX(dout, pd_sck): hxSensor = HX711(dout, pd_sck) hxSensor.tare() convertUnit = 406.773 / 0.03527396 hxSensor.set_reference_unit(convertUnit) hxSensor.set_reading_format("LSB", "MSB") return hxSensor
def straingauge(): try: GPIO.setmode(GPIO.BCM) bib = HX711(dout_pin=21, pd_sck_pin=20) err = bib.zero() if err: print('Valor invalido') leitura_bruta = bib.get_raw_data_mean() if leitura_bruta == False: raise ValueError('Valor lido errado') leitura = bib.get_data_mean() input( 'Pegue uma carga conhecida e ponha na balança. Pressione ENTER quando posicioanr.' ) try: massa_conhecida = input( 'Digite o valor em gramas da massa conhecida: ') valor = float(massa_conhecida) razão = leitura / valor bib.set_scale_ratio(razão) except ValueError: print('Valor impossibilita cálculo.') while True: print(bib.get_weight_mean()) except (KeyboardInterrupt, SystemError): print('Fim do programa') finally: GPIO.cleanup()