rpi-interface-board/rpi-scripts/interface_board_pins.py

114 lines
3.0 KiB
Python

# 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 = {
0: 25, # Dig-IN_1 is connected to GPIO_25
1: 16, # Dig-IN_2 is connected to GPIO_16
2: 26, # Dig-IN_3 is connected to GPIO_26
3: 13, # Dig-IN_4 is connected to GPIO_13
4: 6, # Dig-IN_5 is connected to GPIO_6
5: 5, # Dig-IN_6 is connected to GPIO_5
6: 22, # Dig-IN_7 is connected to GPIO_22
7: 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
# FIXME: numbering in schematic is wrong (inverse) layout / terminal order matches the shift register though (left to right -> 0-7)
# Shift Register Channel Assignments
SHIFT_REG_CHANNEL_BUZZER = 0 # Buzzer connected to shift register channel 0
SHIFT_REG_CHANNEL_RELAY1 = 2 # Relay 1 connected to shift register channel 2
SHIFT_REG_CHANNEL_RELAY2 = 1 # Relay 2 connected to shift register channel 1
# ===============
# ===== 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)
# Pin mappings for Terminal number to actual ADC channels, including max voltage range
ADC_TERMINALS = {
0: {"adc_channel": 1, "max_value": 3.3, "unit": "V"}, # Terminal 0 -> ADC channel 1, max 3.3V
1: {"adc_channel": 0, "max_value": 3.3, "unit": "V"}, # Terminal 1 -> ADC channel 0, max 3.3V
2: {"adc_channel": 3, "max_value": 5, "unit": "V"}, # Terminal 2 -> ADC channel 3, max 5V
3: {"adc_channel": 2, "max_value": 5, "unit": "V"},
4: {"adc_channel": 5, "max_value": 12, "unit": "V"},
5: {"adc_channel": 4, "max_value": 24, "unit": "V"},
6: {"adc_channel": 7, "max_value": 20, "unit": "mA"}, # Terminal 6 -> ADC channel 7, max 20mA
7: {"adc_channel": 6, "max_value": 20, "unit": "mA"},
}
# Alternative to ADC_CHANNELS list have separate constants for the channels (more intuitive)
ADC_CHANNEL_T0__0_TO_3V3 = 1
ADC_CHANNEL_T1__0_TO_3V3 = 0
ADC_CHANNEL_T2__0_TO_5V = 3
ADC_CHANNEL_T3__0_TO_5V = 2
ADC_CHANNEL_T4__0_TO_12V = 5
ADC_CHANNEL_T5__0_TO_24V = 4
ADC_CHANNEL_T6__0_TO_20MA = 7
ADC_CHANNEL_T7__0_TO_20MA = 6
# ====================
# === 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 = 18 # RPI_PWM0
GPIO_PWM2 = 12 # RPI_PWM0 too
# ====================
# === UART / RS485 ===
# ====================
GPIO_UART_TX = 14 # RPI TXD
GPIO_UART_RX = 15 # RPI RXD
GPIO_UART_DIR = 23