Example #1
0
def run():

    ErrorMessage = "ERROR : arguments is not true! "
    gpio.init()
    try:
        #print ("Press CTRL+C to exit")
        if len(sys.argv) != 3:
            print(ErrorMessage)
            return ErrorMessage
        else:
            pin = pinName(sys.argv[1])
            if int(sys.argv[2]) == 2:
                gpio.setcfg(pin, GPIO.INPUT)
                status = gpio.input(pin)
                print("status => ", status)
                return status
            elif int(sys.argv[2]) == 1 or int(sys.argv[2]) == 0:
                gpio.setcfg(pin, gpio.OUTPUT)
                gpio.output(pin, int(sys.argv[2]))
                print("output => OK")
                return "OK"
            else:
                return ErrorMessage

    except KeyboardInterrupt:
        #print ("Goodbye.")
        return ErrorMessage
Example #2
0
def setup():
    #GPIO.setwarnings(False)
    #GPIO.cleanup()
    #GPIO.setmode(GPIO.BCM)
    GPIO.init()
    #GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setcfg(button, GPIO.INPUT)
    GPIO.pullup(button, GPIO.PULLUP)
    #GPIO.setup(lights, GPIO.OUT)
    GPIO.setcfg(lights[0], GPIO.OUTPUT)
    GPIO.setcfg(lights[1], GPIO.OUTPUT)
    #GPIO.output(lights, GPIO.LOW)
    GPIO.output(lights[0], GPIO.LOW)
    GPIO.output(lights[1], GPIO.LOW)
    while internet_on() == False:
        print(".")
    token = gettoken()
    if token == False:
        while True:
            for x in range(0, 5):
                time.sleep(.1)
                GPIO.output(rec_light, GPIO.HIGH)
                time.sleep(.1)
                GPIO.output(rec_light, GPIO.LOW)
    for x in range(0, 5):
        time.sleep(.1)
        GPIO.output(plb_light, GPIO.HIGH)
        time.sleep(.1)
        GPIO.output(plb_light, GPIO.LOW)
    play_audio(path + "hello.mp3")
Example #3
0
def main():
    try:
        # Main program block
        gpio.init()
        gpio.setcfg(LCD_E, gpio.OUTPUT)  # E
        gpio.setcfg(LCD_RS, gpio.OUTPUT)  # RS
        gpio.setcfg(LCD_D4, gpio.OUTPUT)  # D84
        gpio.setcfg(LCD_D5, gpio.OUTPUT)  # D85
        gpio.setcfg(LCD_D6, gpio.OUTPUT)  # D86
        gpio.setcfg(LCD_D7, gpio.OUTPUT)  # D87

        # Initialize display
        lcd_init()

        while True:
            # send text
            lcd_string("Hackerboxes.com", LCD_LINE_1)
            lcd_string("hack the planet", LCD_LINE_2)

            sleep(2)

            # send text
            lcd_string("Hackerboxes.com", LCD_LINE_1)
            lcd_string("HACK THE PLANET", LCD_LINE_2)

            sleep(2)
    except KeyboardInterrupt:
        lcd_string("Goodbye!", LCD_LINE_1)
        print "Goodbye!"
Example #4
0
def shutdowner():
  rospy.init_node('shutdown_node')
  rate = rospy.Rate(10) # 10hz

  if not os.getegid() == 0:
    sys.exit('Script must be run as root')

  delay=5

  portToListen = port.PE5
  portToWrite = port.PE4

  gpio.init()
  gpio.setcfg(portToListen, gpio.INPUT)
  gpio.setcfg(portToWrite, gpio.OUTPUT)

  while not rospy.is_shutdown():
    try:
      print ("Press CTRL+C to exit")
      while True:
        v=gpio.input(portToListen)
        if(v==1):
            sleep(2)
            v=gpio.input(portToListen)
            if(v==1):
              print("shutdown of the Olimex")
              gpio.output(portToWrite, 1)
              os.system("sudo halt -p")
              break
        sleep(delay)
    except KeyboardInterrupt:
      print ("Goodbye.")
Example #5
0
File: pin.py Project: aaaler/k9
 def __init__ (self, pin_id, direction = 1, value = 0):
     self._pinid = pin_id
     self._direction = direction
     self._value = value
     gpio.init()
     gpio.setcfg (pin_id, direction)
     gpio.output (pin_id, value)
Example #6
0
def RUN_INIT():
    print "--> RUN_INIT : "
    gpio.init()
    gpio.setcfg(port.PA6, gpio.OUTPUT)
    gpio.pullup(port.PA6, gpio.PULLDOWN)
    gpio.output(port.PA6, gpio.HIGH)
    time.sleep(0.1)
Example #7
0
    def init_gpio_monitoring(self):
        # Init gpio module
        gpio.init()
        self.log("[  MO-INFO  ] GPIO initialized.")

        # Set directions
        gpio_inputs = self.config.get("gpio_inputs", {})
        gpio_outputs = self.config.get("gpio_outputs", {})

        for func_name, pin_name in gpio_inputs.items():
            if pin_name.startswith("gpio"):
                self.gpio[func_name] = _gpio_input = getattr(
                    connector, pin_name)
            else:
                self.gpio[func_name] = _gpio_input = getattr(port, pin_name)
            gpio.setcfg(_gpio_input, gpio.INPUT)

        for func_name, pin_name in gpio_outputs.items():
            if pin_name.startswith("gpio"):
                self.gpio[func_name] = _gpio_output = getattr(
                    connector, pin_name)
            else:
                self.gpio[func_name] = _gpio_output = getattr(port, pin_name)
            gpio.setcfg(_gpio_output, gpio.OUTPUT)
        self.log("[  MO-INFO  ] GPIO configured:"
                 "\n\tgpio_inputs:"
                 "\n\t\t%s"
                 "\n\tgpio_outputs:"
                 "\n\t\t%s" % ("emitting", "emitting"))
 def __init__(self, input_dict):
     gpio.init()
     for key in input_dict:
         tup = input_dict[key]
         gpio.setcfg(key, gpio.INPUT)
         gpio.pullup(key, gpio.PULLUP)
         self.__hk_add_to_dict(key, tup)
Example #9
0
def blink2():
    gpio.init()
    blink = port.PA10
    gpio.setcfg(blink, gpio.OUTPUT)
    gpio.output(blink, gpio.HIGH)
    sleep(1)
    gpio.output(blink, gpio.LOW)
Example #10
0
def main(argv):

    initial_button_state = 0

    gpio.init()
    gpio.setcfg(POWER_BUTTON, gpio.INPUT)
    gpio.pullup(POWER_BUTTON, gpio.PULLUP)
    gpio.setcfg(LED, gpio.OUTPUT)

    while True:
        # Returns a 1 if open and a 0 if pressed/closed
        current_button_state = gpio.input(POWER_BUTTON)

        #print(initial_button_state, current_button_state)
        #sys.stdout.flush()

        # Check if button state has changed
        if current_button_state != initial_button_state:
            #print('Button pressed')
            gpio.output(LED, 1)
            subprocess.call(CMD,
                            shell=True,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)

        time.sleep(0.1)
Example #11
0
 def __init__(self):
     self._loop = False
     self.detected = False
     self._line1 = port.PA2
     gpio.init()
     gpio.setcfg(self._line1, gpio.INPUT)
     gpio.pullup(self._line1, gpio.PULLUP)
Example #12
0
    def __init__(self, cs_pin, clock_pin, data_pin, units="c"):
        '''Initialize Soft (Bitbang) SPI bus

        Parameters:
        - cs_pin:    Chip Select (CS) / Slave Select (SS) pin (Any GPIO)  
        - clock_pin: Clock (SCLK / SCK) pin (Any GPIO)
        - data_pin:  Data input (SO / MOSI) pin (Any GPIO)
        - units:     (optional) unit of measurement to return. ("c" (default) | "k" | "f")

        '''
        self.cs_pin = port.PA9  #cs_pin
        self.clock_pin = port.PA8  #clock_pin
        self.data_pin = port.PA21  #data_pin
        self.units = units
        self.data = None

        # Initialize needed GPIO
        #GPIO.setmode(self.board)
        gpio.init()
        #GPIO.setup(self.cs_pin, GPIO.OUT)
        gpio.setcfg(self.cs_pin, gpio.OUTPUT)

        #GPIO.setup(self.clock_pin, GPIO.OUT)
        gpio.setcfg(self.clock_pin, gpio.OUTPUT)

        #GPIO.setup(self.data_pin, GPIO.IN)
        gpio.setcfg(self.data_pin, gpio.INPUT)

        # Pull chip select high to make chip inactive
        gpio.output(self.cs_pin, gpio.HIGH)
    def __init__(self, broker_address="localhost", broker_port=1883):
        self.client = mqtt.Client()  #create new instance
        #logging.basicConfig(level=logging.DEBUG)
        logger = logging.getLogger(__name__)
        self.client.enable_logger(logger)
        #self.client.connect(broker_address,broker_port,60) #connect to broker
        #print("Connected to " + broker_address + ":"+ str(broker_port))
        #time.sleep(1)
        #self.client.subscribe("shutters/commandreply")
        #print("Subscribed to shutters/commandreply")
        #self.client.on_message=self.on_message

        # Set up sequences of motor speeds.
        self.forward_speeds = list(range(0, MAX_SPEED, 2))
        self.reverse_speeds = list(range(0, -MAX_SPEED, -2))

        # pinShutter2closedSensor = connector.gpio3p37
        self.pinShutter2openSensor = port.PA10
        self.pinShutter2closedSensor = port.PA20
        self.pinShutter1openSensor = port.PG7
        self.pinShutter1closedSensor = port.PG6
        """Init gpio module"""
        gpio.init()
        """Set directions"""
        gpio.setcfg(self.pinShutter2openSensor, gpio.INPUT)
        gpio.setcfg(self.pinShutter2closedSensor, gpio.INPUT)
        gpio.setcfg(self.pinShutter1openSensor, gpio.INPUT)
        gpio.setcfg(self.pinShutter1closedSensor, gpio.INPUT)
        """Enable pullup resistor"""
        gpio.pullup(self.pinShutter2openSensor, gpio.PULLUP)
        gpio.pullup(self.pinShutter2closedSensor, gpio.PULLUP)
        gpio.pullup(self.pinShutter1openSensor, gpio.PULLUP)
        gpio.pullup(self.pinShutter1closedSensor, gpio.PULLUP)
Example #14
0
 def __init__(self):
     self._led = port.PA10
     self._ledstate = 0
     self._loop = False
     gpio.init()
     gpio.setcfg(self._led, gpio.OUTPUT)
     gpio.output(self._led, 0)
Example #15
0
def Buttons(triggers):
    buttons = triggers.sections()
    GPIO.init()
    pins = []
    gpioType = []
    i = 0
    for button in buttons:
        gpioType.append(button[0])
        pins.append(h3pin[int(button[1:])])
        if gpioType[i] == "B":
            GPIO.setcfg(pins[i], GPIO.INPUT)
            GPIO.pullup(pins[i], GPIO.PULLUP)
        if gpioType[i] == "M":
            GPIO.setcfg(pins[i], GPIO.INPUT)
        i = i + 1

    global buttonPressed
    while True:
        i = 0
        for pin in pins:
            if gpioType[i] == "B":
                if not GPIO.input(pin):
                    buttonPressed = "B" + str(pipin[pin])
            if gpioType[i] == "M":
                if GPIO.input(pin):
                    buttonPressed = "M" + str(pipin[pin])
            i = i + 1
        time.sleep(0.020)
Example #16
0
 def __init__(self):
     gpio.init()
     for column in self.columns:
         gpio.setcfg(column, gpio.OUTPUT)
     for row in self.rows:
         gpio.setcfg(row, gpio.INPUT)
         gpio.pullup(row, gpio.PULLDOWN)
Example #17
0
    def __init__(self, ip='127.0.0.1', port_=5000, bsize=1024):
        self.state = self.Init
        self.TCP_IP = ip  #ip
        self.TCP_PORT = port_  #port
        self.BUFFER_SIZE = bsize  #Buffer size

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.connect((self.TCP_IP, self.TCP_PORT))

        self.closed = False

        self.IN1 = port.PA7
        self.IN2 = port.PA1
        self.IN3 = port.PA0
        self.IN4 = port.PA3
        self.PWMPIN1 = port.PA6
        self.PWMPIN2 = port.PA11

        gpio.init()

        gpio.setcfg(self.IN1, gpio.OUTPUT)
        gpio.setcfg(self.IN2, gpio.OUTPUT)
        gpio.setcfg(self.IN3, gpio.OUTPUT)
        gpio.setcfg(self.IN4, gpio.OUTPUT)
        gpio.setcfg(self.PWMPIN1, gpio.OUTPUT)
        gpio.setcfg(self.PWMPIN2, gpio.OUTPUT)

        self.pwm1 = OrangePwm(10, self.PWMPIN1)
        self.pwm2 = OrangePwm(10, self.PWMPIN2)
        self.pwm1.start(100)
        self.pwm2.start(100)
def shutdowner():

    if not os.getegid() == 0:
        sys.exit('Script must be run as root')

    delay = 5

    portToListen = port.PI2  #13
    portToWrite = port.PI1  #11

    gpio.init()
    gpio.setcfg(portToListen, gpio.INPUT)
    gpio.setcfg(portToWrite, gpio.OUTPUT)
    gpio.output(portToWrite,
                1)  #this tells EPS that shutdown script is running fine

    while 1:
        v = gpio.input(portToListen)
        print v
        if (v == 1):
            sleep(delay)
            v = gpio.input(portToListen)
            if (v == 1):
                print("shutdown of the Olimex")
                gpio.output(portToWrite, 1)
                os.system("sudo halt -p")
                break
        sleep(delay)
Example #19
0
def Buttons(triggers):
    buttons = triggers.sections()
    GPIO.init()
    pins = []
    gpioType = []
    i = 0
    for button in buttons:
        gpioType.append(button[0])
        pins.append(h3pin[int(button[1:])])
        if gpioType[i] == "B":
            GPIO.setcfg(pins[i], GPIO.INPUT)
            GPIO.pullup(pins[i], GPIO.PULLUP)
        if gpioType[i] == "M":
            GPIO.setcfg(pins[i], GPIO.INPUT)
        i = i + 1

    global buttonPressed
    while True:
        i = 0
        for pin in pins:
            if gpioType[i] == "B":
                if not GPIO.input(pin):
                    buttonPressed = "B" + str(pipin[pin])
            if gpioType[i] == "M":
                if GPIO.input(pin):
                    buttonPressed = "M" + str(pipin[pin])
            i = i + 1
        time.sleep(0.020)
Example #20
0
def shutdowner():
    rospy.init_node('shutdown_node')
    rate = rospy.Rate(10)  # 10hz

    if not os.getegid() == 0:
        sys.exit('Script must be run as root')

    delay = 5

    portToListen = port.PE5
    portToWrite = port.PE4

    gpio.init()
    gpio.setcfg(portToListen, gpio.INPUT)
    gpio.setcfg(portToWrite, gpio.OUTPUT)

    while not rospy.is_shutdown():
        try:
            print("Press CTRL+C to exit")
            while True:
                v = gpio.input(portToListen)
                if (v == 1):
                    sleep(2)
                    v = gpio.input(portToListen)
                    if (v == 1):
                        print("shutdown of the Olimex")
                        gpio.output(portToWrite, 1)
                        os.system("sudo halt -p")
                        break
                sleep(delay)
        except KeyboardInterrupt:
            print("Goodbye.")
Example #21
0
def init():
    gpio.init()

    gpio.setcfg(Configuration.Green, gpio.OUTPUT)
    gpio.setcfg(Configuration.Red, gpio.OUTPUT)

    gpio.setcfg(Configuration.Button1, gpio.INPUT)
    gpio.pullup(Configuration.Button1, 0)
    gpio.pullup(Configuration.Button1, gpio.PULLDOWN)
    gpio.pullup(Configuration.Button1, gpio.PULLUP)
    gpio.setcfg(Configuration.Coffee1, gpio.OUTPUT)

    gpio.setcfg(Configuration.Button2, gpio.INPUT)
    gpio.pullup(Configuration.Button2, 0)
    gpio.pullup(Configuration.Button2, gpio.PULLDOWN)
    gpio.pullup(Configuration.Button2, gpio.PULLUP)
    gpio.setcfg(Configuration.Coffee2, gpio.OUTPUT)

    gpio.setcfg(Configuration.Button3, gpio.INPUT)
    gpio.pullup(Configuration.Button3, 0)
    gpio.pullup(Configuration.Button3, gpio.PULLDOWN)
    gpio.pullup(Configuration.Button3, gpio.PULLUP)
    gpio.setcfg(Configuration.Coffee3, gpio.OUTPUT)

    gpio.setcfg(Configuration.Button4, gpio.INPUT)
    gpio.pullup(Configuration.Button4, 0)
    gpio.pullup(Configuration.Button4, gpio.PULLDOWN)
    gpio.pullup(Configuration.Button4, gpio.PULLUP)
    gpio.setcfg(Configuration.Coffee4, gpio.OUTPUT)

    gpio.setcfg(Configuration.Button5, gpio.INPUT)
    gpio.pullup(Configuration.Button5, 0)
    gpio.pullup(Configuration.Button5, gpio.PULLDOWN)
    gpio.pullup(Configuration.Button5, gpio.PULLUP)
Example #22
0
 def initialize_gpio(self):
     gpio.init()
     gpio.setcfg(self.LCD_RS, gpio.OUTPUT)
     gpio.setcfg(self.LCD_E, gpio.OUTPUT)
     gpio.setcfg(self.LCD_D4, gpio.OUTPUT)
     gpio.setcfg(self.LCD_D5, gpio.OUTPUT)
     gpio.setcfg(self.LCD_D6, gpio.OUTPUT)
     gpio.setcfg(self.LCD_D7, gpio.OUTPUT)
Example #23
0
 def __init__(self):
     super(BadgeScanneur, self).__init__()
     self.redis = StrictRedis(host='localhost', port=6379, db=0)
     gpio.init()  # Initialize module. Always called first
     self.continue_reading = True
     signal.signal(signal.SIGINT, self.end_read)
     self.MIFAREReader = MFRC522.MFRC522()
     self.redis.publish(APP_STREAM, "<success>Badgeuse initialisé, prête à scanner.")
Example #24
0
 def __init__(self):
     self.expander = None
     self.expin = 999
     if EMU:
         self.state = {}
         print("gpio emulator enabled")
     else:
         G.init()
    def __init__(self, red, green, blue):
        self.rPin = red
        self.gPin = green
        self.bPin = blue

        gpio.init()
        gpio.setcfg(self.rPin, gpio.OUTPUT)
        gpio.setcfg(self.gPin, gpio.OUTPUT)
        gpio.setcfg(self.bPin, gpio.OUTPUT)
Example #26
0
    def __init__(self):

        self.TRIG = port.PA21 # change this if necessary
        self.ECHO = port.PC3 # change this if necessary
        
        gpio.init()

        gpio.setcfg(self.TRIG, gpio.OUTPUT)
        gpio.setcfg(self.ECHO, gpio.INPUT)
Example #27
0
 async def set(self, *values):
     if not self._initialized:
         gpio.init()
         for led in leds:
             gpio.setcfg(led, gpio.OUTPUT)
         self._initialized = True
     assert (len(values) == len(leds))
     for i in range(len(leds)):
         gpio.output(leds[i], 0 if values[i] else 1)
Example #28
0
    def __init__(self, port, timeout):
        self.port = port
        self.timeout = timeout
        self.timers = {'last': 0}
        self.events = {}

        gpio.init()
        gpio.setcfg(port, gpio.INPUT)  #Configure PE11 as input
        gpio.setcfg(port, 0)  #Same as above
Example #29
0
def blink3():
    gpio.init()
    blink = port.PA7
    gpio.setcfg(blink, gpio.OUTPUT)

    gpio.output(blink, gpio.HIGH)

    sleep(0.03)
    gpio.output(blink, gpio.LOW)
    sleep(0.03)
Example #30
0
def pindown(pin_code):

    if RELETYPE == 1:
        gpiolevel = gpio.HIGH
    else:
        gpiolevel = gpio.LOW

    gpio.init()
    gpio.setcfg(pin_code, gpio.OUTPUT)
    gpio.output(pin_code, gpiolevel)
Example #31
0
def pinstate(pin_code):
    gpio.init()
    state = gpio.input(pin_code)  # Read button state

    if RELETYPE == 1:
        if state == 1:
            state = 0
        else:
            state = 1

    return (state)
Example #32
0
	def __init__(self, savque, ports):#quelock, ports):
		threading.Thread.__init__(self)
		self.savque = savque
		#self.quelock = quelock
		self.ports = ports
		gpio.init()
		for p in self.ports:
			gpio.setcfg(p, gpio.INPUT)
			gpio.pullup(p, gpio.PULLDOWN)
		self.led = connector.LEDp2
		gpio.setcfg(self.led, gpio.OUTPUT)
Example #33
0
def temperature():
    PIN = port.PA6
    gpio.init()
    instance = dht11.DHT11(pin=PIN)

    while True:
        result = instance.read()
        if result.is_valid():
            return ("date: {}  Temperature: {}C and Humidity: {}%".format(
                datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
                result.temperature, result.humidity))
def initiatePin(): #Initialiser les GPIO
	gpio.init()
	pin = port.PG6

	gpio.setcfg(pin, gpio.OUTPUT)
	gpio.input(pin)

	gpio.setcfg(pin, 0)
	gpio.pullup(pin, 0)
	gpio.pullup(pin, gpio.PULLDOWN)
	gpio.pullup(pin, gpio.PULLUP)
Example #35
0
    def begin(self, major, minor, ce_pin):
        # Initialize SPI bus
        self.spidev = spidev.SpiDev()
        self.spidev.open(major, minor)
        self.ce_pin = ce_pin

        gpio.init()
        gpio.setcfg(self.ce_pin, gpio.OUTPUT)

        time.sleep(5 / 1000000.0)

        # Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier
        # WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet
        # sizes must never be used. See documentation for a more complete explanation.
        self.write_register(NRF24.SETUP_RETR, (int('0100', 2) << NRF24.ARD) | (int('1111', 2) << NRF24.ARC))

        # Restore our default PA level
        self.setPALevel(NRF24.PA_MAX)

        # Determine if this is a p or non-p RF24 module and then
        # reset our data rate back to default value. This works
        # because a non-P variant won't allow the data rate to
        # be set to 250Kbps.
        if self.setDataRate(NRF24.BR_250KBPS):
            self.p_variant = True

        # Then set the data rate to the slowest (and most reliable) speed supported by all
        # hardware.
        self.setDataRate(NRF24.BR_1MBPS)

        # Initialize CRC and request 2-byte (16bit) CRC
        self.setCRCLength(NRF24.CRC_16)

        # Disable dynamic payloads, to match dynamic_payloads_enabled setting
        self.write_register(NRF24.DYNPD, 0)

        # Reset current status
        # Notice reset and flush is the last thing we do
        self.write_register(NRF24.STATUS, _BV(NRF24.RX_DR) | _BV(NRF24.TX_DS) | _BV(NRF24.MAX_RT))

        # Set up default configuration.  Callers can always change it later.
        # This channel should be universally safe and not bleed over into adjacent
        # spectrum.
        self.setChannel(self.channel)

        # Flush buffers
        self.flush_rx()
        self.flush_tx()
Example #36
0
	def __init__(self):
		gpio.init()
		
		self.sensorPin = port.PA8 #Port for the light barrier on the column bottom
		self.sleepPin = port.PA9 #Sleep Pin of the Polulu
		self.stepPin = port.PA10 #Step Pin of the Polulu
		self.dirPin = port.PA20 #Direction Pin of the Polulu
		
		
		
		self.height = 8450
		
		#Configure the Pins
		gpio.setcfg(self.sensorPin, gpio.INPUT)
		gpio.pullup(self.sensorPin, gpio.PULLUP)

		gpio.setcfg(self.sleepPin, gpio.OUTPUT)
		gpio.setcfg(self.stepPin, gpio.OUTPUT)
		gpio.setcfg(self.dirPin, gpio.OUTPUT)
Example #37
0
    def __init__(self, params):
        self.value=0
        self.steps_pin = params['steps_pin'] if 'steps_pin' in params else 1
        self.dir_pin = params['dir_pin'] if 'dir_pin' in params else 2
        self.steps = params['steps'] if 'steps' in params else 0
        self.dir = params['dir'] if 'dir' in params else 0
        self.interval = params['interval'] if 'interval' in params else 0.25
        self.steps2sync = params['steps2sync'] if 'steps2sync' in params else 100
        self.stop=1
        if self.steps:
            self.buzy=1
        else:
            self.buzy=0

        signal.signal(signal.SIGALRM, self.alarm_handler)

        gpio.init()
        gpio.setcfg(self.steps_pin, gpio.OUTPUT)
        gpio.setcfg(self.dir_pin, gpio.OUTPUT)
        gpio.output(self.steps_pin, 0)
        gpio.output(self.dir_pin, 0)
Example #38
0
	def __init__(self):
		self.pos = 0
		self.testmode = False
		try:
			from pyA20.gpio import gpio
			from pyA20.gpio import port
			from pyA20.gpio import connector
			global pins

			gpio.init() #Initialize module. Always called first
			pins = [ port.PA8, port.PA9, port.PA10, port.PA20 ]

		
			for p in pins:
				gpio.setcfg(p, gpio.OUTPUT)  #Configure LED1 as output
				gpio.output(p, 1)
				time.sleep(0.01)
				gpio.output(p, 0)
		
			gpio.output(pins[0], 1)
			self.gpio = gpio
		except:
			print "Focuser test mode"
			self.testmode = True
Example #39
0
from pyA20.gpio import gpio
from pyA20.gpio import port
#import RPi.GPIO as GPIO
import dht22
import time
import json

from properties import *

# https://github.com/ionutpi/DHT22-Python-library-Orange-PI/blob/master/README.md

# initialize GPIO
#gpio.setwarnings(False)
#gpio.setmode(GPIO.BCM)
PIN2 = port.PA6
gpio.init()
#gpio.cleanup()

# read data using pin 14
instance = dht22.DHT22(pin=PIN2)

client = mqtt.Client()

data = {
    'client_id': 1,
    'location': 'master_bedroom'
}

while True:
    result = instance.read()
    data['temp'] = result.temperature
Example #40
0
	def setup(self):
		GPIO.init()
		GPIO.setcfg(self._pconfig['button'], GPIO.INPUT)
		GPIO.pullup(self._pconfig['button'], GPIO.PULLUP)
		GPIO.setcfg(self._pconfig['rec_light'], GPIO.OUTPUT)
		GPIO.setcfg(self._pconfig['plb_light'], GPIO.OUTPUT)
Example #41
0
#!/usr/bin/python
from pyA20.gpio import gpio as GPIO
from pyA20.gpio import port
import sys

# Check if there are 2 parameters
if len(sys.argv) == 3:

    # Arguments
    ledPin = int(sys.argv[1])
    state = int(sys.argv[2])

    # Setup GPIO
    GPIO.init()

    # Setup led
    if state == 1:
        # Setup LED as OUTPUT
        GPIO.setcfg(ledPin, GPIO.OUTPUT)
        # Turn on LED (we keep the state)
        GPIO.output(ledPin, True)
    if state == 0:
        # Setup LED as OUTPUT
        # Clean state (this will turn off the led)
        GPIO.setcfg(ledPin, GPIO.OUTPUT)
        GPIO.output(ledPin, False)

else:
    print "usage:onoff_orange.py pin state"