Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 2.74 KB

Meadow.Foundation.Sensors.LoadCell.Hx711.md

File metadata and controls

65 lines (50 loc) · 2.74 KB
uidslug
Meadow.Foundation.Sensors.LoadCell.Hx711
/docs/api/Meadow.Foundation/Meadow.Foundation.Sensors.LoadCell.Hx711
Hx711
Status<img src="https://img.shields.io/badge/Working-brightgreen" style={{ width: "auto", height: "-webkit-fill-available" }} alt="Status badge: working" />
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.LoadCell.Hx711

Code Example

Hx711loadSensor;publicintCalibrationFactor{get;set;}=0;//9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)publicdoubleCalibrationWeight{get;set;}=1.6;// TODO: enter the known-weight (in units below) you used in calibrationpublicoverrideasyncTaskInitialize(){Resolver.Log.Info("Initialize...");loadSensor=newHx711(Device.Pins.D04,Device.Pins.D03);if(CalibrationFactor==0){GetAndDisplayCalibrationUnits(loadSensor);}else{// wait for the ADC to settleawaitTask.Delay(500);// Set the current load to be zeroloadSensor.SetCalibrationFactor(CalibrationFactor,newMass(CalibrationWeight,Mass.UnitType.Grams));loadSensor.Tare();}loadSensor.Updated+=(sender,values)=>Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");}publicoverrideTaskRun(){loadSensor.StartUpdating(TimeSpan.FromSeconds(2));returnTask.CompletedTask;}publicvoidGetAndDisplayCalibrationUnits(Hx711sensor){// first notify the user we're startingResolver.Log.Info($"Beginning Calibration. First we'll tare (set a zero).");Resolver.Log.Info($"Make sure scale bed is clear. Next step in 5 seconds...");Thread.Sleep(5000);sensor.Tare();Resolver.Log.Info($"Place a known weight on the scale. Next step in 5 seconds...");Thread.Sleep(5000);varfactor=sensor.CalculateCalibrationFactor();Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");}

Sample project(s) available on GitHub

close