コード例 #1
0
ファイル: main.py プロジェクト: ludiazv/borosVpi
def init_i2c():
    global Oled
    global Ina
    global Io
    global Firmware_found
    global Tim
    #reset_board()
    #boot_loader=I2c.is_ready(0x22)
    devs = I2c.scan()
    if 0x3C in devs:
        print("Oled screen detected")
        Oled = ssd1306.SSD1306_I2C(128, 64, I2c)
        Oled.poweron()
        Oled.fill(0)
        Oled.contrast(255)
        inf("Init!", 1000)
        Oled.show()
    if 0x40 in devs:
        print("INA219 detected")
        Ina = INA219(0.1, I2c, max_expected_amps=2.5)
        Ina.configure(voltage_range=INA219.RANGE_16V)
    if 0x20 in devs:
        print("PCF8574 io expander detected ", end='')
        Io = PCF8574(I2c)
        time.sleep_ms(500)
        print("IO:{:02X}h".format(Io.port))
        set_current(0)
        Tmc = 0
    if 0x22 in devs:
        print("Bootloader found")
    if 0x33 in devs:
        print("Vpi Board found")
        Firmware_found = True

    return (Ina is not None) and (Io is not None)
コード例 #2
0
 def __init__(self, config):
     global PULLUPS
     PULLUPS = {PinPullup.UP: True, PinPullup.DOWN: False}
     i2c_bus_num = config.get("i2c_bus_num", 1)
     chip_addr = config.get("chip_addr", 0x20)
     from pcf8574 import PCF8574
     self.io = PCF8574(i2c_bus_num, chip_addr)
コード例 #3
0
def test_main():
    i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
    lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)
    pcf = PCF8574(i2c, ADDR)
    keymap = [
        '123A',
        '456B',
        '789C',
        '*0#D'
    ]
    charmap = {
        '1': '.1',    '2': 'abc2', '3': 'def3',
        '4': 'ghi4',  '5': 'jkl5', '6': 'mno6',
        '7': 'pqrs7', '8': 'tuv8', '9': 'wxyz9',
                      '0': '_0',
    }
    keypad = Keypad(pcf, keymap, charmap)

    lcd.clear()
    lcd.show_cursor()
    try:
        word = keypad.get_word(lcd)
        print("Got {} as input".format(word))
    except Exit:
        print('Received exit')

    lcd.clear()
    try:
        word = keypad.get_word(lcd, True)
        print("Got {} as input".format(word))
    except Exit:
        print('Received exit')
コード例 #4
0
    def __pcf_init(self):
        if self.settings.is_rpi_env:
            from pcf8574 import PCF8574
        else:
            from PCF_dummy import PCF8574

        self.pcf_read = PCF8574(1, 0x38)
        self.pcf_write = PCF8574(1, 0x3f)
        # since the creating the instances does fail silently let's check
        # Get pin value from relay_no attr in relay instance
        for relay in self.relays:
            pin = 7 - relay.index
            self.__read_pcf(relay)
            try:
                relay.set_status(self.pcf_write.port[pin])
            except IOError:
                self.error = "Error with write PCF"
コード例 #5
0
def init():
    if P.import_module_exist:
        try:
            L.l.info('Initialising PCF8574')
            P.pcf = PCF8574(P.i2c_port_num, P.pcf_address)
            test_ok = P.pcf.port[0]  # try a read
            P.initialised = True
            L.l.info('Initialising PCF8574 OK, state= {}'.format(P.pcf.port))
        except Exception as ex:
            L.l.info('Unable to initialise PCF8574, ex={}'.format(ex))
コード例 #6
0
    def __init__(self, events):
        self.i2c2 = PCF8574(VolumeBoard.i2c2_port, VolumeBoard.i2c2_address)
        self.volknob      = RotaryEncoder2(ControlBoard.KNOBS[ControlBoard.VOL_KNOB], self.volKnobEvent,\
                                (VolumeBoard.MIN_VOLUME, VolumeBoard.MAX_VOLUME, VolumeBoard.DEFAULT_VOL))
        Volume.__init__(self)  # volume data model
        self.events = events
        """ run through the channels and set up the relays"""
        for i in range(len(self.i2c2.port)):
            self.i2c2.port[i] = VolumeBoard.OFF

        print("VolumeBoard._init__ > ready", self.volumestatus())
コード例 #7
0
def scan():
    addresses = []
    for i in range(8):
        add = 56 + i
        check_pcf = PCF8574(1, add)

        try:
            print(check_pcf.port)
            addresses.append(hex(add))
        except (IOError, TypeError):
            pass
    print("Adrresses responding {}".format(addresses))
    if len(addresses) > 2:
        print("PCF responds on all addresses")
        exit()
コード例 #8
0
    def __init__(self, events):
        self.events = events
        self.State = {
            'source': AudioBoard.DEFAULT_SOURCE,
            'phonesdetect': AudioBoard.OFF,
            'mute': AudioBoard.OFF,
            'gain': AudioBoard.OFF
        }
        self.i2c1 = PCF8574(AudioBoard.i2c1_port, AudioBoard.address)
        Source.__init__(self)
        """ run through the channels and set up the relays"""
        for source in AudioBoard.audioBoardMap:
            print("AudioBoard.__init__> channel:",
                  AudioBoard.audioBoardMap[source])
            self.i2c1.port[AudioBoard.audioBoardMap[source][
                AudioBoard.PIN]] = AudioBoard.OFF
        """ setup the headphones insert detect control """
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(AudioBoard.PHONESDETECTPIN, GPIO.IN)
        GPIO.add_event_detect(AudioBoard.PHONESDETECTPIN,
                              GPIO.BOTH,
                              callback=self.phonesdetect)

        print("AudioBoard.__init__ > ready", self.audiostatus())
コード例 #9
0
 def _load_PCF857X(self, i2c_bus, i2c_address):
   return PCF8574(i2c_bus, i2c_address)
コード例 #10
0
ファイル: pcf8574.py プロジェクト: bwduncan/pi-mqtt-gpio
 def __init__(self, config):
     global PULLUPS
     PULLUPS = {PinPullup.UP: True, PinPullup.DOWN: False}
     from pcf8574 import PCF8574
     self.io = PCF8574(config["i2c_bus_num"], config["chip_addr"])
コード例 #11
0
#https://github.com/flyte/pcf8574
pip install smbus-cffi
apt-get install libffi-dev
pip install pcf8574

#https://www.brainy-bits.com/i2c-explained-i2c-keypad/
#https://www.waveshare.com/wiki/Raspberry_Pi_Tutorial_Series:_I2C
#https://custom-build-robots.com/electronic/raspberry-pi-8-bit-io-port-expander-pcf8574/8823?lang=en
from pcf8574 import PCF8574

i2c_port_num = 1

pcf_address = 0x20

pcf = PCF8574(i2c_port_num, pcf_address)

pcf.port
#[True, True, True, True, True, True, True, True]

pcf.port[0] = False
#[False, True, True, True, True, True, True, True]

pcf.port = [True, False, True, False, True, False, True, False]

pcf.port[7]




コード例 #12
0
KEYMAP = ['123A', '456B', '789C', '*0#D']
CHARMAP = {
    '1': '.1',
    '2': 'abc2',
    '3': 'def3',
    '4': 'ghi4',
    '5': 'jkl5',
    '6': 'mno6',
    '7': 'pqrs7',
    '8': 'tuv8',
    '9': 'wxyz9',
    '0': '_0',
}

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=40000000)
pcf = PCF8574(i2c, KEY_ADDR)
keypad = Keypad(pcf, KEYMAP, CHARMAP)
lcd = I2cLcd(i2c, LCD_ADDR, 2, 16)
pcf1 = PCF8574(i2c, 57)
pcf2 = PCF8574(i2c, 58)
opto_mask = 0b11111111

storrage = Storrage()


class SettingsErr(Exception):
    pass


class CancelSignal(Exception):
    pass
コード例 #13
0
ファイル: remoteRoom.py プロジェクト: Gui-B/Pi-sound-controle
#!/usr/bin/python
from pcf8574 import PCF8574
from time import sleep
import soundRelay as rl
import lcd

i2c_port_num = 1
btn_add = 0x38

btn = PCF8574(i2c_port_num, btn_add)
s = rl.soundrelay()

while True:
    if btn.port[0] is False:
        s.set(3)
    elif btn.port[1] is False:
        s.set(2)
    elif btn.port[2] is False:
        s.set(4)
    elif btn.port[3] is False:
        s.set(1)
    elif btn.port[4] is False:
        s.set(5)
    elif btn.port[5] is False:
        lcd16 = lcd.lcd(0x3f)
        #lcd20 = lcd.lcd(0x27)
        lcd16.backlight(0)
        #lcd20.backlight(0)
    sleep(0.1)

コード例 #14
0
from pcf8574 import PCF8574
from time import sleep

i2c_port_num = 1

pcf_read_address = 0x38
pcf_write_address = 0x3f

pcf_read = PCF8574(i2c_port_num, pcf_read_address)
pcf_write = PCF8574(i2c_port_num, pcf_write_address)

while 1:
    print('Read Port')
    print(pcf_read.port)
    print('Write Port')
    print(pcf_write.port)

    for i, pin_read, pin_write in zip(list(range(0, len(pcf_read.port))),
                                      pcf_read.port, pcf_write.port):
        if pin_read != pin_write:
            print('pin {} has read {} and write {}'.format(
                i, pin_read, pin_write))
            pcf_write.port[i] = pin_read
            print('pin updated')

    sleep(2)
コード例 #15
0
keymap = [
    '123A',
    '456B',
    '789C',
    '*0#D'
]
charmap = {
    '1': '.1',    '2': 'abc2', '3': 'def3',
    '4': 'ghi4',  '5': 'jkl5', '6': 'mno6',
    '7': 'pqrs7', '8': 'tuv8', '9': 'wxyz9',
                  '0': '_0',
}

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=40000000)
pcf = PCF8574(i2c, KEY_ADDR)
keypad = Keypad(pcf, keymap, charmap)
lcd = I2cLcd(i2c, LCD_ADDR, 2, 16)
# f = open('programs.csv', 'w')
# f.close()
storrage = Storrage()

def prep(banner):
    lcd.clear()
    lcd.move_to(0, 0)
    lcd.putstr(banner)
    lcd.move_to(0, 1)

def create_program():

    prog = ''
コード例 #16
0
# Author Martin Pek
# 2CP - TeamEscape - Engineering

from time import sleep
# Controls the relay that has been connected over PCF8574 (I2C) to the RPi

from pcf8574 import PCF8574

tester_address = 0x38
# device under test
dut_address = 0x39

# port is 1 for any but very first models of RPi
tester_pcf = PCF8574(1, tester_address)
dut = PCF8574(1, dut_address)


def scan():
    addresses = []
    for i in range(8):
        add = 56 + i
        check_pcf = PCF8574(1, add)

        try:
            print(check_pcf.port)
            addresses.append(hex(add))
        except (IOError, TypeError):
            pass
    print("Adrresses responding {}".format(addresses))
    if len(addresses) > 2:
        print("PCF responds on all addresses")
コード例 #17
0
import time

from machine import I2C, Pin
from pcf8574 import PCF8574

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=40000000)
pcf1 = PCF8574(i2c, 57)
pcf2 = PCF8574(i2c, 58)

# pcf.write8(0b00000000)
res1 = pcf1.read8(0b11111111)
res2 = pcf2.read8(0b11111111)

print('Opto read is {}, {}'.format(bin(res1), bin(res2)))

del pcf1
del pcf2
del i2c
コード例 #18
0
from pcf8574 import PCF8574
from pcf8574pin import PCFPin

from aswitch import Switch

# I2C pins are GPIO4 (SCL) and GPIO5 (SDA)
# PCF8574 use 100 kHz mode
i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5), freq=100000)

# PCF8574 is at address 0x38
# Pins 0 to 3 are input non inverted
# Pins 4 to 7 are output inverted (relay board for example)
pcf = PCF8574(i2c,
              0x38,
              direction='11110000',
              state='11110000',
              inverted='00001111')


# Callback for aswitch
def toggle(relay):
    relay.toggle()


# Quit by connecting GPIO12 to ground
async def killer():
    pin = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
    while pin.value():
        await asyncio.sleep_ms(50)
コード例 #19
0
 def __init__(self):
     self.pcf = PCF8574(self.i2c_port_num, self.pcf_address)
コード例 #20
0
def create_pcf(port, address):
    try:
        from pcf8574 import PCF8574
        return PCF8574(port, address)
    except ImportError:
        print('Couldn\'t find module pcf8574')
コード例 #21
0
import time
from keypad import Keypad

from machine import I2C, Pin
from pcf8574 import PCF8574

ADDR = 56
keymap = [
    '123A',
    '456B',
    '789C',
    '*0#D'
]
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=40000000)
pcf = PCF8574(i2c, ADDR)
keypad = Keypad(pcf, keymap)

# print('rows cols = [{}, {}]'.format(keypad.rows, keypad.cols))
start = time.ticks_ms()
while time.ticks_diff(time.ticks_ms(), start) < 5000:
    key = keypad.getkey()
    if key is not None:
        print('Key pressed {}'.format(key))

del pcf
del i2c
del keypad
コード例 #22
0
 def _get_hardware(self, i2c_bus, i2c_address):
     return PCF8574(i2c_bus, i2c_address)