Ejemplo n.º 1
0
def initMCP(app):
    mcp.wiringPiSetup()
    #get mcp object if it exisits
    base = cbpi.get_config_parameter("MCP_wiring_Pi_Base", None)
    if base is None:
        base = "500"
        #cbpi.add_config_parameter("MCP_Wiring_Pi_Base", "500", "text", "MCP Base - change is wiring pi libary conflicts occur")
    #app.cache["mcp_base"] = base
    
    mcp.mcp23017Setup(base, "0x20")
Ejemplo n.º 2
0
    def __init__(self, app):
        super().__init__(daemon=True)
        self.app = app

        if wiringpi:
            pin_base = 100
            i2c_addr = 0x20
            wiringpi.wiringPiSetup()
            wiringpi.mcp23017Setup(pin_base, i2c_addr)

        self.shift_button = Button(110, key=pygame.K_LSHIFT)
        self.play_button = Button(21, key=pygame.K_SPACE)
        self.stop_button = Button(20, key=pygame.K_ESCAPE)
        self.record_button = Button(16, key=pygame.K_r)
        self.clear_button = Button(19, key=pygame.K_c)
        self.scope_button = Button(111, key=pygame.K_BACKSPACE)
        self.number_buttons = [
            Button(pin, key=pygame.K_1 + index)
            for index, pin in enumerate([17, 27, 27, 27])
        ]
        self.rotary_param = Rotary(13,
                                   26,
                                   key_left=pygame.K_DOWN,
                                   key_right=pygame.K_UP)
        self.rotary_value1 = Rotary(108,
                                    109,
                                    key_left=pygame.K_q,
                                    key_right=pygame.K_w)
        self.ok_button1 = Button(2, key=pygame.K_e)
        self.rotary_value2 = Rotary(112,
                                    114,
                                    key_left=pygame.K_a,
                                    key_right=pygame.K_s)
        self.ok_button2 = Button(2, key=pygame.K_d)

        self.items = [
            self.shift_button,
            self.play_button,
            self.stop_button,
            self.clear_button,
            self.record_button,
            self.scope_button,
            self.rotary_param,
            self.rotary_value1,
            self.ok_button1,
            self.rotary_value2,
            self.ok_button2,
        ] + self.number_buttons
Ejemplo n.º 3
0
    def __init__(self):
        wiringpi.mcp23017Setup(101, 0x20)  # set up the pins and i2c address
        wiringpi.mcp23017Setup(
            117,
            0x24)  # set up second MCP23017 - not used in single config test
        wiringpi.mcp23017Setup(
            133,
            0x22)  # set up second MCP23017 - not used in single config test
        wiringpi.mcp23017Setup(
            149,
            0x26)  # set up second MCP23017 - not used in single config test
        wiringpi.mcp23017Setup(165, 0x21)

        for x in range(101, 173):
            wiringpi.pinMode(x, 1)
            wiringpi.digitalWrite(x, 1)
Ejemplo n.º 4
0
def init_io():
    humidity, temperature = Adafruit_DHT.read_retry(22, PIN_DHT)
    LOG.info("Humidity %s", humidity)

    # setup buttons
    GPIO.setmode(GPIO.BOARD)
    for pin in BUTTONS:
        GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(pin, GPIO.RISING, callback=interupt_button_pressed, bouncetime=BOUNCETIME)

    # mcp23017 for outputs
    pin_base = 65       # lowest available starting number is 65
    i2c_addr = 0x20     # A0, A1, A2 pins all wired to GN
    wiringpi.wiringPiSetup()                    # initialise wiringp
    wiringpi.mcp23017Setup(pin_base,i2c_addr)   # set up the pins and i2c address

    for key, definition in OUTPUTS.items():
        Output.setup(name=key)
        Output.off(name=key)
Ejemplo n.º 5
0
	def setup(self):
		try:
			wiringpi.wiringPiSetup()
			wiringpi.mcp23017Setup(65, 0x20)
			wiringpi.mcp23017Setup(65 + 16, 0x21)
			wiringpi.mcp23017Setup(65 + 32, 0x22)
		except:
			pass
Ejemplo n.º 6
0
	def create( self ):
		# Addresses: 0x20, 0x21, 0x22
		# Setup WIRING PI in Pin Mode
		wiringpi.wiringPiSetup()

		# Setup the chips
		wiringpi.mcp23017Setup( 65, 0x20 )
		wiringpi.mcp23017Setup( 81, 0x21 )
		wiringpi.mcp23017Setup( 97, 0x22 )

		# Setup pins on the I2C Controller chip
		for x in range( 65, 114 ):
			wiringpi.pinMode( x, 1 ) # Set pin to output
			wiringpi.digitalWrite( x, 1 ) # Set pin to off
Ejemplo n.º 7
0
    def __init__(self):
        # Initialize wiringpi
        wiringpi.wiringPiSetup()
        mcpOnePin = 100
        mcpTwoPin = 200
        mcpThreePin = 300
        mcpFourPin = 400
        wiringpi.mcp23017Setup(mcpOnePin, 0x20)
        wiringpi.mcp23017Setup(mcpTwoPin, 0x21)
        wiringpi.mcp23017Setup(mcpThreePin, 0x22)
        wiringpi.mcp23017Setup(mcpFourPin, 0x23)

        # Hold a list of Sensors objects
        self.sensorElements = []
        for sensorElement in settings.sensorList:
            self.sensorElements.append(
                SensorElement(sensorElement[0], sensorElement[1]))

        # Hold a list of RelayElements objects
        self.relayElements = []
        for relayElement in settings.relayList:
            self.relayElements.append(
                RelayElement(relayElement[0], relayElement[1]))
Ejemplo n.º 8
0
import wiringpi as wiringpi
from time import sleep

pin_base = 65  # lowest available starting number is 65
i2c_addr = 0x20  # A0, A1, A2 pins all wired to GND

wiringpi.wiringPiSetup()  # initialise wiringpi
wiringpi.mcp23017Setup(pin_base, i2c_addr)  # set up the pins and i2c address

wiringpi.pinMode(65, 1)  # sets GPA0 to output
wiringpi.digitalWrite(65, 0)  # sets GPA0 to 0 (0V, off)

wiringpi.pinMode(80, 0)  # sets GPB7 to input
wiringpi.pullUpDnControl(80, 2)  # set internal pull-up

# Note: MCP23017 has no internal pull-down, so I used pull-up and inverted
# the button reading logic with a "not"

try:
    while True:
        wiringpi.digitalWrite(65, 1)  # sets port GPA1 to 1 (3V3, on)
        sleep(1)
        wiringpi.digitalWrite(65, 0)  # sets port GPA1 to 0 (0V, off)
        sleep(1)
finally:
    wiringpi.digitalWrite(65, 0)  # sets port GPA1 to 0 (0V, off)
    wiringpi.pinMode(65, 0)  # sets GPIO GPA1 back to input Mode
    # GPB7 is already an input, so no need to change anything
Ejemplo n.º 9
0
FIV=77
SIX=78
SEV=79
EIG=80
WHI=81
BLA=82

# Define some constants so we can read our own code...
ON = 1
OFF = 0
OUT = 1
IN = 0

# Initialise the I2Cs
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pin_base_i2c1,i2c1_LEDS_addr)
wiringpi.mcp23017Setup(pin_base_i2c2,i2c2_LEDS_addr)

# Set default PIN MODES
wiringpi.pinMode(A,OUT)
wiringpi.pinMode(B,OUT)
wiringpi.pinMode(C,OUT)
wiringpi.pinMode(D,OUT)
wiringpi.pinMode(E,OUT)
wiringpi.pinMode(F,OUT)
wiringpi.pinMode(G,OUT)
wiringpi.pinMode(H,OUT)
wiringpi.pinMode(ONE,OUT)
wiringpi.pinMode(TWO,OUT)
wiringpi.pinMode(THR,OUT)
wiringpi.pinMode(FOU,OUT)
Ejemplo n.º 10
0
LATCH_S1 = 66
CLOCK_S1 = 67

MSBFIRST = 1

LOSE = 92
WIN = 93
ON = 94
OFF = 95
PAUSE = 96
PENALTY = 97

# WIRINGPI SETUP
wiringpi.wiringPiSetup()

wiringpi.mcp23017Setup(65, 0x20)
wiringpi.mcp23017Setup(82, 0x21)

# SET PINS AS OUTPUTS
wiringpi.pinMode(DATA_S1,1)
wiringpi.pinMode(LATCH_S1,1)
wiringpi.pinMode(CLOCK_S1,1)

wiringpi.pinMode(DATA_S2,1)
wiringpi.pinMode(LATCH_S2,1)
wiringpi.pinMode(CLOCK_S2,1)

wiringpi.pinMode(DATA_M1,1)
wiringpi.pinMode(LATCH_M1,1)
wiringpi.pinMode(CLOCK_M1,1)
Ejemplo n.º 11
0
        a_state = wiringpi.digitalRead(self.a_pin)
        b_state = wiringpi.digitalRead(self.b_pin)

        rotation = 0
        if self.a_last_value == 1 and a_state == 0:
            if b_state == 0:
                rotation = -1
            else:
                rotation = 1

        self.a_last_value = a_state
        return rotation

    def get_switch(self):
        return not wiringpi.digitalRead(self.sw_pin)


mcp23017_addr2 = 0x27

base = 65 + 16
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(base, mcp23017_addr2)

switches = [base + 6, base + 9, base + 12]
rotary1 = RotaryEncoder(base + 7, base + 6, base + 5)
while (True):
    rotation = rotary1.get_rotation()
    if (rotation != 0):
        print(rotation)
    sleep(0.01)
Ejemplo n.º 12
0
# Turns on each pin of an mcp23017 on address 0x20 ( quick2wire IO expander )
import wiringpi

pin_base = 65
i2c_addr = 0x20
i2c_addr_2 = 0x21
#pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]

wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pin_base,i2c_addr)
wiringpi.mcp23017Setup(pin_base+16,i2c_addr_2)

#for pin in pins:
for pin in range(65,96):
	wiringpi.pinMode(pin,1)
	wiringpi.digitalWrite(pin,1)
#	wiringpi.delay(1000)
#	wiringpi.digitalWrite(pin,0)
Ejemplo n.º 13
0
Manages all of our power zones.
"""

VERSION = "V1.0.0 (2020-07-31)"

import sys
sys.path.append('/var/www/gardenpi_control/gardenpi')
from sqlalchemy import update, select, and_, create_engine
import system_info
from tables import power, power_scheduled_jobs, power_currently_running
from system_logging import setup_logging
from system_logging import read_logging_config
import logging
import wiringpi as mcp
mcp.wiringPiSetup()  # initialise wiringpi
mcp.mcp23017Setup(96, 0x25)  #MCP2 GPIOs 96-111

# Instantiate SQAlchemy Database Engine
engine = create_engine(system_info.sqlalchemy_db_uri, pool_recycle=3600)

#Setup Module level logging here. Main logging config in system_logging.py
setup_logging()
level = read_logging_config('logging', 'log_level')
level = logging._checkLevel(level)
log = logging.getLogger(__name__)
log.setLevel(level)


class PowerZoneSchedule:
    def __init__(self, name, job_id, zone_job, job_enabled, job_start_time,
                 job_stop_time, job_duration, job_running, monday, tuesday,
Ejemplo n.º 14
0
    console_handler = logging.StreamHandler()
    console_handler.setFormatter(log_formatter)
    console_handler.setLevel(logging.INFO)
    root_logger.addHandler(console_handler)

    file_handler = RotatingFileHandler(os.path.join(cwd, "logs", "main.log"), 'a', 1024 ** 2, 10)
    file_handler.setFormatter(log_formatter)
    file_handler.setLevel(logging.DEBUG)
    root_logger.addHandler(file_handler)

if __name__ == "__main__":
    """
    Enable velocity logging. No velocity control.
    """

    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    i2c.wiringPiSetup() # initialise wiringpi  
    i2c.mcp23017Setup(config.I2C_PINBASE, config.I2C_ADDRESS)   # set up the pins and i2c address
    init_logger()
    
    wheel_l = Wheel('L', linear_actuator=None, debug=True)
    wheel_r = Wheel('R', linear_actuator=None, debug=True)
    wheel_l.initiate()
    wheel_r.initiate()
    
    logging.info("Logging velocity data to log files for left and right wheels.")
    input("Press enter to quit.")
    
    
Ejemplo n.º 15
0
Manages all of our irrigation/hydroponics water zones.
"""

VERSION = "V1.0.0 (2020-07-31)"

import sys
sys.path.append('/var/www/gardenpi_control/gardenpi')
import system_info
from sqlalchemy import update, select, and_, create_engine
from tables import zones, scheduled_jobs, zones_currently_running, water_source, hydroponic_zones
from system_logging import setup_logging
from system_logging import read_logging_config
import logging
import wiringpi as mcp
mcp.wiringPiSetup()  # Initialise wiringpi
mcp.mcp23017Setup(64, 0x26)  # MCP0 GPIO 64-79
mcp.mcp23017Setup(80, 0x27)  # MCP1 GPIO 80-95

# Instantiate SQAlchemy Database Engine
engine = create_engine(system_info.sqlalchemy_db_uri, pool_recycle=3600)

#Setup Module level logging here. Main logging config in system_logging.py
setup_logging()
level = read_logging_config('logging', 'log_level')
level = logging._checkLevel(level)
log = logging.getLogger(__name__)
log.setLevel(level)


class ZoneSchedule:
    def __init__(self, name, job_id, zone_job, job_enabled, job_start_time,