### Example HX711 Scale Values for Load Cells Source: https://github.com/robtillaart/hx711/blob/master/README.md Provides example `set_scale()` values that have worked well for specific 5 KG and 20 KG load cells. Users are advised to use the `calibrate` function to determine their own optimal values. ```C++ scale.set_scale(420.52); scale.set_scale(127.15); ``` -------------------------------- ### HX711 Gain and Channel Control API Source: https://github.com/robtillaart/hx711/blob/master/README.md This section details functions for controlling the gain and selecting the channel of the HX711. It explains the available gain constants and the `set_gain` function, along with important warnings regarding its reliability and usage in `setup()`. ```APIDOC Constants: HX711_CHANNEL_A_GAIN_128 = 128 description: Default gain for Channel A. HX711_CHANNEL_A_GAIN_64 = 64 description: Gain for Channel A. HX711_CHANNEL_B_GAIN_32 = 32 description: Fixed gain for Channel B. set_gain(gain: uint8_t = 128, forced: bool = false) -> bool description: Sets the gain and selects the channel. Invalid gain values will not change the channel/gain. If 'forced' is true, it explicitly tries to set the gain/channel again, including a dummy read. parameters: gain: The desired gain value (128, 64, or 32, defaults to 128). forced: If true, forces the gain setting even if the library thinks it's already set (defaults to false). returns: True if gain was set, false otherwise (e.g., invalid gain value). get_gain() -> uint8_t description: Returns the currently set gain value. returns: The current gain (128, 64, or 32). ``` -------------------------------- ### HX711 Constructor and Initialization API Source: https://github.com/robtillaart/hx711/blob/master/README.md This section describes the constructors and initialization functions for the HX711 library. It covers object creation, resource cleanup, and setting up the communication pins with an optional fast processing mode. ```APIDOC HX711() description: Default constructor for the HX711 object. ~HX711() description: Destructor for the HX711 object. begin(dataPin: uint8_t, clockPin: uint8_t, fastProcessor: bool = false) description: Initializes the HX711 connection. Sets a fixed gain of 128. The fastProcessor option adds a 1 uS delay for each clock half-cycle to ensure timing greater than 200 nS. parameters: dataPin: The data pin connected to the HX711. clockPin: The clock pin connected to the HX711. fastProcessor: Optional flag to enable fast processor mode (defaults to false). reset() description: Resets the internal state of the HX711 to its start condition. As of version 0.3.4, this also performs a power down/up cycle. ``` -------------------------------- ### HX711 Library Main Flow and Calibration API Source: https://github.com/robtillaart/hx711/blob/master/README.md This section outlines the primary sequence of operations for using the HX711 library, focusing on initialization and calibration. It details the functions for establishing connection, setting the zero point, and determining the scale factor based on known weights. ```APIDOC begin(dataPin: uint8_t, clockPin: uint8_t) description: Initializes connection to the HX711. parameters: dataPin: The data pin connected to the HX711. clockPin: The clock pin connected to the HX711. tare() description: Measures and sets the zero point offset of the scale. set_scale(factor: float) description: Sets a known conversion factor for the scale, typically loaded from EEPROM. parameters: factor: The conversion factor to apply. calibrate_scale(weight: float, times: uint8_t) description: Determines the scale factor based on a known weight. The units used for 'weight' will be returned by get_units(). parameters: weight: A known weight placed on the scale (e.g., in grams). times: Number of readings to average for calibration. get_units() description: Returns the units used during the last calibrate_scale() call. ``` -------------------------------- ### HX711 Pricing API Source: https://github.com/robtillaart/hx711/blob/master/README.md Describes experimental functions for integrating pricing calculations with weight measurements. These functions allow setting and retrieving a unit price and calculating the total price based on weight. Their inclusion in the library is currently under discussion. ```APIDOC float get_price(uint8_t times = 1) void set_unit_price(float price = 1.0) float get_unit_price() ``` -------------------------------- ### HX711 Millivolt Conversion Calibration Procedure Source: https://github.com/robtillaart/hx711/blob/master/README.md Outlines an experimental procedure to configure the HX711 as a millivolt meter. This involves applying known millivolt values, taring the zero point, and calibrating the scale to map raw readings to microvolts. The `get_units()` function then returns microvolts. ```APIDOC Apply 0.000 mV to the system. Call tare(times) to calibrate the zero point. Then apply 20.000 mV to the system. Call calibrate_scale(20000) to map the raw reading to 20000 µV = 20 mV. float get_units(uint8_t times = 1) will return microvolts. ``` -------------------------------- ### HX711 Arduino Library API Reference Source: https://github.com/robtillaart/hx711/blob/master/keywords.txt Comprehensive list of data types, methods, and constants available in the HX711 Arduino library. This reference details the core components for interacting with the HX711 load cell amplifier, including functions for reading values, setting parameters, and managing power states. ```APIDOC HX711 Library API Reference Data Types: HX711 Methods and Functions: begin(): void reset(): void is_ready(): bool wait_ready(): void wait_ready_retry(retries: int): bool wait_ready_timeout(timeout: long): bool read(): long read_average(times: int): long read_median(times: int): long read_medavg(times: int): long read_runavg(times: int): long get_value(times: int): float get_units(times: int): float set_raw_mode(): void set_average_mode(): void set_median_mode(): void set_medavg_mode(): void set_runavg_mode(): void get_mode(): int tare(times: int): void get_tare(): float tare_set(offset: long): void set_gain(gain: int): void get_gain(): int set_scale(scale: float): void get_scale(): float set_offset(offset: long): void get_offset(): long calibrate_scale(known_weight: float, times: int): float power_down(): void power_up(): void last_read(): long get_price(value: float): float set_unit_price(price: float): void get_unit_price(): float Constants: HX711_LIB_VERSION: string HX711_RAW_MODE: int HX711_AVERAGE_MODE: int HX711_MEDIAN_MODE: int HX711_MEDAVG_MODE: int HX711_RUNAVG_MODE: int HX711_CHANNEL_A_GAIN_128: int HX711_CHANNEL_A_GAIN_64: int HX711_CHANNEL_B_GAIN_32: int ``` -------------------------------- ### Include HX711 Library Header (C++) Source: https://github.com/robtillaart/hx711/blob/master/README.md This snippet shows the standard C++ include directive required to incorporate the HX711 library into an Arduino project. It makes all the library's functions and classes available for use. ```cpp #include "HX711.h" ``` -------------------------------- ### HX711 Ready State Check API Source: https://github.com/robtillaart/hx711/blob/master/README.md This section details functions for checking the HX711's readiness for a new measurement. It provides options for immediate checks, blocking waits, and waits with retries or timeouts. ```APIDOC is_ready() -> bool description: Checks if the load cell is ready to provide a new reading. returns: True if ready, false otherwise. wait_ready(ms: uint32_t = 0) -> void description: Waits until the HX711 is ready, checking every 'ms' milliseconds. If 'ms' is 0, it waits indefinitely. parameters: ms: The delay in milliseconds between checks (defaults to 0 for blocking wait). wait_ready_retry(retries: uint8_t = 3, ms: uint32_t = 0) -> bool description: Waits for the HX711 to be ready, with a maximum number of retries. parameters: retries: The maximum number of attempts to check for readiness (defaults to 3). ms: The delay in milliseconds between checks (defaults to 0). returns: True if ready within retries, false otherwise. wait_ready_timeout(timeout: uint32_t = 1000, ms: uint32_t = 0) -> bool description: Waits for the HX711 to be ready, with a maximum timeout duration. parameters: timeout: The maximum time in milliseconds to wait (defaults to 1000). ms: The delay in milliseconds between checks (defaults to 0). returns: True if ready within timeout, false otherwise. ``` -------------------------------- ### HX711 Weight Calculation Formula Source: https://github.com/robtillaart/hx711/blob/master/README.md Explains the fundamental formula used by the HX711 library to calculate weight based on raw readings, scale factor, and tare value. It highlights the `get_scale()` and `get_tare()` functions as key parameters for interpolation and calibration. ```APIDOC Weight = get_scale() x raw + get_tare() ``` -------------------------------- ### Multiple HX711 Modules with Shared CLK Line Considerations Source: https://github.com/robtillaart/hx711/blob/master/README.md Discusses the implications of sharing the CLK line among multiple HX711 modules. It highlights side effects such as all modules resetting to channel A and gain 128 after power-down, and potential state mismatches if individual modules call `powerDown()` or `reset()`. ```APIDOC The CLK is used to select channel and to select gain for the NEXT sample. The CLK is used for power down. After wake up after power down all HX711's will reset to channel A and gain 128. WARNING: if one of the objects does a powerDown() or reset() it resets its internal states. The other objects however won't reset their internal state, so a mismatch can occur. WARNING: Sharing the data lines is NOT possible as it could cause short circuit. ``` -------------------------------- ### HX711 Tare and Calibration Procedures Source: https://github.com/robtillaart/hx711/blob/master/README.md This section outlines the process for calibrating the HX711 sensor, including taring (setting the zero point) and calculating the scale factor. The calibration process involves clearing the scale, taring, placing a known weight, and then calling `calibrate_scale()` to determine the scale factor. The units used during calibration will be returned by `get_units()`. The `calibrate_scale()` function uses averaging and does not rely on the currently set read mode. It's important to calibrate with a weight within the expected measurement range and at the anticipated operating temperature. A 'tare' can also be set with a fixed load, but users must ensure the combined fixed and variable load does not exceed the load cell's maximum capacity. ```APIDOC Calibration Steps: 1. Clear the scale. 2. Call tare() to determine and set the zero weight offset. 3. Put a known weight on the scale. 4. Call calibrate_scale(float weight) with the known weight. 5. The scale factor is calculated. 6. Save the offset and scale for later use (e.g., EEPROM). Functions: void tare(uint8_t times = 10) Description: Determines and sets the zero (reference) level offset by averaging measurements. Parameters: times: Number of measurements for averaging the tare value. float get_tare() Description: Returns the calculated tare value (offset * scale). Note: This value changes after calls to calibrate_scale(). Use get_offset() for the raw offset. Returns: The tare value as a float. bool tare_set() Description: Checks if a tare has been set (assumes offset is not zero). Returns: true if tare is set, false otherwise. void calibrate_scale(float weight, uint8_t times = 10) Description: Calculates the scale factor based on a known weight. The weight can be in any unit, and this unit will be used by get_units(). Uses averaging for accuracy. Parameters: weight: The known calibration weight (float, allows decimals and larger ranges). Can be negative. times: Number of measurements for averaging the calibration weight. ``` -------------------------------- ### HX711 Data Read API Source: https://github.com/robtillaart/hx711/blob/master/README.md This section describes various methods for reading data from the HX711. It includes raw readings, averaged readings, median-filtered readings, and running averages, providing flexibility for different measurement needs. ```APIDOC read() -> float description: Performs a raw reading from the HX711. returns: The raw float value from the ADC. read_average(times: uint8_t = 10) -> float description: Reads the average of multiple raw readings. parameters: times: The number of raw readings to average (must be 1 or more, defaults to 10). returns: The averaged float value. read_median(times: uint8_t = 7) -> float description: Reads the median of multiple raw readings. parameters: times: The number of raw readings for median calculation (odd numbers preferred, 3-15, defaults to 7). returns: The median float value. read_medavg(times: uint8_t = 7) -> float description: Reads the average of the "middle half" of multiple raw readings. parameters: times: The number of raw readings (odd numbers preferred, 3-15, defaults to 7). returns: The averaged float value of the middle half. read_runavg(times: uint8_t = 7, alpha: float = 0.5) -> float description: Calculates a running average over multiple measurements. parameters: times: The number of measurements to include in the running average (>= 1, defaults to 7). alpha: The weight factor for the running average (between 0 and 1, defaults to 0.5). returns: The running averaged float value. last_read() -> uint32_t description: Returns the timestamp in milliseconds of the last successful read operation. returns: Timestamp in milliseconds. ``` -------------------------------- ### HX711 Value Retrieval and Scaling Source: https://github.com/robtillaart/hx711/blob/master/README.md Functions to retrieve corrected weight values from the HX711 sensor, adjusted for offset and scale. This section also covers methods for setting and retrieving the scale factor and offset, which are crucial for accurate measurements. In `HX711_RAW_MODE`, the `times` parameter for `get_value()` and `get_units()` is ignored. ```APIDOC Functions: float get_value(uint8_t times = 1) Description: Reads a value from the HX711, corrected for offset. Parameters: times: Number of measurements to average (ignored in HX711_RAW_MODE). Returns: The corrected value as a float. float get_units(uint8_t times = 1) Description: Reads a value from the HX711, converted to proper units based on the set scale. Parameters: times: Number of measurements to average (ignored in HX711_RAW_MODE). Returns: The value in calibrated units as a float. bool set_scale(float scale = 1.0) Description: Sets the scale factor for unit conversion. Parameters: scale: The scale factor, typically a positive number > 50. Can be negative for specific applications. Returns: true if scale is successfully set (not 0), false otherwise. float get_scale() Description: Returns the currently set scale factor. Returns: The scale factor as a float. void set_offset(int32_t offset = 0) Description: Sets the raw offset value. Parameters: offset: The raw offset value. int32_t get_offset() Description: Returns the currently set raw offset value. Returns: The offset as an int32_t. ``` -------------------------------- ### HX711 Read Mode Configuration Source: https://github.com/robtillaart/hx711/blob/master/README.md This section defines the operational modes for reading values from the HX711 sensor, affecting how `get_value()` and `get_units()` behave. It includes constants for various modes and functions to set or retrieve the current mode. Note that `HX711_MEDIAN_MODE` and `HX711_MEDAVG_MODE` are limited to 3-15 samples to conserve memory. ```APIDOC Constants: HX711_RAW_MODE HX711_AVERAGE_MODE HX711_MEDIAN_MODE HX711_MEDAVG_MODE HX711_RUNAVG_MODE Functions: void set_raw_mode() Description: Sets the read mode to raw, calling read() only once. void set_average_mode() Description: Sets the read mode to average, taking the average of 'n' measurements. void set_median_mode() Description: Sets the read mode to median, taking the median of 'n' measurements. void set_medavg_mode() Description: Sets the read mode to median average, taking the average of n/2 median measurements. void set_runavg_mode() Description: Sets the read mode to running average (default alpha = 0.5). uint8_t get_mode() Description: Returns the current operational mode. Default is HX711_AVERAGE_MODE. ``` -------------------------------- ### HX711 Adding Scale API Source: https://github.com/robtillaart/hx711/blob/master/README.md Functions for managing an adding scale feature, allowing to clear, add, and retrieve weight values. These functions are intended to simplify cumulative weight measurements. ```APIDOC void weight_clr() void weight_add() float weight_get() ``` -------------------------------- ### HX711 Rate Control API Source: https://github.com/robtillaart/hx711/blob/master/README.md Functions to configure and query the data acquisition rate (SPS - Samples Per Second) of the HX711 sensor. This includes setting a dedicated pin for rate selection and retrieving the current rate. ```APIDOC void setRatePin(uint8_t pin) - sets the IO pin for rate selection. bool setRate(uint8_t sps) - rate = 10 or 80 SPS, returns false on incorrect input uint8_t getRate() - returns 10 or 80 ``` -------------------------------- ### HX711 Power Management API Source: https://github.com/robtillaart/hx711/blob/master/README.md Documents the API functions for controlling the power state of the HX711 sensor. `power_down()` puts the sensor into sleep mode, blocking for 64 microseconds. `power_up()` wakes it up, potentially resetting internal states. ```APIDOC void power_down() void power_up() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.