feat: 캘리브레이션 및 영점 조정 기능 추가
- perform_calibration(): 시작 시 자동 캘리브레이션 - tare(): 수동 영점 조정 - 10회 평균값으로 오프셋 계산 - CALIBRATION_FACTOR = -411.17
This commit is contained in:
@@ -16,6 +16,13 @@ import time
|
||||
DT_PIN = 5 # GPIO5 -> 29번 핀
|
||||
SCK_PIN = 6 # GPIO6 -> 31번 핀
|
||||
|
||||
# 설정 변수
|
||||
CALIBRATION_FACTOR = -411.17 # 캘리브레이션 팩터
|
||||
|
||||
# 상태 변수
|
||||
is_calibrated = False
|
||||
offset_value = 0
|
||||
|
||||
# HX711 인스턴스
|
||||
hx = None
|
||||
|
||||
@@ -37,18 +44,66 @@ def init_hx711():
|
||||
return False
|
||||
|
||||
|
||||
def perform_calibration():
|
||||
"""캘리브레이션 수행"""
|
||||
global is_calibrated, offset_value
|
||||
|
||||
if is_calibrated:
|
||||
return
|
||||
|
||||
print()
|
||||
print("-" * 50)
|
||||
print(">> 최초 캘리브레이션 진행")
|
||||
print("-" * 50)
|
||||
print("로드셀 위에 아무것도 올리지 마세요!")
|
||||
print("2초 후 영점 조정을 시작합니다...")
|
||||
time.sleep(2)
|
||||
|
||||
print("영점 조정 중...")
|
||||
|
||||
readings = []
|
||||
for _ in range(10):
|
||||
readings.append(hx.read())
|
||||
time.sleep(0.1)
|
||||
|
||||
offset_value = sum(readings) / len(readings)
|
||||
|
||||
print(">> 캘리브레이션 완료!")
|
||||
print(f"현재 오프셋 값: {offset_value:.2f}")
|
||||
print()
|
||||
|
||||
is_calibrated = True
|
||||
|
||||
|
||||
def tare():
|
||||
"""영점 조정 함수"""
|
||||
global offset_value
|
||||
|
||||
print("\n>> 영점 조정 중...")
|
||||
print(" 로드셀 위에 아무것도 올리지 마세요")
|
||||
time.sleep(1)
|
||||
|
||||
readings = []
|
||||
for _ in range(10):
|
||||
readings.append(hx.read())
|
||||
time.sleep(0.1)
|
||||
|
||||
offset_value = sum(readings) / len(readings)
|
||||
print(">> 영점 조정 완료!\n")
|
||||
|
||||
|
||||
def main():
|
||||
if not init_hx711():
|
||||
return
|
||||
|
||||
print("\nRaw 값 읽기 테스트 (10회):")
|
||||
for i in range(10):
|
||||
print(f" [{i+1:2d}] Raw: {hx.read()}")
|
||||
time.sleep(0.5)
|
||||
perform_calibration()
|
||||
|
||||
print("5초 후 tare() 테스트...")
|
||||
time.sleep(5)
|
||||
tare()
|
||||
|
||||
print("테스트 완료")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user