From 6062c6a04e9591b03bee39d7869b34cb8791bbc5 Mon Sep 17 00:00:00 2001 From: Wonshik KIM Date: Sun, 24 Mar 2024 13:55:01 +0900 Subject: [PATCH] fix: update GPIO pin setup and output in init_board() and dfrobot_digital.py --- app/gpio/__init__.py | 3 ++- app/gpio/dfrobot_digital.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/gpio/__init__.py b/app/gpio/__init__.py index 4c74e7e..042f754 100644 --- a/app/gpio/__init__.py +++ b/app/gpio/__init__.py @@ -21,7 +21,8 @@ def init_board(): GPIO.setmode(GPIO.BCM) # Set the specified pin as an OUTPUT - GPIO.setup([i for i in range(22, 28)], GPIO.OUT, initial=GPIO.LOW) + GPIO.setup([i for i in range(0, 27)], GPIO.OUT) + GPIO.output([i for i in range(0, 27)], GPIO.LOW) logger.info(f"GPIO setup complete!") def cleanup_board(): diff --git a/app/gpio/dfrobot_digital.py b/app/gpio/dfrobot_digital.py index a467b64..981945d 100644 --- a/app/gpio/dfrobot_digital.py +++ b/app/gpio/dfrobot_digital.py @@ -20,6 +20,7 @@ def read_digital_pin(pin): raise ValueError("Pin number must be in the range 0 to 27") try: + GPIO.setup(pin, GPIO.IN) return GPIO.input(pin) except Exception as e: raise Exception(f"Failed to read digital pin {pin}: {e}") @@ -45,6 +46,7 @@ def write_digital_pin(pin, value): raise ValueError("Value must be either True, False, 1, or 0") try: + GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.HIGH if value in [True, 1] else GPIO.LOW) except Exception as e: raise Exception(f"Failed to write digital pin {pin}: {e}")