예제 #1
0
def checkThenSetByte(dataVar):
	gpio = GPIO(debug=False)                                            
	for x in range(0,8):
		if x==0: 
			pin=2                                                 
		elif x==1: 
			pin=3
		elif x==2:
			pin=4
		elif x==3:                                                              
			pin=5
		elif x==4:                                                              
			pin=6
		elif x==5:                                                              
			pin=13
		else:
			break
		
		gpio.pinMode(pin,gpio.OUTPUT) 
		if checkBit(dataVar,x)>0:
			print("on")
			gpio.digitalWrite(pin, gpio.HIGH)
			if pin==13:
				print('indikator on')
		else: 	
			print("off")
			gpio.digitalWrite(pin, gpio.LOW)
			if pin==13:                                                                                   
				print('indikator off')
	if debugMode:print("seharusnya setelah di set, disini dicek lagi benar2 on apa tidak")	    
예제 #2
0
def main(argv):
   print 'Starting up'
   gpio = GPIO(debug=False)
   gpio.pinMode(8,gpio.OUTPUT)
   for i in range(4):
      print 'Hi\n'
      gpio.digitalWrite(8,gpio.HIGH)
      time.sleep(0.5)
      print 'Lo\n'
      gpio.digitalWrite(8,gpio.LOW)
      time.sleep(0.5)
   print 'Done\n'
   gpio.cleanup()
예제 #3
0
class Device(object):
    def __init__(self, pin_):
        self.gpio = GPIO(debug=False)
        self.gpio.pinMode(pin_, self.gpio.OUTPUT)

    def onDevice(self, pin_):
        return self.gpio.digitalWrite(pin_, self.gpio.HIGH)

    def offDevice(self, pin_):
        return self.gpio.digitalWrite(pin_, self.gpio.LOW)

    def getDevice(self, pin_):
        return self.gpio.digitalRead(pin_)
예제 #4
0
def main(argv):
   print 'Starting up'
   gpio = GPIO(debug=False)
   for i in range(5):
      gpio.pinMode(8+i,gpio.OUTPUT)
   gpio.pinMode(19,gpio.ANALOG_INPUT)
   for i in range(4100):
      x = gpio.analogRead(19)
      print x
      n = (x-460)/30
      for j in range(5):
         if j<n: 
           s=gpio.HIGH 
         else: 
           s=gpio.LOW
         gpio.digitalWrite(8+j,s)
      time.sleep(0.1)
   print 'Done\n'
   gpio.cleanup()
예제 #5
0
print 'Setting up pins %d and %d...' % (pin, button)

# Set pin 13 to be used as an output GPIO pin.
gpio.pinMode(pin, gpio.OUTPUT)

# Set pin 2 to be used as an input GPIO pin.
gpio.pinMode(button, gpio.INPUT)

print 'Reading from pin %d now...' % button
try:
    while(True):
        # Read the state of the button
        state = gpio.digitalRead(button)

        # If the button is pressed turn ON pin 13
        if state == 1:
            gpio.digitalWrite(pin, gpio.HIGH)

        # If the button is not pressed turn OFF pin 13
        else:
            gpio.digitalWrite(pin, gpio.LOW)

# Kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave the led turned off.
    print '\nCleaning up...'
    gpio.digitalWrite(pin, gpio.LOW)

    # Do a general cleanup. Calling this function is not mandatory.
    gpio.cleanup()
예제 #6
0
import time
import subprocess

from wiringx86 import GPIOGalileoGen2 as GPIO

gpio = GPIO(debug=False)

pwm_pin = 11
value = 0
fade = 5

print("Setting up Pins...")
gpio.pinMode(pwm_pin, gpio.OUTPUT)

try:
    while (True):

        for i in xrange(0, 1000):
            gpio.digitalWrite(pwm_pin, gpio.HIGH)
            time.sleep(0.001)
            gpio.digitalWrite(pwm_pin, gpio.LOW)
            time.sleep(0.001)

        time.sleep(2)

except KeyboardInterrupt:
    print("Cleaning up...")
    gpio.digitalWrite(pwm_pin, gpio.LOW)
    gpio.cleanup()
예제 #7
0
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
state = gpio.HIGH
pins = 20

# Set all pins to be used as output GPIO pins.
print 'Setting up all pins...'
for pin in range(0, pins):
    gpio.pinMode(pin, gpio.OUTPUT)

print 'Blinking all pins now...'
try:
    while(True):
        for pin in range(0, pins):
            # Write a state to the pin. ON or OFF.
            gpio.digitalWrite(pin, state)

        # Toggle the state.
        state = gpio.LOW if state == gpio.HIGH else gpio.HIGH

        # Sleep for a while.
        time.sleep(0.5)

# When you get tired of seeing the led blinking kill the loop with Ctrl-C.
except KeyboardInterrupt:
    # Leave all leds turned off.
    print '\nCleaning up...'
    for pin in range(0, pins):
        gpio.digitalWrite(pin, gpio.LOW)

    # Do a general cleanup. Calling this function is not mandatory.
예제 #8
0
photo_pin = 16

print("Setting up all pins")

gpio.pinMode(user_pin, gpio.OUTPUT)
gpio.pinMode(internet_pin, gpio.OUTPUT)
gpio.pinMode(mote_pin, gpio.OUTPUT)
gpio.pinMode(alarm_pin, gpio.OUTPUT)
gpio.pinMode(speaker_pin, gpio.OUTPUT)
gpio.pinMode(presence_pin, gpio.INPUT)
gpio.pinMode(lm35_pin, gpio.ANALOG_INPUT)
gpio.pinMode(photo_pin, gpio.ANALOG_INPUT)

while (True):
    print("Turning User Pin On")
    gpio.digitalWrite(user_pin, gpio.HIGH)
    time.sleep(0.2)
    print("Turning Internet Pin On")
    gpio.digitalWrite(internet_pin, gpio.HIGH)
    time.sleep(0.2)
    print("Turning Mote Pin On")
    gpio.digitalWrite(mote_pin, gpio.HIGH)
    time.sleep(0.2)
    print("Turning Alarm Pin On")
    gpio.digitalWrite(alarm_pin, gpio.HIGH)
    time.sleep(0.2)
    print("Turning User Pin Off")
    gpio.digitalWrite(user_pin, gpio.LOW)
    time.sleep(0.2)
    print("Turning Internet Pin Off")
    gpio.digitalWrite(internet_pin, gpio.LOW)
예제 #9
0
	varReset = int(jsondata['output']['attribute']['reset'])
	print ("rst : ")
	print (varReset)
	print (" ")
	
	urlKirim = 'http://api.geeknesia.com/api/attribute/on1?api_key=005d9063bc2a1cb4999ef67391f2ba42'
	f = urllib2.urlopen(urlKirim)
	jsondata = json.loads(f.read())
	varOn1 = int(jsondata['output']['attribute']['on1'])
	print ("on1 : ")
	print (varOn1)
	print (" ")

	if varOn1:
		state = gpio.HIGH
		gpio.digitalWrite(2, state)
	else:
		state = gpio.LOW
		gpio.digitalWrite(2, state)

	urlKirim = 'http://api.geeknesia.com/api/attribute/on2?api_key=005d9063bc2a1cb4999ef67391f2ba42'
	f = urllib2.urlopen(urlKirim)
	jsondata = json.loads(f.read())
	varOn2 = int(jsondata['output']['attribute']['on2'])
	print ("on2 : ")
	print (varOn2)
	print (" ")

	if varOn2:
		state = gpio.HIGH
		gpio.digitalWrite(3, state)
예제 #10
0
from openweather import openweather
try:
    with open('config.txt') as json_data:
        config = json.load(json_data)
    piracicaba = openweather(config['api_key'], '3453643')
except:
    print 'Erro na coneccao com a internet'

from upm import pyupm_jhd1313m1 as LCD
lcd = LCD.Jhd1313m1(0, 0x3E, 0x62)
from upm import pyupm_servo as servo
from upm import pyupm_temperature as upm
import threading

pino_sensor_temperatura = 0
pino_rele1 = 4
pino_servo = 5
pino_rele2 = 8
pino_pot = 15
pino_pot2 = 16
pino_pot3 = 17

pinos.pinMode(pino_rele1, pinos.OUTPUT)
pinos.pinMode(pino_rele2, pinos.OUTPUT)
pinos.pinMode(pino_pot, pinos.ANALOG_INPUT)
pinos.pinMode(pino_pot2, pinos.ANALOG_INPUT)
pinos.pinMode(pino_pot3, pinos.ANALOG_INPUT)
pinos.pinMode(pino_servo, pinos.PWM)
sg_servo = servo.ES08A(pino_servo)
pinos.digitalWrite(pino_rele1, pinos.LOW)
pinos.digitalWrite(pino_rele2, pinos.LOW)
예제 #11
0
class Pump(object):
    """
    Simple class that helps to open and close a pump that is connected to the board
    One instance represents one pump
    """

    instances = {}

    opened = 'OPENED'
    closed = 'CLOSED'

    def __init__(self, uuid, pin, name, debug=False, gpio_debug=False):
        print_debug(debug, currentframe().f_code.co_name, 'Init pump: %s' % name, __name__)

        # Make sure we only have one instance per pump
        if uuid in self.instances:
            error = ValueError
            error.message = 'A pump-instance with ID "%i" already exist!' % uuid
            raise error

        # Add the new instance to the instances-list
        Pump.instances[uuid] = self

        self.uuid = uuid
        self.pin = pin
        self.name = name
        self.digital_pin = digitalPins.get(pin)
        self.debug = debug

        all_params_str = u'Uuid: {uuid}. Pin: {pin}. Digital pin: {dpin}. Name: {name}'.format(
            uuid=uuid,
            pin=pin,
            dpin=self.digital_pin,
            name=name,
        )
        print_debug(debug, currentframe().f_code.co_name, all_params_str, __name__)

        # Get a new instance of the GPIO
        self.gpio = GPIO(debug=gpio_debug)  # type: GPIO

        # Set the pump to output
        self.gpio.pinMode(self.digital_pin, self.gpio.OUTPUT)

        # Set the pumps initial status to closed
        self.__status = self.closed

        # Events the pump can send
        self.pump_is_turned_on = signal(blinker_signals['pump_is_on'])
        self.pump_is_turned_off = signal(blinker_signals['pump_is_off'])

    def turn_on_pump(self, magnetic_valve):
        """
        Will open a specific pump and when it's open, and filled with water, it will open the valve provided

        :type magnetic_valve: MagneticValve
        :param magnetic_valve: The valve that should be opened while the pump is opened
        """
        print_debug(self.debug, currentframe().f_code.co_name, 'Turning on pump: %s' % self.name, __name__)
        self.__status = self.opened
        self.gpio.digitalWrite(self.digital_pin, self.gpio.HIGH)

        # Open the valve after 1 second so we know there's water in the hose
        timer_time = 1
        timer = Timer(timer_time, self.__send_turned_on_event, args=[magnetic_valve])
        timer.start()

    def turn_off_pump(self):
        """
        Turn off the pump
        :return:
        """
        print_debug(self.debug, currentframe().f_code.co_name, 'Turning off pump: %s' % self.name, __name__)
        self.__status = self.closed
        self.gpio.digitalWrite(self.digital_pin, self.gpio.LOW)

    def cleanup(self):
        """
        Turn off the pump on cleanup
        """
        self.turn_off_pump()

    def __send_turned_on_event(self, valve):
        """
        Send the turn on signal to the WateringQueue so it knows that it can open the valve
        :param valve:
        :return:
        """
        self.pump_is_turned_on.send(valve)

    @property
    def is_opened(self):
        return self.__status is self.opened

    @property
    def get_instances(self):
        return self.instances