Beispiel #1
0
 def __init__(self):
     self.lock = Lock()
     # Setup pins for spi1, spi0
     wiringpi.pinMode(23, 1)
     wiringpi.pinMode(24, 1)
     wiringpi.wiringPiSPISetup(0, 4000000)
     wiringpi.pcf8574Setup(self.EXPANDER_BASE_PIN, 0x41)
import time
from banco import Banco
import wiringpi
import sys
import RPi.GPIO as GPIO
import smbus

bus = smbus.SMBus(
    1
)  # esta linha especifica qual dispositivo I2C a ser usado. 1 significa que o dispositivo I2C está localizado em / dev / I2C-1

out_A = 0b11111111  # Todos reles em 0

wiringpi.wiringPiSetup()  # configura os 3 PCF8574 da placa de expansao

wiringpi.pcf8574Setup(100, 0x25)  # Definindo os pinos do rele como saida
for x in range(0, 9):

    wiringpi.pinMode(100 + x, 1)
    wiringpi.digitalWrite(100 + x, 1)  # Inicia com o rele desligado

wiringpi.pcf8574Setup(200,
                      0x26)  # Definindo os pinos de saida digital como saida
for x in range(0, 9):

    wiringpi.pinMode(200 + x, 1)
    wiringpi.digitalWrite(200 + x, 1)

wiringpi.pcf8574Setup(300, 0x27)
# # Definindo os pinos de entrada digital como entradas
Beispiel #3
0
    def enable_device():
        """enable the specified device """
        try:
            devices = cm.hardware.devices

            for key in devices.keys():
                device = key
                device_slaves = devices[key]

                if device.lower() == "mcp23008":
                    for slave in device_slaves:
                        params = slave
                        wiringpi.mcp23008Setup(int(params['pinBase']),
                                               int(params['i2cAddress'], 16))

                elif device.lower() == "mcp23s08":
                    for slave in device_slaves:
                        params = slave
                        wiringpi.mcp23s08Setup(int(params['pinBase']),
                                               int(params['spiPort'], 16),
                                               int(params['devId']))

                elif device.lower() == "mcp23016":
                    for slave in device_slaves:
                        params = slave
                        wiringpi.mcp23016Setup(int(params['pinBase']),
                                               int(params['i2cAddress'], 16))

                elif device.lower() == "mcp23017":
                    for slave in device_slaves:
                        params = slave
                        wiringpi.mcp23017Setup(int(params['pinBase']),
                                               int(params['i2cAddress'], 16))

                elif device.lower() == "mcp23s17":
                    for slave in device_slaves:
                        params = slave
                        wiringpi.mcp23s17Setup(int(params['pinBase']),
                                               int(params['spiPort'], 16),
                                               int(params['devId']))

                elif device.lower() == "sr595":
                    for slave in device_slaves:
                        params = slave
                        wiringpi.sr595Setup(int(params['pinBase']),
                                            int(params['numPins']),
                                            int(params['dataPin']),
                                            int(params['clockPin']),
                                            int(params['latchPin']))

                elif device.lower() == "pcf8574":
                    for slave in device_slaves:
                        params = slave
                        wiringpi.pcf8574Setup(int(params['pinBase']),
                                              int(params['i2cAddress'], 16))

                else:
                    logging.error(
                        "Device defined is not supported, please check "
                        "your devices settings: " + str(device))
        except Exception as error:
            logging.debug(
                "Error setting up devices, please check your devices "
                "settings.")
            logging.debug(error)
#!coding:utf8
import wiringpi
import time

#init
wiringpi.wiringPiSetup()
wiringpi.pcf8574Setup(101, 0x23)
'''
#enable
wiringpi.pinMode(101,1)
wiringpi.digitalWrite(101,1)
time.sleep(1)
wiringpi.pinMode(103,1)
wiringpi.digitalWrite(103,1)
time.sleep(1)
wiringpi.pinMode(105,1)
wiringpi.digitalWrite(105,1)
time.sleep(1)
wiringpi.pinMode(107,1)
wiringpi.digitalWrite(107,1)

'''
#disable
wiringpi.pinMode(101, 1)
wiringpi.digitalWrite(101, 0)
time.sleep(1)
wiringpi.pinMode(102, 1)
wiringpi.digitalWrite(102, 0)
time.sleep(1)
wiringpi.pinMode(103, 1)
wiringpi.digitalWrite(103, 0)
import sys
import time
import wiringpi
from wiringpi import GPIO

I2C_ADDR = 0x38
BASE = 100

wiringpi.wiringPiSetup()
wiringpi.pcf8574Setup(BASE, I2C_ADDR)

i = 0
while i < 8:
    wiringpi.pinMode(BASE + i, GPIO.OUTPUT)
    i += 1

wiringpi.pinMode(BASE + 0, GPIO.OUTPUT)

while True:
    try:
        wiringpi.digitalWrite(BASE + 0, GPIO.HIGH)
        time.sleep(1)
        wiringpi.digitalWrite(BASE + 0, GPIO.LOW)
        time.sleep(1)
    except KeyboardInterrupt:
        print('\nExit')
        sys.exit(0)