프로젝트를 위해 로드셀 센서를 샀는데 또 하나의 과정이남았다... 캘리브레이션... 영점잡기..? 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() 호출도 다 되어있으니 그냥 파라미터 값을 수정하면서 계속 컴파일하고 실행시키면 된다. 아래는 샘플코드
위 샘플코드가 들어있는 라이브러리 링크 https://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 캘리브레이션 설명이 있는 깃허브 링크 https://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; } } |