Ejemplo n.º 1
0
 def init_gpio(pin, dir, mode):
     # Set direction and pull-down/pull-up for an mraa gpio pin,
     # and return mraa.Gpio object.
     gpio = mraa.Gpio(pin)
     gpio.dir(dir)
     gpio.mode(mode)
     return gpio
Ejemplo n.º 2
0
def greenled(state):
    ledpin = mraa.Gpio(13)
    ledpin.dir(mraa.DIR_OUT)
    if state == 1:
        ledpin.write(1)
    else:
        ledpin.write(0)
Ejemplo n.º 3
0
def set_mode(pin, mode=1):
    try:
        pin = mraa.Gpio(pin)
        pin.dir(mraa.DIR_OUT)
        pin.write(mode)
    except Exception as ex:
        print(ex)
Ejemplo n.º 4
0
def fridgescanner():
    x = mraa.Gpio(26)
    x.dir(mraa.DIR_OUT)
    x.write(255)
    #time.sleep(2)
    call(['./pic'])
    x.write(0)
    outFile = open('Output.txt', 'w')
    visual_recognition = VisualRecognitionV3('2016-05-20', api_key='cf40138eb6764ea300b5fafe571e3369bc4f6ce9')
    
    output = {}
    with open(join(dirname(__file__), 'cpp-headless-output-COLOR.png'), 'rb') as image_file:
        output = visual_recognition.classify(images_file=image_file)
        outFile.write(json.dumps(output, indent=2))
        outFile.close()
    
    
    
    inp = output.get('images')
    inp = inp[0].get('classifiers')
    
    out = []
    
    for group in inp:
        classes = []
        classes = group.get('classes')
        for desc in classes:
            if desc.get('score') >= THRESHOLD:
                out.append(desc.get('class'))
    
    print out
    outfile = open('thingy.txt', 'w')
    outfile.write('\n'.join(out))
Ejemplo n.º 5
0
def encenderLed(valor):
    #variables rgb e inicializacion de pines RGB
    rojo = 40  #corresponde al pin de la placa
    verde = 36  #corresponde al pin de la placa
    azul = 38  #corresponde al pin de la placa
    pin_r = m.Gpio(rojo)
    pin_b = m.Gpio(azul)
    pin_r.dir(m.DIR_OUT)
    pin_b.dir(m.DIR_OUT)
    print("Encender LED:  " + str(valor))
    if valor > 650:
        pin_r.write(1)
        pin_b.write(1)
    else:
        pin_r.write(0)
        pin_b.write(0)
Ejemplo n.º 6
0
    def __init__(self):
        # read cpuinfo to determine hw
        f = file("/proc/cpuinfo")
        proc = ""
        for line in f:
            if "Intel" in line:
                proc = "Intel"
                break

        if "Intel" in proc:
            self.CS0 = 23
            self.SPI_FROM_DESC = "spi-raw-5-1"
            self.RST_PIN = 36
        else: # assume RPi
            self.CS0 = 24
            self.SPI_FROM_DESC = "spi-raw-0-0"
            self.RST_PIN = 7
        self.cs0 = m.Gpio(self.CS0)
        self.cs0.dir(m.DIR_OUT)
        self.cs0.write(1)

        self.dev = m.spiFromDesc(self.SPI_FROM_DESC)
        self.dev.frequency(62500)
        self.dev.mode(m.SPI_MODE0)
        self.dev.bitPerWord(8)
        self.timeout = 0
        self.rx_buf = []
Ejemplo n.º 7
0
    def get_sensor_info(self, e, switching_to, min_impulse_time):
        # e = threading.Event()
        gpio = mraa.Gpio(self.sensor_pin)
        prev_switch = gpio.read()
        logging.log(
            logging.DEBUG,
            "number_of_activations: " + str(self.number_of_activations))
        start = time.time()

        while (True):
            switch = gpio.read()
            # logging.log(logging.DEBUG, "switch: " + str(switch))
            # '''switching_to  - to what will'''

            if switch != prev_switch and switch == switching_to:
                end = time.time()
                # print ("end - start: " + str(end - start))
                if end - start > min_impulse_time:
                    # logging.log(logging.DEBUG, "switch: " + str(switch))
                    #     logging.log(logging.DEBUG, "event before: " + str(e.is_set()))
                    e.set()
                    logging.log(logging.DEBUG, "event: " + str(e.is_set()))
                    self.number_of_activations += 1
                    logging.log(
                        logging.DEBUG, "number_of_activations: " +
                        str(self.number_of_activations))
                    start = time.time()
                    # logging.log(logging.DEBUG, "event after: " + str(e.is_set()))

            prev_switch = switch
Ejemplo n.º 8
0
    def run(self):
        print("opening thread: "+self.thread_name)
 
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
        s.bind((self.ip, self.port_number))
 
        s.listen(1)
 
        while 1:
                conn, addr = s.accept()
 
                print ('Connection address:', addr)
                
                current_status = 0
 
                while 1:
 
                        data = conn.recv(self.buffer_size)
	                gpio_1 = mraa.Gpio(int(data[5]))
 			gpio_1.dir(mraa.DIR_OUT)
                        if data.find("on") != -1:
          	        	current_status = 1
                        else:
                                current_status = 0
                        gpio_1.write(current_status)
                        print ("received data:", data)
 
                        if data == 'close':
                                break
                conn.close()
        s.close()
        s = none
Ejemplo n.º 9
0
    def __init__(self, step_pin, direction_pin, enable_pin):
        # By default we don't mix the water
        self.state = False
        self.step_pin = step_pin
        self.direction_pin = direction_pin
        self.enable_pin = enable_pin
        self.delay_time = 0.001

        self.step_gpio = mraa.Gpio(step_pin)
        self.direction_gpio = mraa.Gpio(direction_pin)
        self.enable_gpio = mraa.Gpio(enable_pin)

        self.step_gpio.dir(mraa.DIR_OUT)
        self.direction_gpio.dir(mraa.DIR_OUT)
        self.enable_gpio.dir(mraa.DIR_OUT)
        print("The mixer was initialised!")
Ejemplo n.º 10
0
    def __init__(self, port='/dev/ttyMFD1', baudrate=115200, re_de_pin=36, **kwargs):
        super(PlenSerial, self).__init__(
            port=port, baudrate=baudrate, **kwargs)
        self.re_de = mraa.Gpio(re_de_pin)

        self.flushOutput()
        self.flushInput()
Ejemplo n.º 11
0
def led(i):
    if session.get('authenticated'):
        if session['authenticated'] != 'yes':
            response = redirect('/loginForm', code=302)
            return response
    else:
        response = redirect('/loginForm', code=302)
        return response

    ledPostAction = i
    if ledPostAction == 0:
        ledWord = "off"
        ledAction = 0
    elif ledPostAction == 1:
        ledWord = "on"
        ledAction = 1
    else:
        return (True)

    pin = mraa.Gpio(12)
    pin.dir(mraa.DIR_OUT)
    pin.write(ledAction)
    bodyText = Markup("Turning LED " + ledWord +
                      "<br> <br> <a href=/logout> logout </a> <br>")
    return render_template('template.html', bodyText=bodyText)
Ejemplo n.º 12
0
 def __init__(self, pump_name, pin):
     self.state = False
     self.pump_name = pump_name
     self.gpio = mraa.Gpio(pin)
     self.gpio.dir(mraa.DIR_OUT)
     print("The pump \"{}\" was initialised.".format(pump_name))
     return
Ejemplo n.º 13
0
 def reset(self):
     self.RST = m.Gpio(36)
     self.RST.dir(m.DIR_OUT)
     self.RST.write(0)  #reset the device
     time.sleep(0.01)
     self.RST.write(1)  #let the device out of reset
     time.sleep(2.01)  #wait for the CC1110 to come up
Ejemplo n.º 14
0
 def setPinmuxToGpio(self, gpioPinmux, index):
         direction = gpioPinmux.split('_')[1].lstrip().rstrip().lower()
         gpio = mraa.Gpio(index)
         gpio.dir(mraa.DIR_OUT if direction == 'output' else mraa.DIR_IN)
         if direction == 'output':
             gpio.write(0)
         gpio.mode(self.pullMode(index))
Ejemplo n.º 15
0
def ControlRelay(flag):
    relay = mraa.Gpio(62)  # GPIO_51
    relay.dir(mraa.DIR_OUT)
    if flag == 1:
        relay.write(1)
    else:
        relay.write(0)
Ejemplo n.º 16
0
 def __init__(self, cs, spi_mode=mraa.SPI_MODE3):
     self.spi = mraa.Spi(0)
     if cs==0:
         self.cs = mraa.Gpio(23)
     elif cs==1: 
         self.cs = mraa.Gpio(9)
     elif cs==2:
         self.cs = mraa.Gpio(32)
     self.cs.dir(mraa.DIR_OUT)
     self.cs.write(1)
     self.spi.frequency(2000000) # 2 MHz
     self.spi.mode(spi_mode)
     self.spi_mode = spi_mode
     self._WRITE_MAX = 20
     # first write a dummy byte
     self.spi.writeByte(0)
Ejemplo n.º 17
0
    def __init__(self):
        #====== Default values on initialization ======#
        self.currentLat = 0.0      # From the airmar
        self.currentLong = 0.0
        self.truWndDir = 0.0
        self.currentHeading = 0.0

        #Autonomous pins from RC
        self.autonomousPin = mraa.Aio(1)  #The analog pin number for aux 1
        self.auxDivide = 50               #A good dividing line (in 1024 bit adc units) to determine between high and low switch)
        self.currentlyAutonomous = False  #Default into manual on boot (so if in manual during startup we don't lose control)

        #Relay pins
        self.sailRelayPin =  mraa.Gpio(4)    #Pin 4 is sail relays
        self.sailRelayPin.dir(mraa.DIR_OUT)
        self.rudderRelayPin = mraa.Gpio(2)   #Pin 2 is rudder relay
        self.rudderRelayPin.dir(mraa.DIR_OUT)


        # Our publisher for leg data to the navigator
        self.pub_leg = rospy.Publisher("/leg_info", LegInfo, queue_size = 10)
        self.pub_autonomous = rospy.Publisher("/autonomous_status", AutonomousStatus, queue_size = 10)

        #Default into wait mode
        self.compMode = "Wait"     # From competition_info
                                   # POSSIBLE VAULES:
                                   # - Wait
                                   # - SailToPoint
                                   # - MaintainHeading
                                   # - MaintainPointOfSail
                                   # - RoundAndReturn
                                   # - StationKeeping


        self.legQueue = Queue.Queue(maxsize=0)  #A queue of waypoints, no max size
        self.beginLat = 0.0
        self.beginLong = 0.0
        self.taskBeginTime = -1.0    #For timed legs...

        #The end waypoint for this leg
        self.current_target_waypoint = -1


        #CONSTANTS
        self.legArrivalTol = 1.0       #How close do we have to  get to waypoint to have "arrived." 1.0m for now
        self.cautious = False
        self.cautiousDistance = 30.0   #How far away from waypoint to we start being cautious
Ejemplo n.º 18
0
    def __init__(self):
        # Set up the wiringpi object to use physical pin numbers
        # wp.wiringPiSetupPhys()

        # Intel MRAA
        # CS_PIN      = 15   	GPIO(22)
        # DRDY_PIN    = 11	GPIO(17)
        # RESET_PIN   = 12	GPIO(18)
        # PDWN_PIN    = 13	GPIO(27)

        self.CS_PIN = m.Gpio(15)  #phy. 15
        self.DRDY_PIN = m.Gpio(11)  #phy. 11
        self.RESET_PIN = m.Gpio(12)  #phy. 12
        self.PDWN_PIN = m.Gpio(13)  #phy. 13

        # Initialize the DRDY pin
        self.DRDY_PIN.dir(m.DIR_IN)
        # wp.pinMode(self.DRDY_PIN, wp.INPUT)

        # Initialize the reset pin
        self.RESET_PIN.dir(m.DIR_OUT)
        self.RESET_PIN.write(1)
        # reset = m.Gpio(15).dir(m.DIR_OUT)
        # wp.pinMode(self.RESET_PIN, wp.OUTPUT)
        # wp.digitalWrite(self.RESET_PIN, wp.HIGH)
        # self.reset.write(1)

        # Initialize PDWN pin
        self.PDWN_PIN.dir(m.DIR_OUT)
        self.PDWN_PIN.write(1)
        # wp.pinMode(self.PDWN_PIN, wp.OUTPUT)
        # wp.digitalWrite(self.PDWN_PIN, wp.HIGH)

        # Initialize CS pin
        self.CS_PIN.dir(m.DIR_OUT)
        self.CS_PIN.write(1)
        #wp.pinMode(self.CS_PIN, wp.OUTPUT)
        #wp.digitalWrite(self.CS_PIN, wp.HIGH)

        # Initialize the wiringpi SPI setup
        #spi_success = wp.wiringPiSPISetupMode(self.SPI_CHANNEL, self.SPI_FREQUENCY, self.SPI_MODE)
        self.x = m.Spi(self.SPI_CHANNEL)
        self.x.frequency(self.SPI_FREQUENCY)
        self.x.mode(self.SPI_MODE)
        spi_success = self.x
        debug_print("SPI success " + str(spi_success))
Ejemplo n.º 19
0
 def __init__(self, dev=0, spd=1000000):
   pin_22 = mraa.Gpio(self.NRSTPD)
   # Initialize GPIO2 (P10 on LinkIt Smart 7688 board)
   pin_22.dir(mraa.DIR_OUT)  # set as OUTPUT pin
   spi = mraa.Spi(0)
   spi.frequency(spd)
   pin_22.write(1)
   self.MFRC522_Init()
Ejemplo n.º 20
0
def main():
	led_num = sys.argv[1]
	# Use LEDs GPIO 12, 14, 16, 18, 20
	led = mraa.Gpio(led_num)
	# Set LED to be output
	led.dir(mraa.DIR_OUT)
	# Write 1 to the LED
	led.write(1)
Ejemplo n.º 21
0
def pingloop():
    sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
    sock.bind(('', 0))
    led = mraa.Gpio(ledpin)
    led.dir(mraa.DIR_OUT)
    while True:
        data = sock.recv(2)
        toggleled(led)
Ejemplo n.º 22
0
 def __init__(self, pin_number):
     threading.Thread.__init__(self)
     try:
         self._led = mraa.Gpio(pin_number)
         self._led.dir(mraa.DIR_OUT)
         self.stop_flag = False
     except:
         raise
Ejemplo n.º 23
0
 def __init__(self, pin_no, freq=2.0):
     self.stopped = True
     # Export the GPIO pin for use
     if use_mraa:
         self.pin = mraa.Gpio(pin_no)
         self.pin.dir(mraa.DIR_OUT)
         self.pin.write(0)
     self.period = 1 / (2 * freq)
Ejemplo n.º 24
0
 def __init__(self, gpio, sleep=1, name='RainProcess'):
     Process.__init__(self, name=name)
     self.logger = multiprocessing.get_logger()
     self.event = Event()
     self.gpio = gpio
     self.sleep = sleep
     self.pump = mraa.Gpio(self.gpio)
     self.pump.dir(mraa.DIR_OUT)
Ejemplo n.º 25
0
 def get_led(self):
     leds = []
     for i in range(2, 5):
         led = mraa.Gpio(i)
         led.dir(mraa.DIR_OUT)
         led.write(1)
         leds.append(led)
     return leds
Ejemplo n.º 26
0
def buzz():
    BUZZER = mraa.Gpio(7)
    BUZZER.dir(mraa.DIR_OUT)

    BUZZER.write(1)
    time.sleep(3)
    BUZZER.write(0)
    time.sleep(3)
Ejemplo n.º 27
0
 def setState(self):
     led = mraa.Gpio(int(self.info["port"]))
     led.dir(mraa.DIR_OUT)
     led.write(int(self.info["state"]))
     if led.read() == 1:
         return "Encendido"
     else:
         return "Apagado"
Ejemplo n.º 28
0
def buzzer (distance,beeps, pin):
    buzzer = mraa.Gpio(pin)
    buzzer.dir(mraa.DIR_OUT)
    for i in range(beeps):
        time.sleep(.1-5*distance)
        buzzer.write(1)
        time.sleep(distance)
        buzzer.write(0)
Ejemplo n.º 29
0
def ledStatus():
    pin = mraa.Gpio(12)
    if pin.read() == 0:
        status = "off"
    else:
        status = "on"
    bodyText = "The LED is currently " + status
    return render_template('template.html', bodyText=bodyText)
Ejemplo n.º 30
0
def led_glow(x):
    a = mraa.Gpio(29)
    a.dir(mraa.DIR_OUT)
    for i in range x*4:
        a.write(1)
        time.sleep(0.1)
        a.write(0)
        time.sleep(0.1)