Esempio n. 1
0
def buttons_daemon (thread_name, delay):
	gpio = GPIO(debug=False)
	pinButtons = [2,3,4]
	state = [0,0,0]
	k = PyKeyboard()
	for i in pinButtons:
		gpio.pinMode(i, gpio.INPUT) 
	while True:
		for i in xrange(3):
			state[i] = gpio.digitalRead(pinButtons[i])
		if state[1] == 1 and state[2] == 0 and state[3] == 0: #Up Arrow
			k.tap_key('up')	
		if state[2] == 1 and state[1] == 0 and state[3] == 0: #Down Arrow (tab)
			k.tap_key('tab')
		if state[3] == 1 and state[1] == 0 and state[2] == 0: #OK (enter)
			k.tap_key('enter')
		#if state[]
		time.sleep(delay)
Esempio n. 2
0
def start_stream(sensor_pin=14, fs=10):
    """ Reads values from analog pin 14 and forwards them to a LSL-stream. """
    # Setup the LSL stream
    uuid = binascii.b2a_hex(os.urandom(3))
    stream_info = lsl.StreamInfo('luminosity', 'analog', 1, fs, 'float32', uuid)
    stream_outlet = lsl.StreamOutlet(stream_info)

    # Setup GPIO
    gpio = GPIO(debug=False)
    gpio.pinMode(sensor_pin, gpio.ANALOG_INPUT)

    interval = 1.0 / fs

    try:
        while True:
            value = gpio.analogRead(sensor_pin)
            stream_outlet.push_sample([value])
            time.sleep(interval)

    except KeyboardInterrupt:
        print("\nCleaning up...")
        gpio.cleanup()
Esempio n. 3
0
def start_stream(sensor_pin=14, fs=10):

    # Setup the LSL stream
    uuid = binascii.b2a_hex(os.urandom(3))
    stream_info = lsl.StreamInfo('luminosity', 'analog', 1, fs, 'float32', uuid)
    stream_outlet = lsl.StreamOutlet(stream_info)

    # Setup GPIO
    gpio = GPIO(debug=False)
    gpio.pinMode(sensor_pin, gpio.ANALOG_INPUT)

    interval = 1.0 / fs

    try:
        while True:
            value = gpio.analogRead(sensor_pin)
            stream_outlet.push_sample([value])
            time.sleep(interval)

    except KeyboardInterrupt:
        print("\nCleaning up...")
        gpio.cleanup()
Esempio n. 4
0
u_id = "A2837C04-4AE1-441A-95D5-C25E6D9D1D10"


def reg():
    APPLICATION_ID = "TBhSWVtf7LUzCUxUlhF5wFfLKdquF4jEJjK1cVqQ"
    REST_API_KEY = "j3QxkFjL9zzOiSMrUqlQYFh5VZRKSrvWh3A7Ob3a"
    register(APPLICATION_ID, REST_API_KEY)


class UserTable(ParseObject):
    pass


reg()

gpio.pinMode(4, gpio.OUTPUT)
gpio.pinMode(5, gpio.OUTPUT)
gpio.pinMode(6, gpio.OUTPUT)
gpio.pinMode(7, gpio.OUTPUT)


def handler_left():
    gpio.digitalWrite(4, gpio.LOW)
    gpio.digitalWrite(5, gpio.LOW)
    gpio.digitalWrite(6, gpio.HIGH)
    gpio.digitalWrite(7, gpio.LOW)


def handler_straight():
    gpio.digitalWrite(4, gpio.HIGH)
    gpio.digitalWrite(5, gpio.LOW)
Esempio n. 5
0
import time
from wiringx86 import GPIOEdison as GPIO
gpio = GPIO(debug=False)
pin1 = 3
pin2 = 4
pin3 = 5
pin4 = 6
index = 0

print 'Setting up pin %d' % pin1
gpio.pinMode(pin1, gpio.OUTPUT)
print 'Setting up pin %d' % pin2
gpio.pinMode(pin2, gpio.OUTPUT)
print 'Setting up pin %d' % pin3
gpio.pinMode(pin3, gpio.OUTPUT)
print 'Setting up pin %d' % pin4
gpio.pinMode(pin4, gpio.OUTPUT)

print 'Go up now...'
try:
    while (True):
        gpio.digitalWrite(pin4, gpio.LOW)
        gpio.digitalWrite(pin2, gpio.HIGH)
        time.sleep(0.01)

        gpio.digitalWrite(pin1, gpio.LOW)
        gpio.digitalWrite(pin3, gpio.HIGH)
        time.sleep(0.01)

        gpio.digitalWrite(pin2, gpio.LOW)
        gpio.digitalWrite(pin4, gpio.HIGH)
Esempio n. 6
0
# Import the time module enable sleeps between turning the led on and off.
import time

# Import the GPIOEdison class from the wiringx86 module.
from wiringx86 import GPIOEdison as GPIO

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = 13
analogpin = 14

print 'Setting up all pins...'

# Set pin 14 to be used as an analog input GPIO pin.
gpio.pinMode(analogpin, gpio.ANALOG_INPUT)

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

print 'Analog reading from pin %d now...' % analogpin
try:
    while (True):
        # Read the voltage on pin 14
        value = gpio.analogRead(analogpin)

        # Turn ON pin 13
        gpio.digitalWrite(pin, gpio.HIGH)

        # Sleep for a while depending on the voltage we just read. The higher
        # the voltage the more we sleep.
from wiringx86 import GPIOEdison as GPIO
import paho.mqtt.client as paho, os, urlparse, time

gpio = GPIO(debug=False)
analogpin = 17 
gpio.pinMode(analogpin, gpio.ANALOG_INPUT)

# Define event callbacks
def on_connect(mosq, obj, rc):
    print("rc: " + str(rc))

def on_message(mosq, obj, msg):
    print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))

def on_publish(mosq, obj, mid):
    print("mid: " + str(mid))

def on_subscribe(mosq, obj, mid, granted_qos):
    print("Subscribed: " + str(mid) + " " + str(granted_qos))

def on_log(mosq, obj, level, string):
    print(string)

mqttc = paho.Client()
# Assign event callbacks
mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe

# Uncomment to enable debug messages
Esempio n. 8
0
from wiringx86 import GPIOEdison as GPIO
import requests

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
outpin = 3
analogpins = range(14, 17)
url_finger = "http://dev.studalt.ru/store.php?mode=r&id=finger"
url_sensor = "http://dev.studalt.ru/store.php?mode=w&id=sensor"

print 'Setting up all pins...'

# Set pin 14 to be used as an analog input GPIO pin.
for analogpin in analogpins:
    gpio.pinMode(analogpin, gpio.ANALOG_INPUT)

# Set pin 13 to be used as an output GPIO pin.
gpio.setPWMPeriod(outpin, 20000000)
gpio.pinMode(outpin, gpio.PWM)

#print 'Analog reading from pin %d now...' % analogpin
while (True):
    data = []
    level = 12
    gpio.analogWrite(outpin, level)
    for analogpin in analogpins:
        data.append(gpio.analogRead(analogpin))
    data = 'no'  # low, med, high
    if (data < 998):
        data = 'low'
Esempio n. 9
0
# Import the time module enable sleeps between turning the led on and off.
import time

# Import the GPIOEdison class from the wiringx86 module.
from wiringx86 import GPIOEdison as GPIO

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = 3
brightness = 0
fadeAmount = 5

# Set pin 3 to be used as a PWM pin.
print 'Setting up pin %d' % pin
gpio.pinMode(pin, gpio.PWM)

print 'Fading pin %d now...' % pin
try:
    while(True):
        # Write brightness to the pin. The value must be between 0 and 255.
        gpio.analogWrite(pin, brightness)

        # Increment or decrement the brightness.
        brightness = brightness + fadeAmount

        # If the brightness has reached its maximum or minimum value swap
        # fadeAmount sign so we can start fading the led on the other direction.
        if brightness == 0 or brightness == 255:
            fadeAmount = -fadeAmount
Esempio n. 10
0
#The Module can be downloaded from: https://github.com/emutex/wiring-x86
from wiringx86 import GPIOEdison as GPIO
#import pymongo
#from pymongo import MongoClient
import time
import urllib2

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = [1, 7, 8, 10, 11, 12, 13, 14, 16, 18]

# Set pins to be used as an output GPIO pin.
for i in pin:
    print 'Setting up pin %d' % i
    gpio.pinMode(i, gpio.OUTPUT)

####### MONGODB STUFF ########
#Connect to the database at mongolab.com
#client = MongoClient('mongodb://*****:*****@ds051640.mongolab.com:51640/thesis_prototype_1')
#client = MongoClient('mongodb://technoshaman.local:27017')
#client = MongoClient('mongodb://technoshaman.noip.me:4400')
#db = client.thesis_prototype_1
#connect to the collection
#collection = db.data_consume
###############################

counter = 0

try:
    while(True):
Esempio n. 11
0
# you are using a different board such as an Intel® Galileo Gen2, just change the
# import below. wiringx86 uses the same API for all the boards it supports.

# Import the GPIOEdison class from the wiringx86 module.
from wiringx86 import GPIOEdison as GPIO

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = 13
button = 2

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
Esempio n. 12
0
# Import the time module enable sleeps between turning the led on and off.
import time

# Import the GPIOEdison class from the wiringx86 module.
from wiringx86 import GPIOEdison as GPIO

# Create a new instance of the GPIOEdison class.
# 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.
Esempio n. 13
0
#!/usr/bin/python
# https://github.com/SavinaRoja/PyUserInput
import time
from wiringx86 import GPIOEdison as GPIO
gpio = GPIO(debug=False)
pinButtons = [2,3,4]
state = [0,0,0]
for i in pinButtons:
	gpio.pinMode(i, gpio.INPUT)
while True:
	for i in range(3):
		state[i] = gpio.digitalRead(pinButtons[i])
		if state[i] == 1:
                        print "Boton en pin " + str(pinButtons[i]) + " pulsado."
			time.sleep(3)
Esempio n. 14
0
# you are using a different board such as an Intel® Galileo Gen2, just change the
# import below. wiringx86 uses the same API for all the boards it supports.

# Import the GPIOEdison class from the wiringx86 module.
from wiringx86 import GPIOEdison as GPIO

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = 13
button = 2

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
Esempio n. 15
0
gpio = GPIO(debug=False)

u_id = "A2837C04-4AE1-441A-95D5-C25E6D9D1D10"

def reg():
	APPLICATION_ID = "TBhSWVtf7LUzCUxUlhF5wFfLKdquF4jEJjK1cVqQ"
	REST_API_KEY = "j3QxkFjL9zzOiSMrUqlQYFh5VZRKSrvWh3A7Ob3a"
	register(APPLICATION_ID, REST_API_KEY)


class UserTable(ParseObject):
	pass

reg()

gpio.pinMode(4, gpio.OUTPUT)
gpio.pinMode(5, gpio.OUTPUT)
gpio.pinMode(6, gpio.OUTPUT)
gpio.pinMode(7, gpio.OUTPUT)

def handler_left():
	gpio.digitalWrite(4, gpio.LOW)
	gpio.digitalWrite(5, gpio.LOW)
	gpio.digitalWrite(6, gpio.HIGH)
	gpio.digitalWrite(7, gpio.LOW)


def handler_straight():
	gpio.digitalWrite(4, gpio.HIGH)
	gpio.digitalWrite(5, gpio.LOW)
	gpio.digitalWrite(6, gpio.HIGH)
Esempio n. 16
0
# Import the time module enable sleeps between turning the led on and off.
import time

# Import the GPIOEdison class from the wiringx86 module.
from wiringx86 import GPIOEdison as GPIO

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=False)
pin = 13
state = gpio.HIGH

# Set pin 13 to be used as an output GPIO pin.
print 'Setting up pin %d' % pin
gpio.pinMode(pin, gpio.OUTPUT)

print 'Blinking pin %d now...' % pin
try:
    while (True):
        # 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:
Esempio n. 17
0
Hitting Ctrl-C stops motor.
"""

#!usr/bin/python

from wiringx86 import GPIOEdison as GPIO
import time

gpio = GPIO(debug=False)
pin = 9
pin2 = 13
fastness = 100
delta = 5

gpio.pinMode(pin, gpio.PWM)
gpio.pinMode(pin2, gpio.OUTPUT)
gpio.digitalWrite(pin2, gpio.HIGH)

try:
    while (True):
        gpio.analogWrite(pin, fastness)
        fastness = fastness + delta
        if fastness == 0 or fastness == 255:
            delta = -delta
        time.sleep(0.03)

except KeyboardInterrupt:
    gpio.analogWrite(pin, 0)
    gpio.cleanup()
Esempio n. 18
0
from wiringx86 import GPIOEdison as GPIO
import time
gpio = GPIO(debug=False)
time.sleep(2)
gpio.setPWMPeriod(3, 20000000)
gpio.pinMode(3, gpio.PWM)
gpio.pinMode(14, gpio.ANALOG_INPUT)
gpio.pinMode(15, gpio.ANALOG_INPUT)
gpio.pinMode(16, gpio.ANALOG_INPUT)
time.sleep(1)
while 1:
	gpio.analogWrite(3, 5)
	time.sleep(3)
	gpio.analogWrite(3, 9)
	time.sleep(2)
	print "14: " + str(gpio.analogRead(14))
	print "15: " + str(gpio.analogRead(15))
	time.sleep(1)
Esempio n. 19
0
from wiringx86 import GPIOEdison as GPIO
import time
gpio = GPIO(debug=False)
time.sleep(2)
gpio.setPWMPeriod(3, 20000000)
gpio.pinMode(3, gpio.PWM)
gpio.pinMode(14, gpio.ANALOG_INPUT)
gpio.pinMode(15, gpio.ANALOG_INPUT)
gpio.pinMode(16, gpio.ANALOG_INPUT)
time.sleep(1)
while 1:
    gpio.analogWrite(3, 5)
    time.sleep(3)
    gpio.analogWrite(3, 9)
    time.sleep(2)
    print "14: " + str(gpio.analogRead(14))
    print "15: " + str(gpio.analogRead(15))
    time.sleep(1)