private void Button_Click(object sender, RoutedEventArgs e) { /* * How to Calibrate Your Scale: * 1. Call set_scale() with no parameter. * 2. Call tare() with no parameter. * 3. Place a known weight on the scale and call get_units(10). * 4. Divide the result in step 3 to your known weight. You should get about the parameter you need to pass to set_scale. * 5. Adjust the parameter in step 4 until you get an accurate reading. */ if (!inMidCalibration) { txt_results.Text = ""; appendLine("==Calibration==", txt_results); rawNull = hx711b.getRawWeight(AVG_NUM); inMidCalibration = true; appendLine("Now set an object with a known weight, and press 'calibrate' again.", txt_results); //txt_offset.Text = offset.ToString(); } else { float knownWeight = float.Parse(txt_knownWeight.Text); float rawWeight = hx711b.getRawWeight(AVG_NUM); hx711b.setParameters(rawNull, rawWeight, knownWeight); appendLine("", txt_results); appendLine("Your weight scale is", txt_results); appendLine(hx711b.Scale.ToString(), txt_results); appendLine("Your weight offset is", txt_results); appendLine(hx711b.Offset.ToString(), txt_results); txt_scale.Text = hx711b.Scale.ToString(); txt_offset.Text = hx711b.Offset.ToString(); inMidCalibration = false; appendLine("==Done Calibrating==", txt_results); appendLine("==Testing==", txt_results); appendLine("You currenty weighing (should be " + knownWeight.ToString() + "):", txt_results); float rw = hx711b.getWeight(AVG_NUM); appendLine(hx711b.transform(rw).ToString(), txt_results); appendLine("Raw data:", txt_results); appendLine(rw.ToString(), txt_results); } }
public MainPage() { this.InitializeComponent(); gpio = GpioController.GetDefault(); slk = gpio.OpenPin(SLK_PIN); dout = gpio.OpenPin(DOUT_PIN); hx711b = new LinearHX(dout, slk, 128); hx711b.power_down(); Debug.WriteLine("down"); hx711b.power_up(); Debug.WriteLine("up"); hx711b.setParameters(BEST_OFFSET, BEST_SCALE); txt_offset.Text = BEST_OFFSET.ToString(); txt_scale.Text = BEST_SCALE.ToString(); }