Skip to content

Commit

Permalink
Create hardware.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 10, 2024
1 parent 9eda8f7 commit 2c8c4b8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions hardware_integration/hardware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import RPi.GPIO as GPIO

def setup_i2c(sda_pin, scl_pin):
"""
Sets up the I2C communication protocol using the specified SDA and SCL pins.
"""
GPIO.setmode(GPIO.BCM)
GPIO.setup(sda_pin, GPIO.OUT)
GPIO.setup(scl_pin, GPIO.OUT)
GPIO.output(sda_pin, GPIO.HIGH)
GPIO.output(scl_pin, GPIO.HIGH)
GPIO.setmode(GPIO.BCM)
GPIO.setup(sda_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(scl_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def setup_spi(sclk_pin, mosi_pin, miso_pin):
"""
Sets up the SPI communication protocol using the specified SCLK, MOSI, and MISO pins.
"""
GPIO.setmode(GPIO.BCM)
GPIO.setup(sclk_pin, GPIO.OUT)
GPIO.setup(mosi_pin, GPIO.OUT)
GPIO.setup(miso_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def cleanup():
"""
Cleans up the GPIO pins and resets the GPIO library.
"""
GPIO.cleanup()

0 comments on commit 2c8c4b8

Please sign in to comment.