def __init__(self, i2c, columns, lines): # pylint: disable=too-many-locals """Initialize RGB character LCD connected to shield using I2C connection on the specified I2C bus with the specified number of columns and lines on the display. """ import adafruit_mcp230xx self._mcp = adafruit_mcp230xx.MCP23017(i2c) reset = self._mcp.get_pin(15) read_write = self._mcp.get_pin(14) enable = self._mcp.get_pin(13) db4 = self._mcp.get_pin(12) db5 = self._mcp.get_pin(11) db6 = self._mcp.get_pin(10) db7 = self._mcp.get_pin(9) red = self._mcp.get_pin(6) green = self._mcp.get_pin(7) blue = self._mcp.get_pin(8) self._left_button = self._mcp.get_pin(4) self._up_button = self._mcp.get_pin(3) self._down_button = self._mcp.get_pin(2) self._right_button = self._mcp.get_pin(1) self._select_button = self._mcp.get_pin(0) self._buttons = [ self._left_button, self._up_button, self._down_button, self._right_button, self._select_button ] for pin in self._buttons: pin.switch_to_input(pull=digitalio.Pull.UP) super().__init__(reset, enable, db4, db5, db6, db7, columns, lines, red, green, blue, read_write)
def IC_init(): adc = list() gpioe = list() adc_add = list() gpio_add = list() for sysitr in range(totsys): sysnum = sysitr + 1 confsec = 'EVE' + str(sysnum) if config[confsec].getboolean('enabled'): adc_add.append(config[confsec].getint('a_address')) if not config[confsec].getboolean('Pi_pins'): gpio_add.append(config[confsec].getint('m_address')) adc_add = list(set(adc_add)) gpio_add = list(set(gpio_add)) i2c = busio.I2C(board.SCL, board.SDA) if adc_add: for add in adc_add: adc.append(ADS.ADS1015(i2c, address=add)) if gpio_add: for add in gpio_add: gpioe.append(adafruit_mcp230xx.MCP23017(i2c, address=add)) return { 'adc': adc, 'gpioe': gpioe, 'adc_add': adc_add, 'gpio_add': gpio_add }
def __init__(self, i2c): self.mcp = adafruit_mcp230xx.MCP23017(i2c) self.mcp.iodir = 0x0000 # Make all pins outputs # Configure the individual control pins self.mode_pin = self.mcp.get_pin(8) self.mode_pin.direction = digitalio.Direction.OUTPUT self.mode_pin.value = PROGRAMMER_USE self.write_pin = self.mcp.get_pin(9) self.write_pin.direction = digitalio.Direction.OUTPUT self.write_pin.value = WRITE_DISABLED self.chip_select_pin = self.mcp.get_pin(10) self.chip_select_pin.direction = digitalio.Direction.OUTPUT self.chip_select_pin.value = CHIP_DISABLED self.address_clock_pin = self.mcp.get_pin(11) self.address_clock_pin.direction = digitalio.Direction.OUTPUT self.address_clock_pin.value = CLOCK_INACTIVE self.clock_reset_pin = self.mcp.get_pin(12) self.clock_reset_pin.direction = digitalio.Direction.OUTPUT self.clock_reset_pin.value = RESET_INACTIVE self.led_pin = self.mcp.get_pin(13) self.led_pin.direction = digitalio.Direction.OUTPUT self.led_pin.value = False
def _connect_to_hardware(self): import board import busio import adafruit_mcp230xx self.i2c = busio.I2C(board.SCL, board.SDA) self.sensor = adafruit_mcp230xx.MCP23017(self.i2c) self.setup_relays()
def get_mcp(i2c_address): """Returns an MCP23017 chip object.""" import adafruit_mcp230xx import board import busio i2c = busio.I2C(board.SCL, board.SDA) mcp = adafruit_mcp230xx.MCP23017(i2c, address=i2c_address) return mcp
def __init__(self, i2c, address=0): # Match the Arduino code, addresses start at 0x20 address = address + 0x20 self.i2c = i2c self.mcp = adafruit_mcp230xx.MCP23017(self.i2c, address) # Sets all the MCP pins to output for i in range(0, 16): self.mcp.get_pin(i).direction = digitalio.Direction.OUTPUT self.fliptime = 0.090 self.i2c.unlock()
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the MCP23017 devices.""" invert_logic = config.get(CONF_INVERT_LOGIC) i2c_address = config.get(CONF_I2C_ADDRESS) i2c = busio.I2C(board.SCL, board.SDA) mcp = adafruit_mcp230xx.MCP23017(i2c, address=i2c_address) switches = [] pins = config.get(CONF_PINS) for pin_num, pin_name in pins.items(): pin = mcp.get_pin(pin_num) switches.append(MCP23017Switch(pin_name, pin, invert_logic)) add_entities(switches)
def _load_expander_netlist(self): with open('expander-netlist.csv', 'r') as csvfile: mapreader = csv.reader(csvfile, delimiter=';') for row in mapreader: if len(row) == 3: if row[0] not in self._mcps: self._mcps[row[0]] = adafruit_mcp230xx.MCP23017( self._i2c, address=int(row[0], base=16)) self._pins[row[2]] = self._mcps[row[0]].get_pin( self._decode_padname_to_pin(row[1])) elif len(row) == 1 and row[0][0] == '#': pass else: raise AssertionError( "Unable to parse row from netlist file.")
def __init__(self, address=0x20, label='F'): self._i2c = I2C() self.address = address self.label = label try: self._driver = adafruit_mcp230xx.MCP23017(self._i2c.i2c, address=self.address) for pin in self._pinmap[1:] + (self._status, ): self._driver.get_pin( pin).direction = digitalio.Direction.OUTPUT self._driver.get_pin(pin).value = False self.status(True) except (OSError, ValueError): print("No such device %x" % self.address) raise
def __init__(self, i2c, columns, lines, backlight_inverted=False): import adafruit_mcp230xx self._mcp = adafruit_mcp230xx.MCP23017(i2c) reset = self._mcp.get_pin(15) read_write = self._mcp.get_pin(14) enable = self._mcp.get_pin(13) db4 = self._mcp.get_pin(12) db5 = self._mcp.get_pin(11) db6 = self._mcp.get_pin(10) db7 = self._mcp.get_pin(9) red = self._mcp.get_pin(6) green = self._mcp.get_pin(7) blue = self._mcp.get_pin(8) self._left_button = self._mcp.get_pin(4) self._up_button = self._mcp.get_pin(3) self._down_button = self._mcp.get_pin(2) self._right_button = self._mcp.get_pin(1) self._select_button = self._mcp.get_pin(0) #backlight backlight_pin = self._mcp.get_pin(5) self._buttons = [ self._left_button, self._up_button, self._down_button, self._right_button, self._select_button ] for pin in self._buttons: pin.switch_to_input(pull=digitalio.Pull.UP) super().__init__(reset, enable, db4, db5, db6, db7, columns, lines, red, green, blue, read_write, backlight_pin=backlight_pin, backlight_inverted=backlight_inverted)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the MCP23017 binary sensors.""" pull_mode = config[CONF_PULL_MODE] invert_logic = config[CONF_INVERT_LOGIC] i2c_address = config[CONF_I2C_ADDRESS] i2c = busio.I2C(board.SCL, board.SDA) mcp = adafruit_mcp230xx.MCP23017(i2c, address=i2c_address) binary_sensors = [] pins = config[CONF_PINS] for pin_num, pin_name in pins.items(): pin = mcp.get_pin(pin_num) binary_sensors.append( MCP23017BinarySensor(pin_name, pin, pull_mode, invert_logic)) add_devices(binary_sensors, True)
def __init__(self, i2c, columns, lines): # pylint: disable=too-many-locals """Initialize RGB character LCD connected to shield using I2C connection on the specified I2C bus with the specified number of columns and lines on the display. """ import adafruit_mcp230xx self._mcp = adafruit_mcp230xx.MCP23017(i2c) reset = self._mcp.get_pin(15) read_write = self._mcp.get_pin(14) enable = self._mcp.get_pin(13) db4 = self._mcp.get_pin(12) db5 = self._mcp.get_pin(11) db6 = self._mcp.get_pin(10) db7 = self._mcp.get_pin(9) red = self._mcp.get_pin(6) green = self._mcp.get_pin(7) blue = self._mcp.get_pin(8) super().__init__(reset, enable, db4, db5, db6, db7, columns, lines, red, green, blue, read_write)
import board import busio from Adafruit_MotorHAT import Adafruit_MotorHAT from RPi import GPIO from celery import shared_task, current_task from celery.utils.log import get_task_logger LOGGER = get_task_logger(__name__) CLK = 18 MISO = 23 MOSI = 24 CS = 25 MCP3008 = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI) I2C = busio.I2C(board.SCL, board.SDA) MCP23017 = adafruit_mcp230xx.MCP23017(I2C) MOTOR_HAT = Adafruit_MotorHAT(addr=0x60) GPIO.setmode(GPIO.BCM) GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP) def turn_off_motors(): """ Stop the 4 motor pulses """ MOTOR_HAT.getMotor(1).run(Adafruit_MotorHAT.RELEASE) MOTOR_HAT.getMotor(2).run(Adafruit_MotorHAT.RELEASE) MOTOR_HAT.getMotor(3).run(Adafruit_MotorHAT.RELEASE) MOTOR_HAT.getMotor(4).run(Adafruit_MotorHAT.RELEASE)
#GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP) #GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Declaración de Variables de Interrupciones # Initialize the I2C bus: i2c = busio.I2C(board.SCL, board.SDA) # Hardware SPI configuration: SPI_PORT = 0 SPI_DEVICE = 0 mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE)) # Create an instance of either the MCP23008 or MCP23017 class depending on # which chip you're using: mcp = adafruit_mcp230xx.MCP23017(i2c) # MCP23017 mcp2 = adafruit_mcp230xx.MCP23017(i2c) # MCP23017-2 # Optionally change the address of the device if you set any of the A0, A1, A2 # pins. Specify the new address with a keyword parameter: mcp2 = adafruit_mcp230xx.MCP23017(i2c, address=0x21) # MCP23017 w/ A0 set # Now call the get_pin function to get an instance of a pin on the chip. # This instance will act just like a digitalio.DigitalInOut class instance # and has all the same properties and methods (except you can't set pull-down # resistors, only pull-up!). For the MCP23008 you specify a pin number from 0 # to 7 for the GP0...GP7 pins. For the MCP23017 you specify a pin number from # 0 to 15 for the GPIOA0...GPIOA7, GPIOB0...GPIOB7 pins (i.e. pin 12 is GPIOB4). pin0 = mcp.get_pin(0) pin1 = mcp.get_pin(1) pin2 = mcp.get_pin(2)
def __init__(self, sysnum): self.sysnum = sysnum self.sysstr = 'EVE' + str(self.sysnum) self.config = configparser.ConfigParser() self.config.read('eve-conf.ini') # Define Experiment Variables self.time_between_pumps = self.config[self.sysstr].getfloat('time_between_pumps') self.OD_thr = self.config[self.sysstr].getfloat('OD_thr') self.OD_min = self.config[self.sysstr].getfloat('OD_min') self.time_between_ODs = self.config[self.sysstr].getfloat('time_between_ODs') # how often to gather OD data, in seconds self.time_between_graphs = self.config[self.sysstr].getfloat('time_between_graphs') # how often to graph, in minutes # OD_thr is the threshold above which to activate drug pump [vish bench tests: empty: 3.5V, Clear Vial: 0.265V, Very Cloudy Vial: 2.15V] #time_between_writes = 1 # how often to write out OD data, in minutes #loops_between_writes = (time_between_writes*60)/time_between_ODs # time bewteen writes in loops self.time_between_saves = self.config[self.sysstr].getfloat('time_between_saves') # Set Up I2C to Read OD Data # Create the I2C bus self.P_drug_times = self.config[self.sysstr].getfloat('P_drug_times') self.P_nut_times = self.config[self.sysstr].getfloat('P_nut_times') self.P_waste_times = self.config[self.sysstr].getfloat('P_waste_times') self.running_data = [] # the list which will hold our 2-tuples of time and OD self.pump_data = [] self.OD_tmplist = [] self.pump_tmplist = [] # self.currOD = np.zeros(num_cham) self.currOD = 0 # averaged OD value # self.avOD = np.zeros(num_cham) self.avOD = 0 self.OD_av_length = self.config[self.sysstr].getint('OD_av_length') # OD averaging buffer self.avOD_buffer = np.zeros(self.OD_av_length)#need to change for multiplexing self.elapsed_loop_time = 0 self.loops = 0 self.last_dilutionOD = 0 self.nut = 0 self.drug = 1 self.waste = 2 self.drug_mass = 0 self.total_time = self.config[self.sysstr].getfloat('Exp_time_hours')*3600 #in seconds self.loops_between_ODs = 1 self.loops_between_pumps = (self.time_between_pumps*60)/self.time_between_ODs # time between pumps in loops # num_cham = 1 # number of morbidostat vials being used self.i2c = busio.I2C(board.SCL, board.SDA) # # Create the ADC object using the I2C bus self.ads = ADS.ADS1015(self.i2c) # # Create single-ended input on channel 0 # # photoreceptor_channel = 0 self.photod = AnalogIn(self.ads, getattr(ADS,'P'+ str(self.config[self.sysstr].getint('Analogin')))) # Setup the GPIO Pins to Control the Pumps self.pipins = self.config[self.sysstr].getboolean('Pi_pins') self.P_drug_pins = self.config[self.sysstr].getint('P_drug_pins') self.P_nut_pins = self.config[self.sysstr].getint('P_nut_pins') self.P_waste_pins = self.config[self.sysstr].getint('P_waste_pins') self.P_LED_pins = self.config[self.sysstr].getint('P_LED_pins') # P_fan_pins = self.config[self.sysstr].getint('P_fan_pins') self.pin_list = [self.P_drug_pins, self.P_nut_pins, self.P_waste_pins, self.P_LED_pins] if self.pipins: GPIO.setmode(GPIO.BCM) for pin in self.pin_list: GPIO.setup(pin, GPIO.OUT) else: self.pins = [None]*(max(self.pin_list)+1) self.mcp = adafruit_mcp230xx.MCP23017(self.i2c, address=self.config[self.sysstr].getint('m_address')) for pin in self.pin_list: self.pins[pin] = self.mcp.get_pin(pin) self.pins[pin].direction = digitalio.Direction.OUTPUT self.pins[pin].value = False self.writer = 0 self.init_time = datetime.now() self.slack_client = SlackClient(self.config['MAIN']['slack_key']) # self.chanid = self.config['MAIN']['slack_chanid'] self.slack_usericon = self.config[self.sysstr]['slack_icon'] self.chan = self.config['MAIN']['slack_channel'] self.slack_client.api_call( "chat.postMessage", channel = self.chan, username=self.sysstr, icon_url = self.slack_usericon, text = self.init_time.strftime('Initialized at %H:%M:%S') )
import board import busio from digitalio import Direction, Pull import adafruit_mcp230xx # Initialize the I2C bus: i2c = busio.I2C(board.SCL, board.SDA) # Initialize the MCP23017 chip on the bonnet mcp = adafruit_mcp230xx.MCP23017(i2c) # Optionally change the address of the device if you set any of the A0, A1, A2 # pins. Specify the new address with a keyword parameter: #mcp = adafruit_mcp230xx.MCP23017(i2c, address=0x21) # MCP23017 w/ A0 set # Make a list of all the port A pins (a.k.a 0-7) port_a_pins = [] for pin in range(0, 8): port_a_pins.append(mcp.get_pin(pin)) # Make a list of all the port B pins (a.k.a 8-15) port_b_pins = [] for pin in range(8, 16): port_b_pins.append(mcp.get_pin(pin)) # Set all the port A pins to output for pin in port_a_pins: pin.direction = Direction.OUTPUT # Set all the port B pins to input, with pullups! for pin in port_b_pins:
import RPi.GPIO as GPIO import adafruit_mcp230xx import digitalio import board import busio import adafruit_ads1x15.ads1015 as ADS from adafruit_ads1x15.analog_in import AnalogIn #import numpy as np # Create the I2C bus i2c = busio.I2C(board.SCL, board.SDA) # Create the ADC object using the I2C bus ads = ADS.ADS1015(i2c) mcp = adafruit_mcp230xx.MCP23017(i2c, address=32) # Create single-ended input on channel 0 # photoreceptor_channel = 0 pd = AnalogIn(ads, ADS.P0) # setup the GPIO pins to control the pumps P_drug_pins = [0] P_nut_pins = [1] P_waste_pins = [2] P_LED_pins = [3] # P_fan_pins = [4] pin_list = P_drug_pins + P_nut_pins + P_waste_pins + P_LED_pins pins = list()