{"id":13780356,"url":"https://github.com/bogde/HX711","last_synced_at":"2025-05-11T13:32:07.143Z","repository":{"id":13564983,"uuid":"16257296","full_name":"bogde/HX711","owner":"bogde","description":"An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.","archived":false,"fork":false,"pushed_at":"2023-05-10T09:13:50.000Z","size":101,"stargazers_count":887,"open_issues_count":114,"forks_count":536,"subscribers_count":69,"default_branch":"master","last_synced_at":"2024-08-03T18:15:03.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bogde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2014-01-26T17:14:50.000Z","updated_at":"2024-07-30T01:27:26.000Z","dependencies_parsed_at":"2023-10-20T18:30:39.963Z","dependency_job_id":null,"html_url":"https://github.com/bogde/HX711","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogde%2FHX711","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogde%2FHX711/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogde%2FHX711/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bogde%2FHX711/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bogde","download_url":"https://codeload.github.com/bogde/HX711/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225056806,"owners_count":17414213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:14.850Z","updated_at":"2024-11-17T15:31:08.396Z","avatar_url":"https://github.com/bogde.png","language":"C++","readme":"# HX711\nAn Arduino library to interface the [Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC)]\nfor reading load cells / weight scales.\n\nIt supports the architectures `atmelavr`, `espressif8266`, `espressif32`,\n`atmelsam`, `teensy` and `ststm32` by corresponding [PlatformIO] targets.\n\n[Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC)]: http://www.dfrobot.com/image/data/SEN0160/hx711_english.pdf\n[PlatformIO]: https://platformio.org/\n\n\n## Synopsis\n\n### Blocking mode\nThe library is usually used in blocking mode, i.e. it will wait for the\nhardware becoming available before returning a reading.\n\n```c++\n#include \"HX711.h\"\nHX711 loadcell;\n\n// 1. HX711 circuit wiring\nconst int LOADCELL_DOUT_PIN = 2;\nconst int LOADCELL_SCK_PIN = 3;\n\n// 2. Adjustment settings\nconst long LOADCELL_OFFSET = 50682624;\nconst long LOADCELL_DIVIDER = 5895655;\n\n// 3. Initialize library\nloadcell.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);\nloadcell.set_scale(LOADCELL_DIVIDER);\nloadcell.set_offset(LOADCELL_OFFSET);\n\n// 4. Acquire reading\nSerial.print(\"Weight: \");\nSerial.println(loadcell.get_units(10), 2);\n```\n\n### Non-blocking mode\nIt is also possible to define a maximum timeout to wait for the hardware\nto be initialized. This won't send the program into a spinlock when the\nscale is disconnected and will probably also account for hardware failures.\n```\n// 4. Acquire reading without blocking\nif (loadcell.wait_ready_timeout(1000)) {\n    long reading = loadcell.get_units(10);\n    Serial.print(\"Weight: \");\n    Serial.println(reading, 2);\n} else {\n    Serial.println(\"HX711 not found.\");\n}\n```\n\n\n## FAQ\nhttps://github.com/bogde/HX711/blob/master/doc/faq.md\n\n\n## More examples\nSee `examples` directory in this repository.\n\n\n## HAL support\n- [Arduino AVR core](https://github.com/arduino/ArduinoCore-avr)\n- [Arduino core for ESP8266](https://github.com/esp8266/Arduino)\n- [Arduino core for ESP32](https://github.com/espressif/arduino-esp32)\n- [Arduino core for SAMD21](https://github.com/arduino/ArduinoCore-samd) (untested)\n- [Arduino core for SAMD51](https://github.com/adafruit/ArduinoCore-samd) (untested)\n- [Arduino core for STM32](https://github.com/stm32duino/Arduino_Core_STM32)\n- [Arduino Core for Adafruit Bluefruit nRF52 Boards](https://github.com/adafruit/Adafruit_nRF52_Arduino)\n\n\n## Hardware support\nThe library has been tested successfully on the following hardware.\n\n- [ATmega328]: Arduino Uno\n- [ESP8266]: WeMos D1 mini, Adafruit HUZZAH\n- [ESP32]: ESP32 DEVKIT V1, Heltec WiFi Kit 32, Adafruit Feather HUZZAH32\n- [STM32 F1] ([Cortex-M3]): STM32F103C8T6 STM32 Blue Pill Board\n- [nRF52]: Adafruit Feather nRF52840 Express\n\nThanks, @bogde and @ClemensGruber!\n\n[ATmega328]: https://en.wikipedia.org/wiki/ATmega328\n[ESP8266]: https://en.wikipedia.org/wiki/ESP8266\n[ESP32]: https://en.wikipedia.org/wiki/ESP32\n[STM32 F1]: https://en.wikipedia.org/wiki/STM32#STM32_F1\n[Cortex-M3]: https://en.wikipedia.org/wiki/ARM_Cortex-M#Cortex-M3\n[nRF52]: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fstruct_nrf52%2Fstruct%2Fnrf52.html\n\n\n## Features\n1. It provides a `tare()` function, which \"resets\" the scale to 0. Many other\n   implementations calculate the tare weight when the ADC is initialized only.\n   I needed a way to be able to set the tare weight at any time.\n   **Use case**: Place an empty container on the scale, call `tare()` to reset\n   the readings to 0, fill the container and get the weight of the content.\n\n2. It provides a `power_down()` function, to put the ADC into a low power mode.\n   According to the datasheet,\n   \u003e When PD_SCK pin changes from low to high and stays at high\n   \u003e for longer than 60μs, HX711 enters power down mode.\n\n   **Use case**: Battery-powered scales. Accordingly, there is a `power_up()`\n   function to get the chip out of the low power mode.\n\n3. It has a `set_gain(byte gain)` function that allows you to set the gain factor\n   and select the channel. According to the datasheet,\n   \u003e Channel A can be programmed with a gain of 128 or 64, corresponding to\n   a full-scale differential input voltage of ±20mV or ±40mV respectively, when\n   a 5V supply is connected to AVDD analog power supply pin. Channel B has\n   a fixed gain of 32.\n\n   The same function is used to select the channel A or channel B, by passing\n   128 or 64 for channel A, or 32 for channel B as the parameter. The default\n   value is 128, which means \"channel A with a gain factor of 128\", so one can\n   simply call `set_gain()`.\n\n   This function is also called from the initializer method `begin()`.\n\n4. The `get_value()` and `get_units()` functions can receive an extra parameter \"times\",\n   and they will return the average of multiple readings instead of a single reading.\n\n\n## How to calibrate your load cell\n1. Call `set_scale()` with no parameter.\n2. Call `tare()` with no parameter.\n3. Place a known weight on the scale and call `get_units(10)`.\n4. Divide the result in step 3 to your known weight. You should\n   get about the parameter you need to pass to `set_scale()`.\n5. Adjust the parameter in step 4 until you get an accurate reading.\n\n\n## Build\n\n### All architectures\nThis will spawn a Python virtualenv in the current directory,\ninstall `platformio` into it and then execute `platformio run`,\neffectively building for all environments defined in `platformio.ini`.\n\n    make build-all\n\n#### Result\n```\nEnvironment feather_328                 [SUCCESS]\nEnvironment atmega_2560\t                [SUCCESS]\nEnvironment huzzah                      [SUCCESS]\nEnvironment lopy4                       [SUCCESS]\nEnvironment teensy31                    [SUCCESS]\nEnvironment teensy36                    [SUCCESS]\nEnvironment feather_m0                  [SUCCESS]\nEnvironment arduino_due                 [SUCCESS]\nEnvironment feather_m4                  [SUCCESS]\nEnvironment bluepill   \t                [SUCCESS]\nEnvironment adafruit_feather_nrf52840   [SUCCESS]\n```\n\n#### Details\nhttps://gist.github.com/amotl/5ed6b3eb1fcd2bc78552b218b426f6aa\n\n\n### Specific architecture\nYou can run a build for a specific architecture by specifying\nthe appropriate platform label on the command line.\n\n    # Build for LoPy4\n    make build-env environment=lopy4\n\n    # Build for Feather M0\n    make build-env environment=feather_m0\n\n\n## Deprecation warning\nThis library received some spring-cleaning in February 2019 (#123),\nremoving the pin definition within the constructor completely, as\nthis was not timing safe. (#29) Please use the new initialization\nflavor as outlined in the example above.\n\n\n## Credits\nThanks to Weihong Guan who started the first version of this library in 2012\nalready (see [[arduino|module]Hx711 electronic scale kit](http://aguegu.net/?p=1327),\n[sources](https://github.com/aguegu/ardulibs/tree/master/hx711)), Bogdan Necula\nwho took over in 2014 and last but not least all others who contributed to this\nlibrary over the course of the last years, see also `CONTRIBUTORS.rst` in this\nrepository.\n\n#### See also\n- https://item.taobao.com/item.htm?id=18121631630\n- https://item.taobao.com/item.htm?id=544769386300\n\n\n## Similar libraries\nThere are other libraries around, enjoy:\n\n- https://github.com/olkal/HX711_ADC\n- https://github.com/queuetue/Q2-HX711-Arduino-Library\n\n\n---\n\n## Appendix\n\n### Considerations about real world effects caused by physics\nYou should consider getting into the details of strain-gauge load cell\nsensors when expecting reasonable results. The range of topics is from\nsufficient and stable power supply, using the proper excitation voltage\nto the Seebeck effect and temperature compensation.\n\nSee also:\n- [Overview about real world effects](https://community.hiveeyes.org/t/analog-vs-digital-signal-gain-amplifiers/380/6)\n- [Thermoelectric effect](https://en.wikipedia.org/wiki/Thermoelectric_effect) (Seebeck effect)\n- Temperature compensation: [Resource collection](https://community.hiveeyes.org/t/temperaturkompensation-fur-waage-hardware-firmware/115), [DIY research](https://community.hiveeyes.org/t/temperaturkompensation-fur-waage-notig-datensammlung/245)\n- [Power management for HX711](https://community.hiveeyes.org/t/stromversorgung-hx711/893)\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbogde%2FHX711","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbogde%2FHX711","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbogde%2FHX711/lists"}