HX711 캘리브레이션 - HX711 kaellibeuleisyeon

프로젝트를 위해 로드셀 센서를 샀는데 

또 하나의 과정이남았다...  캘리브레이션... 영점잡기..? 

Example code 에 있는 HX711_full_example 을 돌려보니 뭔 값만 나오고 어쩌란건가 싶었다

코드를 보니 깃허브 링크가 있다 

과정은 다음과 같다.

1. set_scale()을 parameter 없이 호출한다. 

    쓰여있는 코드에서 set_scale을 찾아 내용을 비워준다.....

2. tare() 을 호출한다.

3. 무게를 알고있는 물체를 올리고 get_units(10) 호출

4. (내가 올린 무게) / 3번의 결과값  을 해준다. 

이 결과를 set_scale() 인수로 넘긴다.

5. 알맞은 값이 나올 때까지 4번의 결과를 계속조정한다. 

예제코드에 set_scale 도 get_unit() 호출도 다 되어있으니 그냥 파라미터 값을 수정하면서 계속 컴파일하고 실행시키면 된다. 

아래는 샘플코드

/** * * HX711 library for Arduino - example file * //github.com/bogde/HX711 * * MIT License * (c) 2018 Bogdan Necula * **/ #include "HX711.h" // HX711 circuit wiring const int LOADCELL_DOUT_PIN = 4; const int LOADCELL_SCK_PIN = 0; HX711 scale; void setup() { Serial.begin(38400); Serial.println("HX711 Demo"); Serial.println("Initializing the scale"); // Initialize library with data output pin, clock input pin and gain factor. // Channel selection is made by passing the appropriate gain: // - With a gain factor of 64 or 128, channel A is selected // - With a gain factor of 32, channel B is selected // By omitting the gain factor parameter, the library // default "128" (Channel A) is used here. scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); Serial.println("Before setting up the scale:"); Serial.print("read: \t\t"); Serial.println(scale.read()); // print a raw reading from the ADC Serial.print("read average: \t\t"); Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC Serial.print("get value: \t\t"); Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet) Serial.print("get units: \t\t"); Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided // by the SCALE parameter (not set yet) scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details scale.tare(); // reset the scale to 0 Serial.println("After setting up the scale:"); Serial.print("read: \t\t"); Serial.println(scale.read()); // print a raw reading from the ADC Serial.print("read average: \t\t"); Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC Serial.print("get value: \t\t"); Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare() Serial.print("get units: \t\t"); Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided // by the SCALE parameter set with set_scale Serial.println("Readings:"); } void loop() { Serial.print("one reading:\t"); Serial.print(scale.get_units(), 1); Serial.print("\t| average:\t"); Serial.println(scale.get_units(10), 1); scale.power_down(); // put the ADC in sleep mode delay(5000); scale.power_up(); }

위 샘플코드가 들어있는 라이브러리 링크

//www.arduino.cc/reference/en/libraries/hx711-arduino-library/

HX711 Arduino Library - Arduino Reference

Reference > Libraries > Hx711 arduino library HX711 Arduino Library Sensors Library to interface the Avia Semiconductor HX711 ADC. An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for reading load cells

www.arduino.cc

캘리브레이션 설명이 있는 깃허브 링크

//github.com/bogde/HX711#how-to-calibrate-your-load-cell

GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for

An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales. - GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconduct...

github.com

#include "HX711.h"

#define DOUT  5

#define CLK  4

HX711 scale(DOUT, CLK);

float calibration_factor = -12170//=100g

float output;

int readIndex;

float total=0;

float average=0;

float average_last=0;

const int cycles=20;

float readings[cycles];

void setup() {

Serial.begin(9600);

Serial.println("HX711 calibration sketch");

Serial.println("Remove all weight from scale");

Serial.println("After readings begin, place known weight on scale");

Serial.println("Press + or a to increase calibration factor");

Serial.println("Press - or z to decrease calibration factor");

scale.set_scale();

scale.tare();     //Reset the scale to 0

long zero_factor = scale.read_average(); //Get a baseline reading

Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale.

Serial.println(zero_factor);

}

void loop() {

scale.set_scale(calibration_factor); //Adjust to this calibration factor

Serial.print("Reading: ");

output=scale.get_units(), 2;

Serial.print(output);

total = total - readings[readIndex];

readings[readIndex] = scale.get_units(), 2;

total = total + readings[readIndex];

readIndex = readIndex + 1;

if (readIndex >= cycles) {

readIndex = 0;

}

average = total / cycles;

average=scale.get_units(), 2;

if((average_last>average+0.03 || average_last<average-0.03)){

if (average<0.06) {

average=0;

}

Serial.print("\tFilter: ");

Serial.print(average);

average_last=average;

}

else{

Serial.print("\tFilter: ");

Serial.print(average_last);

}

Serial.print(" g"); 

Serial.print(" calibration_factor: ");

Serial.print(calibration_factor);

Serial.println();

if(Serial.available()) {

char temp = Serial.read();

if(temp == '+' || temp == 'a')

calibration_factor += 10;

else if(temp == '-' || temp == 'z')

calibration_factor -= 10;

}

}

Toplist

최신 우편물

태그