Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = 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
Syntax
public class Hx711 : PollingSensorBase<Mass>, IObservable<IChangeResult<Mass>>, IMassSensor, ISamplingSensor<Mass>, ISensor<Mass>, IDisposable
Constructors
Hx711(IDigitalOutputPort, IDigitalInputPort, uint?)
Creates an instance of the Hx711 Driver class
Declaration
public Hx711(IDigitalOutputPort sck, IDigitalInputPort dout, uint? tareValue = null)
Parameters
Type | Name | Description |
---|---|---|
IDigitalOutputPort | sck | |
IDigitalInputPort | dout | |
uint? | tareValue |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Hx711(IPin, IPin, uint?)
Creates an instance of the Hx711 Driver class
Declaration
public Hx711(IPin sck, IPin dout, uint? tareValue = null)
Parameters
Type | Name | Description |
---|---|---|
IPin | sck | Serial clock pin |
IPin | dout | Digital output pin |
uint? | tareValue | Tare value threshold |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Properties
DefaultSamplePeriod
Gets default sample period (1 Second)
Declaration
public TimeSpan DefaultSamplePeriod { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Gain
24-Bit Dual-Channel ADC For Bridge Sensors
Declaration
public Hx711.AdcGain Gain { get; }
Property Value
Type | Description |
---|---|
Hx711.AdcGain |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
IsDisposed
Is the peripheral disposed
Declaration
public bool IsDisposed { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
IsSleeping
Is the peripheral sleeping
Declaration
public bool IsSleeping { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Mass
The last read Mass
Declaration
public Mass? Mass { get; }
Property Value
Type | Description |
---|---|
Mass? |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
TareValue
Gets/Sets Tare value
Declaration
public uint TareValue { get; set; }
Property Value
Type | Description |
---|---|
uint |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Methods
CalculateCalibrationFactor()
Calculates the calibration factor of the load cell. Call this method with a known weight on the sensor, and then use the returned value in a call to SetCalibrationFactor(int, Mass) before using the sensor.
Declaration
public int CalculateCalibrationFactor()
Returns
Type | Description |
---|---|
int |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Dispose(bool)
Dispose of the object
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Is disposing |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
RaiseEventsAndNotify(IChangeResult<Mass>)
Inheritance-safe way to raise events and notify observers.
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<Mass> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<Mass> | changeResult |
Overrides
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
ReadSensor()
Gets the current sensor weight
Declaration
protected override Task<Mass> ReadSensor()
Returns
Type | Description |
---|---|
Task<Mass> |
Overrides
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
SetCalibrationFactor(int, Mass)
Sets the sensor's calibration factor based on a factor calculated with a know weight by calling CalculateCalibrationFactor().
Declaration
public void SetCalibrationFactor(int factor, Mass knownValue)
Parameters
Type | Name | Description |
---|---|---|
int | factor | |
Mass | knownValue |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Sleep()
Puts the device into low-power sleep mode
Declaration
public void Sleep()
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Tare()
Tares the sensor, effectively setting the current weight reading to relative zero.
Declaration
public void Tare()
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Wake()
Takes the device out of low-power sleep mode
Declaration
public void Wake()
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}
Events
MassUpdated
Mass changed event
Declaration
public event EventHandler<IChangeResult<Mass>> MassUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Mass>> |
Remarks
Hx711 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
Hx711 loadSensor;
public int CalibrationFactor { get; set; } = 0; //9834945 - 8458935; // TODO: change this based on your scale (using the method provided below)
public double CalibrationWeight { get; set; } = 1.6; // TODO: enter the known-weight (in units below) you used in calibration
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
loadSensor = new Hx711(Device.Pins.D04, Device.Pins.D03);
if (CalibrationFactor == 0)
{
GetAndDisplayCalibrationUnits(loadSensor);
}
else
{ // wait for the ADC to settle
await Task.Delay(500);
// Set the current load to be zero
loadSensor.SetCalibrationFactor(CalibrationFactor, new Mass(CalibrationWeight, Mass.UnitType.Grams));
loadSensor.Tare();
}
loadSensor.MassUpdated += (sender, values) => Resolver.Log.Info($"Mass is now returned {values.New.Grams:N2}g");
}
public override Task Run()
{
loadSensor.StartUpdating(TimeSpan.FromSeconds(2));
return Task.CompletedTask;
}
public void GetAndDisplayCalibrationUnits(Hx711 sensor)
{ // first notify the user we're starting
Resolver.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);
var factor = sensor.CalculateCalibrationFactor();
Resolver.Log.Info($"Your scale's Calibration Factor is: {factor}. Enter this into the code for future use.");
}