Exemple #1
0
  def __init__(self):
    self.lcd = progress_lcd.ProgressLCD(rs_pin=17, en_pin=27, d4_pin=9, d5_pin=11, d6_pin=5, d7_pin=6)
    self.lcd.display_message('Welcome, Time-Traveller!')
    GPIO.setmode(GPIO.BCM)


    self.aux_systems_to_pins = {'Forward Deflector':4, 'Morlock Suppressor':0, 'Turbo Encabulator':5, 'Spline Reticulator':1, 'Flux Capacitor':2, 'Stallyn\'s Amps':6, 'Eye of Harmony':3, 'Improbability Drive':7}
    self.inverter_pins = [12, 8, 13, 9, 11, 15, 10, 14]
    self.shunt_pins = [15, 14, 13, 12, 11, 10, 9, 8]
    self.reactor_pin = 4
    self.tachyon_pins = [22, 10]


    self.tachyon_pins = [22, 10]
    self.reactor_pin = 4
    self.grav_pins = [8, 25, 24, 23, 18, 21, 20, 16, 12, 7]
    for pin in [self.reactor_pin]+self.tachyon_pins+self.grav_pins:
      GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    self.MCP0 = MCP230xx.MCP23017(0x20)
    self.MCP7 = MCP230xx.MCP23017(0x27)
    for pin in range(16):
      for MCP in [self.MCP0, self.MCP7]:
        MCP.setup(pin, GPIO.IN)
        MCP.pullup(pin, True)


    self.controls = control_manager.SpaceTeamControls()


    # MCP0 controls
    self.controls.make_button_array('inverters{}', self.MCP0.input, self.inverter_pins, 
                                    button_text = "Invert residuum {}!")
    for name, pin in self.aux_systems_to_pins.iteritems():
      self.controls.make_toggle(name, control_manager.toggle_reader(pin, self.MCP0.input), 
                                toggle_texts=['Route auxilliary power to the {}'.format(name),
                                              'Cut auxilliary power to the {}'.format(name)])

    #MCP7 controls
    self.controls.make_toggle_array('shunt{}', self.MCP7.input, self.shunt_pins, 
                                    toggle_texts=['Enable cyclotron shunt {}', 
                                                  'Disable cyclotron shunt {}'])

    #GPIO controls
    self.controls.make_toggle('reactor', control_manager.toggle_reader(self.reactor_pin, GPIO.input),
                              toggle_texts=['Engage the chronotonic reactor!',
                                            'DISENGAGE CHRONOTONIC REACTOR'])
    self.controls.make_button_array('tachyon{}', GPIO.input, self.tachyon_pins,
                                    button_text='Bleed tachyoners from valve {}')
    self.controls.make_toggle_array('graviton{}', GPIO.input, self.grav_pins,
                                    toggle_texts=['Disengage graviton flux restrictor {}!',
                                                  'Engage graviton flux restrictor {}!'])

    self._state = self.controls.read_state()
Exemple #2
0
	def __init__(self):
		#2 frames at 30fps (~66ms)
		self.debounce = 2
		#I2C addresses where we can find our port expander
		addresses = [0x20, 0x21]
		self.mcps = [MCP230XX.MCP23017(address = addr) for addr in addresses]
		#port mappings
		self.port_mappings = [{'C4': 4, 'C#4': 8, 'D4': 3, 'D#4': 9, \
		'E4': 15, 'F4': 14, 'F#4': 10,'G4': 13, 'G#4': 7, 'A4': 12,\
		'A#4': 6, 'B4': 11},{'C3': 13, 'C#3': 0, 'D3': 12, 'D#3': 1, \
		'E3': 11, 'F3': 10, 'F#3': 2, 'G3': 9, 'G#3': 15, 'A3': 8,\
		'A#3': 14, 'B3': 3}]
		self.LOW = 0
		self.HIGH = 1
		#current state
		self.state = []
		#cooldowns
		self.cooldown = []
		self.updates = {}
		for mcp,mappings in zip(self.mcps, self.port_mappings):
			state = {}
			cooldown = {}
			for _,pin in mappings.items():
				#Setup pin as input
				mcp.setup(pin, MCP230XX.GPIO.IN)
				mcp.pullup(pin, 1)
    			#Create initial state and cooldown
				state[pin] = self.HIGH
				cooldown[pin] = self.debounce
			self.state.append(state)
			self.cooldown.append(cooldown)
Exemple #3
0
def speedometer(speed):
    if speed > SPEED_LIMIT:
        speed = SPEED_LIMIT
    speed_percent = (speed * 100) / SPEED_LIMIT
    leds_lit = (NUM_LEDS * speed_percent) / 100
    leds_lit = int(math.ceil(leds_lit))
    print('LEDs lit: {}/{}'.format(str(leds_lit), str(NUM_LEDS)))
    mcp = MCP230xx.MCP23017()
    for pin in MCP_PINS:
        mcp.setup(pin, GPIO.OUT)
    for _i in range(0, 10):
        for pin in MCP_PINS:
            mcp.output(pin, 1)
            time.sleep(BLINK_SPEED)
            next_pin = pin + 1
            mcp.output(next_pin, 1)
            mcp.output(pin, 0)
            time.sleep(BLINK_SPEED)
        for pin in MCP_PINS_R:
            mcp.output(pin, 1)
            time.sleep(BLINK_SPEED)
            prev_pin = pin - 1
            if (prev_pin != -1):
                mcp.output(prev_pin, 1)
                mcp.output(pin, 0)
                time.sleep(BLINK_SPEED)
    i = 1
    for pin in MCP_PINS:
        if leds_lit >= i:
            mcp.output(pin, 1)
            time.sleep(BLINK_SPEED)
        else:
            mcp.output(pin, 0)
        i += 1
 def __init__(self):
     self.__chip1 = MCP230xx.MCP23017(0x20)
     self.__chip2 = MCP230xx.MCP23017(0x21)
     self.__chip3 = MCP230xx.MCP23017(0x22)
     self.__chip4 = MCP230xx.MCP23017(0x23)
     self.__arduino = serial.Serial('/dev/ttyACM0',9600)
     for i in range(16):
         self.__chip1.setup(i,1)
         self.__chip2.setup(i,1)
         self.__chip3.setup(i,1)
         self.__chip4.setup(i,1)
     self.__board_pos = [b'0']*64
     self.__last_board_pos = [0]*64
     self.itt = 0
     self.temp = [b'0']*64
     self.last_byte = [b'0']*64
Exemple #5
0
def speedometer(speed):
    if speed > SPEED_LIMIT: speed = SPEED_LIMIT
    speed_percent = (speed * 100) / SPEED_LIMIT
    leds_lit = (NUM_LEDS * speed_percent) / 100
    leds_lit = int(math.ceil(leds_lit))
    print('LEDs lit: {}/{}'.format(str(leds_lit), str(NUM_LEDS)))
    mcp = MCP230xx.MCP23017()
    for PIN in MCP_PINS:
        mcp.setup(PIN, GPIO.OUT)
    for i in range(0, 10):
        for PIN in MCP_PINS:
            mcp.output(PIN, 1)
            time.sleep(BLINK_SPEED)
            NEXT_PIN = PIN + 1
            mcp.output(NEXT_PIN, 1)
            mcp.output(PIN, 0)
            time.sleep(BLINK_SPEED)
        for PIN in MCP_PINS_R:
            mcp.output(PIN, 1)
            time.sleep(BLINK_SPEED)
            PREV_PIN = PIN - 1
            if (PREV_PIN != -1):
                mcp.output(PREV_PIN, 1)
                mcp.output(PIN, 0)
                time.sleep(BLINK_SPEED)
    i = 1
    for PIN in MCP_PINS:
        if leds_lit >= i:
            mcp.output(PIN, 1)
            time.sleep(BLINK_SPEED)
        else:
            mcp.output(PIN, 0)
        i += 1
Exemple #6
0
 def __init__(self,
              address=0x20,
              busnum=I2C.get_default_bus(),
              cols=16,
              lines=2):
     """Initialize the character LCD plate.  Can optionally specify a separate
     I2C address or bus number, but the defaults should suffice for most needs.
     Can also optionally specify the number of columns and lines on the LCD
     (default is 16x2).
     """
     # Configure MCP23017 device.
     self._mcp = MCP.MCP23017(address=address, busnum=busnum)
     # Set LCD R/W pin to low for writing only.
     self._mcp.setup(LCD_PLATE_RW, GPIO.OUT)
     self._mcp.output(LCD_PLATE_RW, GPIO.LOW)
     # Set buttons as inputs with pull-ups enabled.
     for button in (SELECT, RIGHT, DOWN, UP, LEFT):
         self._mcp.setup(button, GPIO.IN)
         self._mcp.pullup(button, True)
     # Initialize LCD (with no PWM support).
     super(Adafruit_CharLCDPlate, self).__init__(LCD_PLATE_RS,
                                                 LCD_PLATE_EN,
                                                 LCD_PLATE_D4,
                                                 LCD_PLATE_D5,
                                                 LCD_PLATE_D6,
                                                 LCD_PLATE_D7,
                                                 cols,
                                                 lines,
                                                 LCD_PLATE_RED,
                                                 LCD_PLATE_GREEN,
                                                 LCD_PLATE_BLUE,
                                                 enable_pwm=False,
                                                 gpio=self._mcp)
Exemple #7
0
def main():
    print read_config()
    raw_input("Press Enter to continue...")
    mcp = MCP230xx.MCP23017(0x20)
    setup_mcp(mcp)
    while True:
        config = read_config_mcp(mcp)
        print config[0], config[1]
Exemple #8
0
 def __init__(self, i2c_address, max_bit):
     self.i2c_address = i2c_address
     self._mcp = MCP.MCP23017(address = i2c_address)
     if self._mcp is None:
         raise Exception("Unable to instantiate MCP")
     self.bit_range = range(0, max_bit)
     for b in self.bit_range:
         self._mcp.setup(b, GPIO.OUT)
 def __init__(self, address, pins=None):
     if not pins:
         pins = range(16)
     self._pins = [int(pin) for pin in pins]
     self._address = int(address) + 0x20
     self._mcp = MCP230xx.MCP23017(self._address)
     for pin in self._pins:
         self._mcp.setup(pin, GPIO.IN)
         self._mcp.pullup(pin, True)
     self.state = self.read_state()
Exemple #10
0
def read_config():
    result = []
    for address in range(0x20, 0x28):
        try:
            mcp = MCP230xx.MCP23017(address)
        except IOError:
            return result
        setup_mcp(mcp)
        result += [read_config_mcp(mcp)]
    return result
Exemple #11
0
    def __init__(self, address=0x20):
        self.mMcp = MCP.MCP23017(
            address)  #create an object to interface with io expander
        self.mLcd = LCD.Adafruit_CharLCDBackpack()
        self.mLcd.set_backlight(0)
        self.mLcd.clear()
        self.mLcd.blink(True)

        for i in range(self.mRows):  #set pins GPA3-A6 as input pins
            self.mMcp.setup(self.mRowPins[i], GPIO.IN)
            self.mMcp.pullup(self.mRowPins[i], True)
            self.mMcp.setup(self.mRelayPins[i], GPIO.OUT)
            self.mMcp.output(self.mRelayPins[i], GPIO.HIGH)
Exemple #12
0
    def __init__(self):
        #self.gpio = GPIO.get_platform_gpio()
        self.mcpi2c = MCP.MCP23017(0x20, busnum=1)
        #self.gpio.setup(SH74HC595._DATA_pin, GPIO.OUT)
        self.mcpi2c.setup(SH74HC595._DATA_pin, MCP.GPIO.OUT)
        #self.gpio.setup(SH74HC595._LATCH_pin, GPIO.OUT)
        self.mcpi2c.setup(SH74HC595._LATCH_pin, MCP.GPIO.OUT)
        #self.gpio.setup(SH74HC595._CLOCK_pin, GPIO.OUT)
        self.mcpi2c.setup(SH74HC595._CLOCK_pin, MCP.GPIO.OUT)

        # is used to store states of all pins
        self._registers = list()
        # How many of the shift registers - you can change them with shiftRegisters method
        self._number_of_shiftregisters = 1
Exemple #13
0
    def __init__(self, i2c_address, max_bit, update_rate_hz=100):
        self.i2c_address = i2c_address
        self.bit_range = range(0, max_bit)  # the bits we're interested in
        self._mcp = MCP.MCP23017(address=i2c_address)
        if self._mcp is None:
            raise Exception("Unable to instantiate MCP")
        for b in self.bit_range:
            self._mcp.setup(b, GPIO.IN)
            self._mcp.pullup(b, True)
        self.update_rate_hz = update_rate_hz

        self.runner = Thread(target=self.loop)
        self.runner.setDaemon(True)
        self.runner.start()
    def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None,
                 gpio=None, spi=None, i2c_bus=None, i2c_address=SSD1306_I2C_ADDRESS,
                 i2c=None, mcp_rst=None, mcp_address=None):
        self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base')
        self._spi = None
        self._i2c = None
        self.width = width
        self.height = height
        self._pages = height//8
        self._buffer = [0]*(width*self._pages)
        # Default to platform GPIO if not provided.
        self._gpio = gpio
        # Instantiate MCP if rst pin is in mcp.
        if mcp_rst is not None and mcp_address is not None:
            self.__mcp_rst = mcp_rst
            self.__mcp = MCP.MCP23017(mcp_address, busnum=1)
		    self.__mcp.setup(self.__mcp_rst, MCP.GPIO.OUT)
Exemple #15
0
#!/usr/bin/python3
import time

import Adafruit_GPIO as GPIO
import Adafruit_GPIO.MCP230xx as MCP230xx

mcp = MCP230xx.MCP23017(
)  # This assumes the MCP23017 is at the default address 0x20, if not pass in an argument with the actual address in hex.

# Setup pin 1 as an output and pin 2 as an input, very similar to RPi.GPIO library.
mcp.setup(0, GPIO.OUT)
mcp.setup(1, GPIO.OUT)
mcp.setup(2, GPIO.OUT)
mcp.setup(3, GPIO.OUT)
mcp.setup(4, GPIO.OUT)
mcp.setup(5, GPIO.OUT)
mcp.setup(6, GPIO.OUT)
mcp.setup(7, GPIO.OUT)
mcp.setup(8, GPIO.OUT)
mcp.setup(9, GPIO.OUT)
mcp.setup(10, GPIO.OUT)
mcp.setup(11, GPIO.OUT)
mcp.setup(12, GPIO.OUT)
mcp.setup(13, GPIO.OUT)
mcp.setup(14, GPIO.OUT)
mcp.setup(15, GPIO.OUT)

# Loop forever blinking pin 1 high and low every second.
while True:
    mcp.output(0, GPIO.HIGH)
    time.sleep(1.0)
Exemple #16
0
#https://www.youtube.com/watch?v=MCGeeqKfv7Q
#
import Adafruit_DHT
import BMP085
from time import sleep
import datetime
from utilities import *
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
import Adafruit_GPIO as GPIO
from Adafruit_GPIO import MCP230xx
from time import sleep

mcp = MCP230xx.MCP23017(busnum=1, address=0x20)  #io expander
mcp.setup(0, GPIO.IN)

RST = None
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

disp.begin()
disp.clear()
disp.display()
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
Exemple #17
0
        drawTarget()
        disp.image(image)
        disp.display()


def shoot():
    print('%s %s' % (posShipX+3, posShipY))
    bullets.append({'x': posShipX+3, 'y': posShipY})


def createTargets():
    pass


if __name__ == '__main__':
    mcpi2c = MCP.MCP23017(0x20, busnum=1)
    # use pin 0 as OUTPUT, 1 as INPUT pin
    mcpi2c.setup(0, MCP.GPIO.OUT)
    mcpi2c.setup(1, MCP.GPIO.IN)
    print('start')

    initDisp()
    drawShip()

    start_new_thread(input_thread, (mcpi2c,))

    while 1:
        try:
            # Quick example: DONT DO THIS:
            time.sleep(5)
        except KeyboardInterrupt:
Exemple #18
0
lcd_d6 = 4
lcd_d7 = 5
lcd_red = 6
lcd_green = 7
lcd_blue = 8

# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows = 2

# Alternatively specify a 20x4 LCD.
# lcd_columns = 20
# lcd_rows    = 4

# Initialize MCP23017 device using its default 0x20 I2C address.
gpio = MCP.MCP23017()

# Alternatively you can initialize the MCP device on another I2C address or bus.
# gpio = MCP.MCP23017(0x24, busnum=1)

# Initialize the LCD using the pins
lcd = LCD.Adafruit_RGBCharLCD(lcd_rs,
                              lcd_en,
                              lcd_d4,
                              lcd_d5,
                              lcd_d6,
                              lcd_d7,
                              lcd_columns,
                              lcd_rows,
                              lcd_red,
                              lcd_green,
DIGITEMP_SENSORS = "/tmp/imager_safetyd.temperature"

LCD_RS = 0
LCD_EN = 1
LCD_D4 = 2
LCD_D5 = 3
LCD_D6 = 4
LCD_D7 = 5
LCD_RED = 6
LCD_GREEN = 7
LCD_BLUE = 8

LCD_COLUMNS = 20
LCD_ROWS = 4

GPIO = MCP.MCP23017(busnum=2)

LCD = LC.Adafruit_RGBCharLCD(LCD_RS,
                             LCD_EN,
                             LCD_D4,
                             LCD_D5,
                             LCD_D6,
                             LCD_D7,
                             LCD_COLUMNS,
                             LCD_ROWS,
                             LCD_RED,
                             LCD_GREEN,
                             LCD_BLUE,
                             gpio=GPIO)

Exemple #20
0
        while curr < max:
            pwm.set_pwm(channel, 0, curr)
            pwm.set_pwm(channel2, 0, curr)
            curr += step
            time.sleep(t)
    else:
        curr = max
        while curr > min:
            pwm.set_pwm(channel, 0, curr)
            pwm.set_pwm(channel2, 0, curr)
            curr -= step
            time.sleep(t)


if __name__ == '__main__':
    mcp = MCP.MCP23017(
        0x24)  # MCP23017 creating an object of the class called MCP
    pwm = PWM.PCA9685()
    pwm.set_pwm_freq(500)
    min = 409
    max = 4095
    Flag = 0  #Motion not  detected
    counter = 0

    lcd_columns = 16
    lcd_rows = 2
    lcd = LCD.Adafruit_CharLCDBackpack()
    lcd.set_backlight(0)
    lcd.clear()

    detected = False
Exemple #21
0
 def __init__(self, address=0x20):
     try:
         self.mMcp = MCP.MCP23017(address)
         self.getPos()
     except Exception as ex:
         print("Error getting the position", ex)
##
# Maker's Digest
#
# MCP23017 GPIO Expander Example
#
# Dont forget to install the libraries! See README.md for details.
##
from time import sleep  # Import sleep from time
import Adafruit_GPIO.MCP230xx as MCP230XX  # Import Adafruit MCP23017 Library

mcp = MCP230XX.MCP23017()  # Instantiate mcp object
dly = .25  # Set delay of 1/4 second

# Setup Outputs.
# We loop through all 16 GPIO to set them as GPIO.OUT, which
# needs to be referenced as MCP230XX.GPIO.OUT.
#
# If you are only using one or two of the GPIO pins on the
# mcp23017, you can set them up for outputs individually as:
# mcp.setup(0, MCP230XX.GPIO.OUT)
# OR
# mcp.setup(0, MCP230XX.GPIO.IN)
#
# See Adafruit_Python_GPIO on github for more details on
# using this library.
for x in range(0, 16):
    mcp.setup(x, MCP230XX.GPIO.OUT)


# Main Program
# Loop through all 16 GPIO to set high, then low.
Exemple #23
0
### Define MCP pins connected to LCD
lcd_rs = 6
lcd_en = 4
lcd_d4 = 3
lcd_d5 = 2
lcd_d6 = 1
lcd_d7 = 0
lcd_backlight = None

### Define LCD type
lcd_columns = 20
lcd_rows = 4

### Initialize MCP23017 for LCD
gpiomcp = MCP.MCP23017(0x20, busnum=1)

### Initialize LCD panel parameters
lcd = LCD.Adafruit_CharLCD(lcd_rs,
                           lcd_en,
                           lcd_d4,
                           lcd_d5,
                           lcd_d6,
                           lcd_d7,
                           lcd_columns,
                           lcd_rows,
                           lcd_backlight,
                           gpio=gpiomcp)
lcd.show_cursor(False)
lcd.blink(False)
lcd.clear()
import sys
import time
import paho.mqtt.client as mqtt

import Adafruit_GPIO.MCP230xx as MCP
import Adafruit_GPIO as GPIO

broker = "broker.iot-br.com"
port = 8080
keppAlive = 60
topic = 'DZ/rasp/relay/#'

mcp = MCP.MCP23017()
mcp.setup(0, GPIO.OUT)


def on_connect(client, userdata, flags, rc):
    print("[STATUS] Conectado ao Broker. Resultado de conexao: " + str(rc))

    client.subscribe(topic)


def on_message(client, userdata, msg):
    message = str(msg.payload)  # converte a mensagem recebida
    print("[MSG RECEBIDA] Topico: " + msg.topic + " / Mensagem: " + message)

    topic = str(msg.topic).split('/')
    relayName = int(topic[3])

    if message == '1':
        mcp.output(relayName, True)
Exemple #25
0
##
# Maker's Digest
#
# MCP23017 GPIO Expander Example
#
# Dont forget to install the libraries! See README.md for details.
##
from time import sleep  # Import sleep from time
import Adafruit_GPIO.MCP230xx as MCP230XX  # Import Adafruit MCP23017 Library

mcp = MCP230XX.MCP23017(address=0x21)  # Instantiate mcp object
REFRESH_RATE = 30.0  # Set delay of 1/4 second
quit_pin = 9
prev_low = {
    0: False,
    1: False,
    2: False,
    3: False,
    4: False,
    5: False,
    6: False,
    7: False,
    8: False,
    9: False,
    10: False,
    11: False,
    12: False,
    13: False,
    14: False,
    15: False,
    16: False