Exemplo n.º 1
0
        } = WeightUnits.Grams;                                                       // TODO: enter the units of the known-weight you used in calibration

        public MeadowApp()
        {
            Console.WriteLine($"Creating Sensor...");
            using (loadSensor = new Hx711(Device, Device.Pins.D04, Device.Pins.D03))
            {
                if (CalibrationFactor == 0)
                {
                    GetAndDisplayCalibrationUnits(loadSensor);
                }
                else
                {
                    // wait for the ADC to settle
                    Thread.Sleep(500);

                    // Set the current load to be zero
                    loadSensor.SetCalibrationFactor(CalibrationFactor, new Weight(CalibrationWeight, CalibrationWeightUnits));
                    loadSensor.Tare();

                    // start reading
                    while (true)
                    {
                        var c = loadSensor.GetWeight();
                        Console.WriteLine($"Conversion returned {c.StandardValue:0.0} {c.StandardUnits}");
                        Thread.Sleep(1000);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void GetAndDisplayCalibrationUnits(Hx711 sensor)
        {
            // first notify the user we're starting
            Console.WriteLine($"Beginning Calibration. First we'll tare (set a zero).");
            Console.WriteLine($"Make sure scale bed is clear.  Next step in 5 seconds...");
            Thread.Sleep(5000);
            sensor.Tare();
            Console.WriteLine($"Place a known weight on the scale.  Next step in 5 seconds...");
            Thread.Sleep(5000);
            var factor = sensor.CalculateCalibrationFactor();

            Console.WriteLine($"Your scale's Calibration Factor is: {factor}.  Enter this into the code for future use.");
        }