diff --git a/rpi-scripts/examples/read_digital_inputs.py b/rpi-scripts/examples/read_digital_inputs.py new file mode 100644 index 0000000..8dcbbc0 --- /dev/null +++ b/rpi-scripts/examples/read_digital_inputs.py @@ -0,0 +1,29 @@ +# Add the parent directory to the module search path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +from interface_board_pins.py import GPIO_DIGITAL_INPUTS # map of which GPIO pins are associated with which input terminal (1-8) + +import RPi.GPIO as GPIO + + + +# Initialize GPIO +GPIO.setmode(GPIO.BCM) +for pin in DIGITAL_INPUTS.values(): + GPIO.setup(pin, GPIO.IN) + + + +# Repeatedly read GPIOs +print("Reading digital inputs:") +try: + while True: + for label, pin in DIGITAL_INPUTS.items(): + state = GPIO.input(pin) + print(f"Input {label} (GPIO {pin}): {'HIGH' if state else 'LOW'}") + print("-" * 40) + +except KeyboardInterrupt: + print("Exiting...") + +finally: + GPIO.cleanup() diff --git a/rpi-scripts/interface_board_pins.py b/rpi-scripts/interface_board_pins.py new file mode 100644 index 0000000..8bb289f --- /dev/null +++ b/rpi-scripts/interface_board_pins.py @@ -0,0 +1,80 @@ +# Pin mappings for GPIOs and other components specifically for the pi-interface-board_v1.0 + + + +# === Digital Inputs === +# Pin mappings for digital inputs (labeled on housing as 1-8) +GPIO_DIGITAL_INPUTS = { + 1: 25, # Dig-IN_1 is connected to GPIO_25 + 2: 16, # Dig-IN_2 is connected to GPIO_16 + 3: 26, # Dig-IN_3 is connected to GPIO_26 + 4: 13, # Dig-IN_4 is connected to GPIO_13 + 5: 6, # Dig-IN_5 is connected to GPIO_6 + 6: 5, # Dig-IN_6 is connected to GPIO_5 + 7: 22, # Dig-IN_7 is connected to GPIO_22 + 8: 24, # Dig-IN_8 is connected to GPIO_24 +} + + + + +# === Shift Register === +GPIO_SHIFT_REG_DATA = 27 +GPIO_SHIFT_REG_LATCH = 17 +GPIO_SHIFT_REG_CLOCK = 4 + + + + +# === ADC === +# ADC IC is connected to RPI SPI interface 0 (pins below) +ADC_SPI_BUS_NUM = 0 +ADC_SPI_DEVICE_NUM = 0 +ADC_SPI_CS_PIN = 8 # SPI Chip Select for MCP3208 +# MISO_0: GPIO_9 +# MOSI_0: GPIO_10 +# SCLK_0: GPIO_11 +# CE_0: GPIO# MCP3208 (ADC) + +ADC_CHANNELS = { + 1: 0, # Channel 1 = ADC channel 0 + 2: 1, # Channel 2 = ADC channel 1 + 3: 2, # ... + 4: 3, + 5: 4, + 6: 5, + 7: 6, + 8: 7 +} + + + + +# === SPI Terminal === +SPI_BUS_NUM = 1 +# MISO_1: GPIO_19 +# MOSI_1: GPIO_20 +# SCLK_1: GPIO_21 +# CE_1: GPIO_7 + + + + +# === I2C Terminal === +GPIO_I2C_SDA = 2 +GPIO_I2C_SCL = 3 + + + + +# === PWM outputs === +GPIO_PWM1 = 12 # RPI_PWM0 +GPIO_PWM2 = 18 # RPI_PWM0 too + + + + +# === UART / RS485 === +GPIO_UART_TX = 14 # RPI TXD +GPIO_UART_RX = 15 # RPI RXD +GPIO_UART_DIR = 23 \ No newline at end of file