Skip to content

Commit

Permalink
fix: pin range and init digial ports
Browse files Browse the repository at this point in the history
  • Loading branch information
wokim committed Apr 2, 2024
1 parent 6062c6a commit 1d9f207
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ def get(self):
}

# Read digital pins
for pin in range(0, 28): # Assuming digital pins are from 0 to 27
for pin in range(20, 28): # Assuming digital pins are from 20 to 27
try:
value = read_digital_pin(pin)
status['digital'].append({'pin': pin, 'value': value})
except Exception:
status['digital'].append({'pin': pin, 'value': 'Error'})

# Read analog pins
for pin in range(1, 5): # Assuming analog pins are from 1 to 4
for pin in range(0, 4): # Assuming analog pins are from 0 to 3
try:
value = read_analog_from_dfrobot(pin)
status['analog'].append({'pin': pin, 'value': value, 'bits': 12})
Expand All @@ -142,7 +142,7 @@ def get(self):
status['mcp3008'].append({'pin': pin, 'value': 'Error', 'bits': 10})

# Read PWM pins
for pin in range(1, 5): # Assuming PWM pins are from 1 to 4
for pin in range(0, 4): # Assuming PWM pins are from 0 to 3
try:
value = get_pwm_duty_cycle(pin)
status['pwm'].append({'pin': pin, 'value': value})
Expand Down
11 changes: 9 additions & 2 deletions app/gpio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
spi = spidev.SpiDev()

def init_board():
cleanup_board()

board.set_adc_enable()
board.set_pwm_enable()
board.set_pwm_frequency(1000)
Expand All @@ -20,9 +22,14 @@ def init_board():
# Set GPIO mode to BCM
GPIO.setmode(GPIO.BCM)

pins = [20, 21, 22, 23, 24, 25, 26, 27]
# pins = [0, 1, 2, 3, 4, 5, 6, 7]

for pin in pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)

# Set the specified pin as an OUTPUT
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

0 comments on commit 1d9f207

Please sign in to comment.