コード例 #1
0
ファイル: chessboard.py プロジェクト: marcosswald/kasparov
    def __init__(self):
        # Pin definition
        self._reset_pin = 27
        self._interrupt_pin = 17
        self._led_green = 14
        self._led_yellow = 15
        self._led_red = 18

        # settings
        self.mode = self.TWO_PLAYER_MODE
        self._computer_color = chess.BLACK

        # Set GPIOs
        GPIO.setmode(GPIO.BCM)  # set GPIO numbering
        GPIO.setup(self._reset_pin, GPIO.OUT)
        GPIO.setup(self._interrupt_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        self.setStatusLed(self._led_green, self.LED_OFF)
        self.setStatusLed(self._led_yellow, self.LED_OFF)
        self.setStatusLed(self._led_red, self.LED_ON)

        # MCP
        GPIO.output(self._reset_pin, GPIO.LOW)  # reset all devices
        time.sleep(0.1)
        GPIO.output(self._reset_pin, GPIO.HIGH)
        self._rowAB = MCP23017(0)  # Device address 0
        self._rowCD = MCP23017(1)  # Device address 1
        self._rowEF = MCP23017(2)  # Device address 2
        self._rowGH = MCP23017(3)  # Device address 3
        self._positions = [[1] * 8] * 8

        # start stockfish engine
        self._engine = chess.uci.popen_engine("stockfish")

        # register interrupt callback
        GPIO.add_event_detect(self._interrupt_pin,
                              GPIO.FALLING,
                              callback=self._onInterruptEvent,
                              bouncetime=10)
        self._board_initialized = False  # board has not yet been initialized
        self.readPositions()  # clear interrupt
コード例 #2
0
    def __init__(self):
        i2c = I2C(-1, Pin(_SCL), Pin(_SDA))

        self._mcp1 = MCP23017(i2c, _ADDR_MCP1, def_inp=0,
                              def_val=1)  # all outputs, all high
        # for pin in range(8):
        #     self._mcp1.decl_output(pin)
        # self._mcp1.decl_output(OutputController._LED_Y)
        # self._mcp1.decl_output(OutputController._LED_G)

        self._mcp2 = MCP23017(
            i2c, _ADDR_MCP2, def_inp=0,
            def_val=0)  # default outputs, all low (no pullups)
        for pin in range(4):  # reset relay outputs (off)
            self._mcp2.decl_output(pin)
            self._mcp2.output(pin, 0)
        self._mcp2.decl_input(_IN_SWITCH_BLF)  # switch input
        self._mcp2.pullup(
            _IN_SWITCH_BLF,
            True)  # additional pullup (also there is the 82k pullup)
        self._mcp2.decl_input(_IN_PWR)  # powered status input

        self._dot = 0  # dot currently lighted?
        self._pattern = 0  # currently displayed segment pattern (without dot)
        self._circle = 1  # lighting pattern of circle if used (1, 2, 4, 8, 16, 32, 1, 2, ...)

        # last read states:
        self.pwr = None
        self.sw_pressed = None  # last switch state (from recent check): down?

        # 0 = normal, 1/2/3/... = special modes (after holding switch down), (-x = reset from special mode)
        # special modes: 1 = 0-100 km/h measurement
        #                on shutdown: mode = 1-9: network control stays on for <mode> hours
        #                             mode >= 10: return to console (hard reset required for normal operation)
        self.mode = 0
        self.rly = {k: False for k in _RLY}  # current relais states (last set)

        self.off()
コード例 #3
0
    def init(cls, i2c):
        cls._i2c = i2c
        cls._mcp23017 = MCP23017(i2c)
        # Display control lines
        cls.EPD_CL = Pin(0, Pin.OUT, value=0)
        cls.EPD_LE = Pin(2, Pin.OUT, value=0)
        cls.EPD_CKV = Pin(32, Pin.OUT, value=0)
        cls.EPD_SPH = Pin(33, Pin.OUT, value=1)
        cls.EPD_OE = cls._mcp23017.pin(0, Pin.OUT, value=0)
        cls.EPD_GMODE = cls._mcp23017.pin(1, Pin.OUT, value=0)
        cls.EPD_SPV = cls._mcp23017.pin(2, Pin.OUT, value=1)
        cls._tsFlag = False
        cls.rotation = 0
        # Display data lines - we only use the Pin class to init the pins
        Pin(4, Pin.OUT)
        Pin(5, Pin.OUT)
        Pin(18, Pin.OUT)
        Pin(19, Pin.OUT)
        Pin(23, Pin.OUT)
        Pin(25, Pin.OUT)
        Pin(26, Pin.OUT)
        Pin(27, Pin.OUT)
        # TPS65186 power regulator control
        cls.TPS_WAKEUP = cls._mcp23017.pin(3, Pin.OUT, value=0)
        cls.TPS_PWRUP = cls._mcp23017.pin(4, Pin.OUT, value=0)
        cls.TPS_VCOM = cls._mcp23017.pin(5, Pin.OUT, value=0)
        cls.TPS_INT = cls._mcp23017.pin(6, Pin.IN)
        cls.TPS_PWR_GOOD = cls._mcp23017.pin(7, Pin.IN)
        # Misc
        cls.GPIO0_PUP = cls._mcp23017.pin(8, Pin.OUT, value=0)
        cls.VBAT_EN = cls._mcp23017.pin(9, Pin.OUT, value=1)
        cls.VBAT = ADC(Pin(35))
        cls.VBAT.atten(ADC.ATTN_11DB)
        cls.VBAT.width(ADC.WIDTH_12BIT)
        #Frontlight
        cls.FRONTLIGHT = cls._mcp23017.pin(11, Pin.OUT, value=0)

        #Toucscreen
        cls._tsXResolution = 0
        cls._tsYResolution = 0
        cls.touchX = 0
        cls.touchY = 0
        cls._xPos = [0,0]
        cls._yPos = [0,0]
        cls.xraw = [0,0]
        cls.yraw = [0,0]
        cls._on = False  # whether panel is powered on or not

        if len(_Inkplate.byte2gpio) == 0:
            _Inkplate.gen_byte2gpio()
コード例 #4
0
    def init(cls, i2c):
        cls._i2c = i2c
        cls._mcp23017 = MCP23017(i2c)
        # Display control lines
        cls.EPD_CL = Pin(0, Pin.OUT, value=0)
        cls.EPD_LE = Pin(2, Pin.OUT, value=0)
        cls.EPD_CKV = Pin(32, Pin.OUT, value=0)
        cls.EPD_SPH = Pin(33, Pin.OUT, value=1)
        cls.EPD_OE = cls._mcp23017.pin(0, Pin.OUT, value=0)
        cls.EPD_GMODE = cls._mcp23017.pin(1, Pin.OUT, value=0)
        cls.EPD_SPV = cls._mcp23017.pin(2, Pin.OUT, value=1)
        # Display data lines - we only use the Pin class to init the pins
        Pin(4, Pin.OUT)
        Pin(5, Pin.OUT)
        Pin(18, Pin.OUT)
        Pin(19, Pin.OUT)
        Pin(23, Pin.OUT)
        Pin(25, Pin.OUT)
        Pin(26, Pin.OUT)
        Pin(27, Pin.OUT)
        # TPS65186 power regulator control
        cls.TPS_WAKEUP = cls._mcp23017.pin(3, Pin.OUT, value=0)
        cls.TPS_PWRUP = cls._mcp23017.pin(4, Pin.OUT, value=0)
        cls.TPS_VCOM = cls._mcp23017.pin(5, Pin.OUT, value=0)
        cls.TPS_INT = cls._mcp23017.pin(6, Pin.IN)
        cls.TPS_PWR_GOOD = cls._mcp23017.pin(7, Pin.IN)
        # Misc
        cls.GPIO0_PUP = cls._mcp23017.pin(8, Pin.OUT, value=0)
        cls.VBAT_EN = cls._mcp23017.pin(9, Pin.OUT, value=1)
        cls.VBAT = ADC(Pin(35))
        cls.VBAT.atten(ADC.ATTN_11DB)
        cls.VBAT.width(ADC.WIDTH_12BIT)
        # Touch sensors
        cls.TOUCH1 = cls._mcp23017.pin(10, Pin.IN)
        cls.TOUCH2 = cls._mcp23017.pin(11, Pin.IN)
        cls.TOUCH3 = cls._mcp23017.pin(12, Pin.IN)

        cls._on = False  # whether panel is powered on or not

        if len(_Inkplate.byte2gpio) == 0:
            _Inkplate.gen_byte2gpio()
コード例 #5
0
ファイル: ctrl.py プロジェクト: stecrz/MicroPython
    def __init__(self):
        i2c = I2C(-1, Pin(_SCL), Pin(_SDA))

        # declare MCP output/inputs:
        self._mcp = MCP23017(i2c, _ADDR_MCP, def_inp=0,
                             def_val=0)  # default output, all low (no pullups)
        for pin in list(_RLY.values()) + [_LED_G, _LED_B, _BUZZER]:
            self._mcp.decl_output(pin)
        self._mcp.decl_input(_IN_SWITCH_BLF)
        self._mcp.pullup(_IN_SWITCH_BLF,
                         True)  # additional pullup, default low
        self._mcp.decl_input(_IN_PWR)
        self._mcp.decl_input(_IN_TEST)
        self._mcp.pullup(_IN_TEST, True)  # additional pullup, default high!

        # last read states:
        self.pwr = None
        self.sw_pressed = None  # last switch state (from recent check): down?
        self.rly = {k: False for k in _RLY}  # current relais states (last set)

        self.oled = OLED(64, 128, i2c)
        self.off()
コード例 #6
0
def all_call_reset(bus):
  bus.write_byte(I2C_ALL_CALL, I2C_SOFT_RESET)

# initialize I2C
BUS_ID = 1
_SMBUS = smbus.SMBus(BUS_ID)

# these pins are not used in the code, just here for reference
SMBUS_SDA_PIN = 03
SMBUS_SCL_PIN = 05

# not used atm
from ads1115 import ADS1115

from mcp23017 import MCP23017
MCP20 = MCP23017(_SMBUS, 0x20)
MCP21 = MCP23017(_SMBUS, 0x21)
MCP22 = MCP23017(_SMBUS, 0x22)
MCP26 = MCP23017(_SMBUS, 0x26)
MCP27 = MCP23017(_SMBUS, 0x27)

INPUTS = [
    MCP20,
    MCP21,
    MCP22,
    MCP26,
    MCP27,
    ]

# initialize microcontroller
from microcontroller import Microcontroller
コード例 #7
0
    bus.write_byte(I2C_ALL_CALL, I2C_SOFT_RESET)


# initialize I2C
BUS_ID = 1
_SMBUS = smbus.SMBus(BUS_ID)

# these pins are not used in the code, just here for reference
SMBUS_SDA_PIN = 03
SMBUS_SCL_PIN = 05

from ads1115 import ADS1115
ANALOG1 = ADS1115(_SMBUS, 0x48)

from mcp23017 import MCP23017
MCP22 = MCP23017(_SMBUS, 0x22)
MCP23 = MCP23017(_SMBUS, 0x23)
MCP24 = MCP23017(_SMBUS, 0x24)
MCP25 = MCP23017(_SMBUS, 0x25)
MCP26 = MCP23017(_SMBUS, 0x26)
MCP27 = MCP23017(_SMBUS, 0x27)

INPUTS = [
    MCP22,
    MCP23,
    MCP24,
    MCP25,
    MCP26,
    MCP27,
    ANALOG1,
]
コード例 #8
0
    def begin(self):
        self.wire = I2C(0, scl=Pin(22), sda=Pin(21))
        self._mcp23017 = MCP23017(self.wire)
        self.TOUCH1 = self._mcp23017.pin(10, Pin.IN)
        self.TOUCH2 = self._mcp23017.pin(11, Pin.IN)
        self.TOUCH3 = self._mcp23017.pin(12, Pin.IN)

        self.spi = SPI(2)

        self.spi.init(baudrate=2000000, firstbit=SPI.MSB, polarity=0, phase=0)

        self.EPAPER_BUSY_PIN = Pin(EPAPER_BUSY_PIN, Pin.IN)
        self.EPAPER_RST_PIN = Pin(EPAPER_RST_PIN, Pin.OUT)
        self.EPAPER_DC_PIN = Pin(EPAPER_DC_PIN, Pin.OUT)
        self.EPAPER_CS_PIN = Pin(EPAPER_CS_PIN, Pin.OUT)

        self.framebuf = bytearray(D_ROWS * D_COLS // 2)

        self.GFX = GFX(
            D_COLS,
            D_ROWS,
            self.writePixel,
            self.writeFastHLine,
            self.writeFastVLine,
            self.writeFillRect,
            None,
            None,
        )

        self.resetPanel()

        _timeout = time.ticks_ms()
        while not self.EPAPER_BUSY_PIN.value() and (time.ticks_ms() -
                                                    _timeout) < 10000:
            pass

        if not self.EPAPER_BUSY_PIN.value():
            return False

        self.sendCommand(PANEL_SET_REGISTER)
        self.sendData(b"\xef\x08")
        self.sendCommand(POWER_SET_REGISTER)
        self.sendData(b"\x37\x00\x23\x23")
        self.sendCommand(POWER_OFF_SEQ_SET_REGISTER)
        self.sendData(b"\x00")
        self.sendCommand(BOOSTER_SOFTSTART_REGISTER)
        self.sendData(b"\xc7\xc7\x1d")
        self.sendCommand(PLL_CONTROL_REGISTER)
        self.sendData(b"\x3c")
        self.sendCommand(TEMP_SENSOR_REGISTER)
        self.sendData(b"\x00")
        self.sendCommand(VCOM_DATA_INTERVAL_REGISTER)
        self.sendData(b"\x37")
        self.sendCommand(b"\x60")
        self.sendData(b"\x20")
        self.sendCommand(RESOLUTION_SET_REGISTER)
        self.sendData(b"\x02\x58\x01\xc0")
        self.sendCommand(b"\xE3")
        self.sendData(b"\xaa")

        time.sleep_ms(100)

        self.sendCommand(b"\x50")
        self.sendData(b"\x37")

        self.setMCPForLowPower()

        self._panelState = True
        return True