nanoFramework.Iot.Device.Hx711 1.1.907

Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Hx711 --version 1.1.907
                    
NuGet\Install-Package nanoFramework.Iot.Device.Hx711 -Version 1.1.907
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.Hx711" Version="1.1.907" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.Iot.Device.Hx711" Version="1.1.907" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Hx711" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.Iot.Device.Hx711 --version 1.1.907
                    
#r "nuget: nanoFramework.Iot.Device.Hx711, 1.1.907"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package nanoFramework.Iot.Device.Hx711@1.1.907
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nanoFramework.Iot.Device.Hx711&version=1.1.907
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Hx711&version=1.1.907
                    
Install as a Cake Tool

Hx711 (M5Stack WEIGHT)

This is a library to interact with the Hx711 ADC. This is conveniently assembled and package in the M5Stack WEIGHT module.

weight_05.png

Documentation

  • The module documentation can be found here.
  • Datasheet for the Hx711 ADC can be found here.

Usage

Signals and connections

Check the connections for the WEIGTH module at the product page. From the schematic one can see these signals:

  • DOUT: Grove connector pin 1
  • PDSCK: Grove connector pin 2

Our code is using SPI to generate the clock signals and read back data from the HX711, so the connections need to match the SPI signals like this:

  • MOSI → PDSCK
  • MISO → DOUT

SPI clock is not used so feel free to route to an unused GPIO. There is also no need for the CS signal so no need to define a pin for it.

Important: make sure you setup the SPI pins for ESP32 before creating the Scale. For this, make sure you install the nanoFramework.Hardware.ESP32 NuGet.

///////////////////////////////////////////////////////////////////////
// When connecting to an ESP32 device, need to configure the SPI GPIOs
// The following mapping is used in order to connect the WEIGTH module
// to a M5Core device using the Grove port A
// MOSI: connects to WEIGHT Grove pin 2
// MISO: connects to WEIGHT Grove pin 1
// CLOCK: connect to any free port as it's not used at all
Configuration.SetPinFunction(21, DeviceFunction.SPI1_MOSI);
Configuration.SetPinFunction(22, DeviceFunction.SPI1_MISO);
Configuration.SetPinFunction(23, DeviceFunction.SPI1_CLOCK);

Warning Make sure to follow the instructions above. At first glance they can look contrary to the naming of the signals and schematics in M5Stack documentation. That's because the GROVE connectors are meant to use I2C and their implementation of the driver is different from ours.

For other devices, like STM32, please make sure you're using the pins for the UART you want to use.

Configuring SPI

// setup SPI connection settings
// the clock value was adjusted in order to get the typical duration expected by the PD_SCK ~1us
var spisettings = new SpiConnectionSettings(1)
{
    ClockFrequency = Scale.DefaultClockFrequency
};

// create SPI device
var spidev = SpiDevice.Create(spisettings);

// create scale
var scale = new Scale(spidev);

The scale class is very simple to use and offers some configurations. Let's explore the most common usage scenarios.

Taring a scale

Taring is used to exclude a measurement from the total weight given by the scale. Most commonly, this function is used to negate the weight of the container or other elements attached to the scale.

// set scale tare to get accurate readings
scale.Tare();

Reading the weight

To take a reading of the weight on the load cell just need to call Read. The following code snippet will read the weight continuously and output the value to the output pane.


// loop forever outputting the current reading
while (true)
{
    var reading = scale.Read();

    Console.WriteLine($"Weight: {reading}");

    Thread.Sleep(2_000);
}

Settings and configurations

The library exposes several configurations. Please explore the documentation here.

Acknowledgments

The development of this library was kindly sponsored by greenYng!

greenyng-logo.png

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.907 166 10/2/2025
1.1.864 273 4/2/2025
1.1.852 284 3/11/2025
1.1.822 216 2/26/2025
1.1.775 196 2/4/2025
1.1.772 187 2/4/2025
1.1.759 202 1/31/2025
1.1.755 176 1/31/2025
1.1.737 192 1/13/2025
1.1.696 214 12/16/2024
1.1.685 180 12/4/2024
1.1.673 215 10/23/2024
1.1.631 195 8/28/2024
1.1.595 199 7/24/2024
1.1.570 210 6/14/2024
1.1.560 191 5/29/2024
1.1.548 185 5/15/2024
1.1.436 344 11/10/2023
1.1.384 306 9/6/2023
1.1.329 273 5/26/2023
1.1.313 283 5/12/2023
1.1.297 306 5/3/2023
1.1.253 391 2/22/2023
1.1.203 449 12/28/2022
1.1.141 535 10/25/2022
1.1.128 496 10/22/2022
1.1.122 558 10/12/2022
1.1.114 537 10/8/2022
1.1.95 550 9/22/2022
1.1.87 618 9/15/2022
1.1.73 528 9/8/2022
1.1.35 543 8/4/2022
1.1.5 558 7/13/2022
1.0.86.41205 549 7/6/2022
1.0.58.2032 567 6/23/2022
1.0.54.32999 558 6/16/2022
1.0.50.47843 548 6/15/2022
1.0.4.7661 551 5/24/2022
1.0.3.10097 553 5/23/2022
1.0.1.10218 552 5/23/2022