Hx711.h no such file or directory là gì

Trong quá trình làm việc cũng như vọc vạch Arduino thì việc thêm thư viện cho arduino ide là một điều xảy ra thường xuyên, việc thêm một thư viện mới không hề khó khăn mà thực sự đơn giản. Hôm nay, mình sẽ hướng dẫn các bạn chi tiết làm sao để có thể thêm một thư viện mới vào Arduino IDE nhé. Nếu bạn là một người mới, lần đầu tiên đọc bài viết này, là người đang muốn tìm hiểu và học tập arduino thì bước đầu tiên bạn nên làm là tải phần mềm Arduino IDE về nhé. Mình sẽ để link bên dưới chỉ cần làm theo bài viết thì mọi việc sẽ trở nên đơn giản.

  • Xem ngay: Hướng dẫn cài đặt phần mềm Arduino IDE

2 Cách thêm thư viện Arduino IDE chuẩn nhất

Cách 1: Bạn khởi động Arduino IDE, click vào Sketch trên thanh công cụ chọn Include Library > Manage Libraries

Hx711.h no such file or directory là gì

Tiếp theo sẽ là vùng Library Manager là nơi chứa các thư viện mới nhất từ các doanh nghiệp, cộng đồng, cá nhân đã quyên góp tiền để xây dựng phần mềm. Bạn click vào Filter your seach để tiềm kiếm thư vện hoặc sử dụng Type và Topic để lọc ra các kết quả tìm kiếm mà bạn đang cần.

Hx711.h no such file or directory là gì

Khi đã chọn được thư viện cần, nhấn Install để tiến hành cài đặt.

Hx711.h no such file or directory là gì

Tiến hành kiểm tra xem thư viện đã được thêm vào chưa: Vào File > Examples.

Hx711.h no such file or directory là gì

Cách 2: Khởi động Arduino IDE, click vào Sketch trên thanh công cụ chọn Include Library > Add .ZIP library…

Hx711.h no such file or directory là gì

Truy cập vào thư mục mà bạn đã lưu thư viện có đuôi .ZIP.

Hx711.h no such file or directory là gì

Click vào thư viện mà bạn muốn cài đặt.

Hx711.h no such file or directory là gì

Nếu Upload thành công Arduino IDE sẽ xuất hiện thông báo Library add to your libraries. Check Include library menu.

Hx711.h no such file or directory là gì

Tiến hành kiểm tra xem thư viện đã được thêm vào chưa: Vào File > Examples.

Hx711.h no such file or directory là gì

Các lỗi thường gặp khi thêm mới thư viện Arduino IDE cần biết

Bị trùng lặp thư viện Arduino IDE

Một lỗi cơ bản nhưng những bạn mới tập tành Arduino hay mắc phải là thêm mới thư viện đã có trong hệ thống của Arduino. Vậy phải làm sao, cơ bản nhất là bạn không cần phải làm gì cả, trong trường hợp bạn muốn thêm thư viện mới thì bước đầu tiên cần xóa thư viện cũ trong hệ thống arduino đi, rồi add thư viện mới vào thế là xong nhé.

An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for reading load cells / weight scales.

It supports the architectures atmelavr, espressif8266, espressif32,atmelsam, teensy and ststm32 by corresponding PlatformIO targets.

Synopsis

Blocking mode

The library is usually used in blocking mode, i.e. it will wait for the hardware becoming available before returning a reading.

include "HX711.h"

HX711 loadcell; // 1. HX711 circuit wiring const int LOADCELL_DOUT_PIN = 2; const int LOADCELL_SCK_PIN = 3; // 2. Adjustment settings const long LOADCELL_OFFSET = 50682624; const long LOADCELL_DIVIDER = 5895655; // 3. Initialize library loadcell.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); loadcell.set_scale(LOADCELL_DIVIDER); loadcell.set_offset(LOADCELL_OFFSET); // 4. Acquire reading Serial.print("Weight: "); Serial.println(loadcell.get_units(10), 2);

Non-blocking mode

It is also possible to define a maximum timeout to wait for the hardware to be initialized. This won't send the program into a spinlock when the scale is disconnected and will probably also account for hardware failures.

// 4. Acquire reading without blocking
if (loadcell.wait_ready_timeout(1000)) {
    long reading = loadcell.get_units(10);
    Serial.print("Weight: ");
    Serial.println(reading, 2);
} else {
    Serial.println("HX711 not found.");
}

FAQ

https://github.com/bogde/HX711/blob/master/doc/faq.md

More examples

See

// 4. Acquire reading without blocking
if (loadcell.wait_ready_timeout(1000)) {
    long reading = loadcell.get_units(10);
    Serial.print("Weight: ");
    Serial.println(reading, 2);
} else {
    Serial.println("HX711 not found.");
}

0 directory in this repository.

HAL support

  • Arduino AVR core
  • Arduino core for ESP8266
  • Arduino core for ESP32
  • Arduino core for SAMD21 (untested)
  • Arduino core for SAMD51 (untested)
  • Arduino core for STM32
  • Arduino Core for Adafruit Bluefruit nRF52 Boards

Hardware support

The library has been tested successfully on the following hardware.

  • ATmega328: Arduino Uno
  • ESP8266: WeMos D1 mini, Adafruit HUZZAH
  • ESP32: ESP32 DEVKIT V1, Heltec WiFi Kit 32, Adafruit Feather HUZZAH32
  • (): STM32F103C8T6 STM32 Blue Pill Board
  • nRF52: Adafruit Feather nRF52840 Express

Thanks, @bogde and @ClemensGruber!

Features

  1. It provides a

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    1 function, which "resets" the scale to 0. Many other implementations calculate the tare weight when the ADC is initialized only. I needed a way to be able to set the tare weight at any time. Use case: Place an empty container on the scale, call

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    1 to reset the readings to 0, fill the container and get the weight of the content.
  2. It provides a

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    3 function, to put the ADC into a low power mode. According to the datasheet,
    When PD_SCK pin changes from low to high and stays at high for longer than 60μs, HX711 enters power down mode.

    Use case: Battery-powered scales. Accordingly, there is a

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    4 function to get the chip out of the low power mode.
  3. It has a

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    5 function that allows you to set the gain factor and select the channel. According to the datasheet, Channel A can be programmed with a gain of 128 or 64, corresponding to a full-scale differential input voltage of ±20mV or ±40mV respectively, when a 5V supply is connected to AVDD analog power supply pin. Channel B has a fixed gain of 32. The same function is used to select the channel A or channel B, by passing 128 or 64 for channel A, or 32 for channel B as the parameter. The default value is 128, which means "channel A with a gain factor of 128", so one can simply call

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

  4. This function is also called from the initializer method

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    7.
  5. The

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    8 and

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    9 functions can receive an extra parameter "times", and they will return the average of multiple readings instead of a single reading.

How to calibrate your load cell

  1. Call

    Environment feather_328 [SUCCESS] Environment atmega_2560 [SUCCESS] Environment huzzah [SUCCESS] Environment lopy4 [SUCCESS] Environment teensy31 [SUCCESS] Environment teensy36 [SUCCESS] Environment feather_m0 [SUCCESS] Environment arduino_due [SUCCESS] Environment feather_m4 [SUCCESS] Environment bluepill [SUCCESS] Environment adafruit_feather_nrf52840 [SUCCESS]

    0 with no parameter.
  2. Call

    // 4. Acquire reading without blocking if (loadcell.wait_ready_timeout(1000)) {

    long reading = loadcell.get_units(10);  
    Serial.print("Weight: ");  
    Serial.println(reading, 2);  
    
    } else {
    Serial.println("HX711 not found.");  
    
    }

    1 with no parameter.
  3. Place a known weight on the scale and call

    Environment feather_328 [SUCCESS] Environment atmega_2560 [SUCCESS] Environment huzzah [SUCCESS] Environment lopy4 [SUCCESS] Environment teensy31 [SUCCESS] Environment teensy36 [SUCCESS] Environment feather_m0 [SUCCESS] Environment arduino_due [SUCCESS] Environment feather_m4 [SUCCESS] Environment bluepill [SUCCESS] Environment adafruit_feather_nrf52840 [SUCCESS]

    2.
  4. Divide the result in step 3 to your known weight. You should get about the parameter you need to pass to

    Environment feather_328 [SUCCESS] Environment atmega_2560 [SUCCESS] Environment huzzah [SUCCESS] Environment lopy4 [SUCCESS] Environment teensy31 [SUCCESS] Environment teensy36 [SUCCESS] Environment feather_m0 [SUCCESS] Environment arduino_due [SUCCESS] Environment feather_m4 [SUCCESS] Environment bluepill [SUCCESS] Environment adafruit_feather_nrf52840 [SUCCESS]

    0.
  5. Adjust the parameter in step 4 until you get an accurate reading.

Build

All architectures

This will spawn a Python virtualenv in the current directory, install

Environment feather_328                 [SUCCESS]
Environment atmega_2560                  [SUCCESS]
Environment huzzah                      [SUCCESS]
Environment lopy4                       [SUCCESS]
Environment teensy31                    [SUCCESS]
Environment teensy36                    [SUCCESS]
Environment feather_m0                  [SUCCESS]
Environment arduino_due                 [SUCCESS]
Environment feather_m4                  [SUCCESS]
Environment bluepill                     [SUCCESS]
Environment adafruit_feather_nrf52840   [SUCCESS]

4 into it and then execute

Environment feather_328                 [SUCCESS]
Environment atmega_2560                  [SUCCESS]
Environment huzzah                      [SUCCESS]
Environment lopy4                       [SUCCESS]
Environment teensy31                    [SUCCESS]
Environment teensy36                    [SUCCESS]
Environment feather_m0                  [SUCCESS]
Environment arduino_due                 [SUCCESS]
Environment feather_m4                  [SUCCESS]
Environment bluepill                     [SUCCESS]
Environment adafruit_feather_nrf52840   [SUCCESS]

5, effectively building for all environments defined in

Environment feather_328                 [SUCCESS]
Environment atmega_2560                  [SUCCESS]
Environment huzzah                      [SUCCESS]
Environment lopy4                       [SUCCESS]
Environment teensy31                    [SUCCESS]
Environment teensy36                    [SUCCESS]
Environment feather_m0                  [SUCCESS]
Environment arduino_due                 [SUCCESS]
Environment feather_m4                  [SUCCESS]
Environment bluepill                     [SUCCESS]
Environment adafruit_feather_nrf52840   [SUCCESS]

6.

Result

Environment feather_328                 [SUCCESS]
Environment atmega_2560                  [SUCCESS]
Environment huzzah                      [SUCCESS]
Environment lopy4                       [SUCCESS]
Environment teensy31                    [SUCCESS]
Environment teensy36                    [SUCCESS]
Environment feather_m0                  [SUCCESS]
Environment arduino_due                 [SUCCESS]
Environment feather_m4                  [SUCCESS]
Environment bluepill                     [SUCCESS]
Environment adafruit_feather_nrf52840   [SUCCESS]

Details

https://gist.github.com/amotl/5ed6b3eb1fcd2bc78552b218b426f6aa

Specific architecture

You can run a build for a specific architecture by specifying the appropriate platform label on the command line.

# Build for LoPy4
make build-env environment=lopy4
# Build for Feather M0
make build-env environment=feather_m0

Deprecation warning

This library received some spring-cleaning in February 2019 (

123), removing the pin definition within the constructor completely, as this was not timing safe. (

29) Please use the new initialization flavor as outlined in the example above.

Credits

Thanks to Weihong Guan who started the first version of this library in 2012 already (see [arduino|module]Hx711 electronic scale kit, sources), Bogdan Necula who took over in 2014 and last but not least all others who contributed to this library over the course of the last years, see also

Environment feather_328                 [SUCCESS]
Environment atmega_2560                  [SUCCESS]
Environment huzzah                      [SUCCESS]
Environment lopy4                       [SUCCESS]
Environment teensy31                    [SUCCESS]
Environment teensy36                    [SUCCESS]
Environment feather_m0                  [SUCCESS]
Environment arduino_due                 [SUCCESS]
Environment feather_m4                  [SUCCESS]
Environment bluepill                     [SUCCESS]
Environment adafruit_feather_nrf52840   [SUCCESS]

7 in this repository.

See also

  • https://item.taobao.com/item.htm?id=18121631630
  • https://item.taobao.com/item.htm?id=544769386300

Similar libraries

There are other libraries around, enjoy:

  • https://github.com/olkal/HX711_ADC
  • https://github.com/queuetue/Q2-HX711-Arduino-Library

Appendix

Considerations about real world effects caused by physics

You should consider getting into the details of strain-gauge load cell sensors when expecting reasonable results. The range of topics is from sufficient and stable power supply, using the proper excitation voltage to the Seebeck effect and temperature compensation.