Open joelschutz opened 5 years ago
Those updates definitely make sense. But I'd rather add them not to the driver itself (I mean the HX711 class) but to the class Scales(HX711) in the examples/scales.py. My main point is to keep driver's implementation clear from any high-level application code. First of all, the HX711 chip is a 24-Bit Analog-to-Digital Converter (ADC), and building Scales is one of its possible use-cases.
Feel free to implement the code as you wish. Since I'm building a scale this configuration is better for my use. Also I don't have much programing experience and think that some optimization is necessary.
It includes 3 functions to use the hx711 as a weigh scale interface.
self.tare() --> Used to tare the scale and offset it to zero. self.set_scale --> Used to set a custom multiplier to convert the data into mass values self.read_w() --> Used to read the data with multiplier and tare applied for weigh scale applications
Calibration procedure: You will need a known weigh to calibrate the scale. First, use self.tare() to compensate for the weigh of the mounting. Next, put the weigh in the scale and use self.read_w(). Now, divide the output by the weigh and apply it to the self.set_scale('your_number_here'). Remember that some boards don't support floating point numbers, prefer to input a integer number in this cases. After this procedure, the result of self.read_w() will be a float( or integer, depending on set_scale you inputed) of the weigh in the same unit as your calibration weigh.