Skip to content

Commit

Permalink
fix: update GPIO pin setup and output in init_board() and dfrobot_dig…
Browse files Browse the repository at this point in the history
…ital.py
  • Loading branch information
wokim committed Mar 24, 2024
1 parent f37c658 commit 6062c6a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/gpio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 2 additions & 0 deletions app/gpio/dfrobot_digital.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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}")

0 comments on commit 6062c6a

Please sign in to comment.