Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
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)
Beispiel #4
0
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.
        time.sleep(value / 1023.0)

        # Turn OFF pin 13
        gpio.digitalWrite(pin, gpio.LOW)

        # Sleep for a while depending on the voltage we just read. The higher
        # the voltage the more we sleep.
        time.sleep(value / 1023.0)
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
#mqttc.on_log = on_log

# Parse CLOUDMQTT_URL (or fallback to localhost)
url_str = os.environ.get('CLOUDMQTT_URL', 'mqtt://*****:*****@geeknesia.com:1883')
url = urlparse.urlparse(url_str)

# Connect
mqttc.username_pw_set(url.username, url.password)
mqttc.connect(url.hostname, url.port)

# Start subscribe, with QoS level 0
mqttc.subscribe("hello/world", 0)

# Publish a message
mqttc.publish("iot/live", "DEVICE_ID")

# Continue the network loop, exit when an error occurs
rc = 0
while rc == 0:
    rc = mqttc.loop()
    value = gpio.analogRead(analogpin)
    mqttc.publish("iot/data", '{"code":"USERNAME:PASSWORD","attributes":{"LDR":"'+value+'"}}')
    time.sleep(60)
print("rc: " + str(rc))
Beispiel #6
0
# 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'
        if (data < 990):
            data = 'med'
            if (data < 970):
                data = 'high'
    print "Writing to dev.studalt.ru..."
    l = requests.get(url_sensor + "&data=" + str(data))
    print "Reading gesture..."
    l = requests.get(url_finger)
    if l.status_code == 200:
        print "DEBUG: " + l.text
        if l.text.lower() == 'fist':
            level = 14
Beispiel #7
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)