def __init__(self, i2c, columns, lines, address=None, backlight_inverted=False): """Initialize character LCD connected to backpack using I2C connection on the specified I2C bus with the specified number of columns and lines on the display. Optionally specify if backlight is inverted. """ if address: mcp = MCP23008(i2c, address=address) else: mcp = MCP23008(i2c) super().__init__( mcp.get_pin(1), mcp.get_pin(2), mcp.get_pin(3), mcp.get_pin(4), mcp.get_pin(5), mcp.get_pin(6), columns, lines, backlight_pin=mcp.get_pin(7), backlight_inverted=backlight_inverted, )
def __init__(self, i2c, address): """ :param address: The I2C address of your LCD. """ self.i2c = i2c self.address = address self.data_buffer = bytearray(1) self._backlight = True if address: self.mcp = MCP23008(i2c, address=address) else: self.mcp = MCP23008(i2c) self.reset self.mcp.get_pin(1) self.enable = self.mcp.get_pin(2) self.dl4 = self.mcp.get_pin(3) self.dl5 = self.mcp.get_pin(4) self.dl6 = self.mcp.get_pin(5) self.dl7 = self.mcp.get_pin(6) self.backlight_pin = self.mcp.get_pin(7) # set all pins as outputs for pin in (self.reset, self.enable, self.d4, self.d5, self.d6, self.d7): pin.direction = digitalio.Direction.OUTPUT
def __init__(self, i2c, columns, lines, backlight_inverted=False): """Initialize character LCD connected to backpack using I2C connection on the specified I2C bus with the specified number of columns and lines on the display. Optionally specify if backlight is inverted. """ from adafruit_mcp230xx.mcp23008 import MCP23008 mcp = MCP23008(i2c) super().__init__(mcp.get_pin(1), mcp.get_pin(2), mcp.get_pin(3), mcp.get_pin(4), mcp.get_pin(5), mcp.get_pin(6), columns, lines, backlight_pin=mcp.get_pin(7), backlight_inverted=backlight_inverted)
relay.direction = digitalio.Direction.OUTPUT # SERCOM spi = busio.SPI(board.SCK, board.MOSI, board.MISO) i2c = busio.I2C(board.SCL, board.SDA) # ADS1248 ADS1248.setup(spi, board.D3, board.D4) adc0 = ADS1248(board.D2, board.D12, 2.5) adc1 = ADS1248(board.D11, board.D10, 2.5) adc2 = ADS1248(board.D9, board.D7, 2.5) # ADS1248.verbose = True # MCP23008 mcp0 = MCP23008(i2c, address=0x20) mcp1 = MCP23008(i2c, address=0x21) mcp2 = MCP23008(i2c, address=0x22) # Temp sensors tmp0 = analogio.AnalogIn(board.A0) tmp1 = analogio.AnalogIn(board.A1) tmp2 = analogio.AnalogIn(board.A2) tmp3 = analogio.AnalogIn(board.A3) # Fan # fan = pulseio.PWMOut(board.A5, frequency=5000, duty_cycle=0) fan = digitalio.DigitalInOut(board.A5) fan.direction = digitalio.Direction.OUTPUT # BMS
#GPIO setup for non-expander ports import RPi.GPIO as GPIO import time #Haven't gotten around to figuring this out #import multiprocessing #port Expander stuff import board import busio from digitalio import Direction from adafruit_mcp230xx.mcp23008 import MCP23008 #Port expander setup i2c = busio.I2C(board.SCL, board.SDA) mcp = MCP23008(i2c) #Port expander declarations fSharp6 = mcp.get_pin(0) gSharp6 = mcp.get_pin(1) aSharp6 = mcp.get_pin(2) cSharp7 = mcp.get_pin(3) dSharp7 = mcp.get_pin(4) fSharp7 = mcp.get_pin(5) gSharp7 = mcp.get_pin(6) aSharp7 = mcp.get_pin(7) #Port expanders as output fSharp6.direction = Direction.OUTPUT gSharp6.direction = Direction.OUTPUT aSharp6.direction = Direction.OUTPUT
#!/usr/bin/env python3 import time import board import busio import digitalio from adafruit_mcp230xx.mcp23008 import MCP23008 i2c = busio.I2C(board.SCL, board.SDA) mcp24 = MCP23008(i2c, address=0x24) mcp21 = MCP23008(i2c, address=0x21) mcp23 = MCP23008(i2c, address=0x22) #mcp = MCP23008(i2c) pin0 = mcp24.get_pin(0) pin1 = mcp23.get_pin(0) pin2 = mcp21.get_pin(0) pin0.switch_to_output(value=False) pin1.switch_to_output(value=False) pin2.switch_to_output(value=False) # Setup pin1 as an input with a pull-up resistor enabled. Notice you can also # use properties to change this state. #pin1.value = True #print("pin1 on") #time.sleep(600) # Now loop blinking the pin 0 output and reading the state of pin 1 input. sleep_time = 1