예제 #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)
예제 #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()
예제 #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()
예제 #4
0
from parse_rest.connection import register, ParseBatcher
# Alias the Object type to make clear is not a normal python Object
from parse_rest.datatypes import Object as ParseObject
from parse_rest.user import User
from wiringx86 import GPIOEdison as GPIO
import sys

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():
예제 #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)
예제 #6
0
# This example is inspired on Arduino Analog Input example.
# http://arduino.cc/en/Tutorial/AnalogInput
#
# This example will work "out of the box" on an Intel® Edison board. If
# 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 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
예제 #7
0
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
예제 #8
0
# This example is inspired on Arduino Analog Input example.
# http://arduino.cc/en/Tutorial/AnalogInput
#
# This example will work "out of the box" on an Intel® Edison board. If
# 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 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
예제 #9
0
# This example is inspired on Arduino Fade example.
# http://arduino.cc/en/Tutorial/Fade
#
# This example will work "out of the box" on an Intel® Edison board. If
# 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 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.
예제 #10
0
 GPIO 49     - j20 Pin 6     -      8
 GPIO 42     - j20 Pin 9     -      12
 GPIO 41     - j20 Pin 10    -      10
"""

# Import the GPIOEdison class from the wiringx86 module.
#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
예제 #11
0
#
# See license in LICENSE.txt file.
#
# This example is inspired on Arduino Button example.
# http://arduino.cc/en/Tutorial/Button
#
# This example will work "out of the box" on an Intel® Edison board. If
# 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
예제 #12
0
# This example is inspired on Arduino Blink example.
# http://arduino.cc/en/Tutorial/Blink
#
# This example will work "out of the box" on an Intel® Edison board. If
# 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 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)
예제 #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)
예제 #14
0
#
# See license in LICENSE.txt file.
#
# This example is inspired on Arduino Button example.
# http://arduino.cc/en/Tutorial/Button
#
# This example will work "out of the box" on an Intel® Edison board. If
# 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
예제 #15
0
# SOURCE: https://github.com/emutex/wiring-x86/blob/master/examples/analog_input.py
# 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
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:
예제 #16
0
from parse_rest.connection import register, ParseBatcher
# Alias the Object type to make clear is not a normal python Object
from parse_rest.datatypes import Object as ParseObject
from parse_rest.user import User
from wiringx86 import GPIOEdison as GPIO
import sys


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)
예제 #17
0
# This example is inspired on Arduino Blink example.
# http://arduino.cc/en/Tutorial/Blink
#
# This example will work "out of the box" on an Intel® Edison board. If
# 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 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
예제 #18
0
"""
Using Wiring-x86 to power motor A which turns the left wheel forward.

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)
예제 #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)
예제 #20
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)