Beispiel #1
0
def call_back1():
	print "From call_back1..."
	try:
		red.write(0)
		sleep(0.2)
		red.write(1)
		print adc.read()
	except IoTPy_APIError, e: # don't see the UPER board
		details = e.args[0]
		die(details)
Beispiel #2
0
from colorsys import hls_to_rgb
from time import sleep
from IoTPy.pyuper.ioboard import IoBoard
from IoTPy.pyuper.pwm import PWM
from IoTPy.pyuper.utils import IoTPy_APIError, die

try:
    u = IoBoard()
except IoTPy_APIError, e:  # seems can't establish connection with the UPER board
    details = e.args[0]
    die(details)

try:  # let's try to attach PWM object to non PWM pin
    a = u.get_pin(PWM, 23)
except IoTPy_APIError, e:  # got an exception, pin capabilities must be different from requested
    details = e.args[0]
    print details

with u.get_pin(PWM, 27) as R, u.get_pin(PWM, 28) as G, u.get_pin(PWM, 34) as B:
    R.width_us(0)
    R.width_us(2500)
    sleep(0.5)
    R.width_us(10000)
    sleep(0.5)
    R.write(0)
    sleep(0.5)
    R.write(0.25)
    sleep(0.5)
    R.write(0.9)
    print "Red LED duty is:", R.read()
    sleep(0.5)
Beispiel #3
0
from time import sleep

from IoTPy.pyuper.ioboard import IoBoard
from IoTPy.pyuper.i2c import I2C
from IoTPy.pyuper.utils import IoTPy_ThingError, IoTPy_APIError, IoTPy_IOError, errmsg, die
from IoTPy.things.srf08 import Srf08


try:
	with IoBoard() as u, Srf08(I2C(u)) as sensor:
		for i in range(10):
			try:
				print "distance: %3dcm" % sensor.distance(Srf08.CM),
				print "light:", sensor.light()
			except IoTPy_ThingError:
				die("Distance/Light sensor reading error, exiting")
			sleep(0.2)
		sensor.change_address(0x74)
		print "------------sensor address changed------------"
		for i in range(10):
			try:
				print "distance: %3dcm" % sensor.distance(Srf08.CM),
				print "light:", sensor.light()
			except IoTPy_ThingError:
				die("Distance/Light sensor reading error, exiting")
			sleep(0.2)
		sensor.change_address(0x70)
		print "------------sensor address changed------------"
		for i in range(10):
			try:
				print "distance: %3dcm" % sensor.distance(Srf08.CM),
Beispiel #4
0
from time import sleep
from IoTPy.pyuper.utils import IoTPy_ThingError, die
from IoTPy.pyuper.i2c import I2C
from IoTPy.pyuper.ioboard import IoBoard
from IoTPy.things.si7020 import Si7020
from IoTPy.things.am2321 import AM2321


with IoBoard() as u, AM2321(I2C(u)) as sensor, Si7020(I2C(u)) as other_sensor:
    print "UID", hex(sensor.read_uid())
    for i in range(10):
        try:
            print "----------------------------------"
            print "Si7020 t = %4.2fC RH= %4.2f%%" % (other_sensor.temperature(), other_sensor.humidity())
            sleep(0.5)
            sensor.read()
            print "AM2321 t = %4.2fC RH= %4.2f%%" % (sensor.temperature, sensor.humidity)
        except IoTPy_ThingError:
            pass
            die("Temperature/humidity sensor reading error, exiting.")
        sleep(0.5)
Beispiel #5
0
# Uros PETREVSKI <*****@*****.**>
# Drasko DRASKOVIC <*****@*****.**>
#
###
"""
Simple ADC value reading example with IoTPy.
"""
from time import sleep
from IoTPy.pyuper.ioboard import IoBoard
from IoTPy.pyuper.adc import ADC
from IoTPy.pyuper.utils import IoTPy_APIError, die

try:
    u = IoBoard()
except IoTPy_APIError, e:  # seems can't establish connection with the board
    details = e.args[0]
    die(details)

try:  # let's try to attach ADC object to non ADC pin
    a = u.get_pin(ADC, 27)
except IoTPy_APIError, e:  # got an exception, pin capabilities must be different from requested
    details = e.args[0]
    print details

with u.get_pin(ADC, 24) as adc_pin:
    for i in range(10):
        val = adc_pin.read()
        print "RAW ADC value:", val,
        voltage = 5.0 / 1024 * val
        print "| Voltage:", voltage, "V"
        sleep(0.1)
Beispiel #6
0
    timeout=0.1
)
"""
while True:
    try:

        port_to_try = serial.Serial(
            port='/dev/tty.usbmodem14131',
            baudrate=230400, #virtual com port on USB is always max speed
            parity=serial.PARITY_ODD,
            stopbits=serial.STOPBITS_ONE,
            bytesize=serial.EIGHTBITS,
            timeout=0.1
        )

        port_to_try.write('GetDeviceInfo()')
        uper_response = port_to_try.read()    #read one, blocking

        n = port_to_try.inWaiting()        #look if there is moreresp = port_to_try.read(33)
        if n:  #print "%r" % resp
            #pass
            uper_response = uper_response + port_to_try.read(n)  #
        i += 1
        if not (i % 10):
            print i, n, "%r" % uper_response
        port_to_try.flush()
        port_to_try.close()
        sleep(0.1)
    except:
        die("PYKSHT!")
Beispiel #7
0
          585, 586, 588, 589, 591, 593, 594, 596, 598, 599, 601, 603, 604, 606, 608, 609, 611, 613, 614,
          616, 618, 620, 621, 623, 625, 627, 628, 630, 632, 634, 636, 638, 639, 641, 643, 645, 647, 649,
          651, 653, 654, 656, 658, 660, 662, 664, 666, 668, 670, 672, 674, 676, 678, 680, 683, 685, 687,
          689, 691, 693, 695, 697, 700, 702, 704, 706, 708, 711, 713, 715, 718, 720, 722, 725, 727, 729,
          732, 734, 737, 739, 741, 744, 746, 749, 752, 754, 757, 759, 762, 764, 767, 770, 773, 775, 778,
          781, 784, 786, 789, 792, 795, 798, 801, 804, 807, 810, 813, 816, 819, 822, 825, 829, 832, 835,
          838, 842, 845, 848, 852, 855, 859, 862, 866, 869, 873, 877, 881, 884, 888, 892, 896, 900, 904,
          908, 912, 916, 920, 925, 929, 933, 938, 942, 947, 952, 956, 961, 966, 971, 976, 981, 986, 991,
          997, 1002, 1007, 1013, 1019, 1024, 1030, 1036, 1042, 1049, 1055, 1061, 1068, 1075, 1082, 1088,
          1096, 1103, 1110, 1118, 1126, 1134, 1142, 1150, 1159, 1168, 1177, 1186, 1196, 1206, 1216, 1226,
          1237, 1248, 1260, 1272, 1284, 1297, 1310, 1324, 1338, 1353, 1369, 1385, 1402, 1420, 1439, 1459,
          1480, 1502 ]


pin = 23

try:
    with IoBoard() as u, u.get_pin(ADC, pin) as thermistor_pin:
        for i in range(100):
            adc_val = thermistor_pin.read()
            temp = adc_to_temperature[adc_val - 238]
            print adc_val, temp/20.0, "degC"
            sleep(0.5)

except (IoTPy_IOError, IoTPy_APIError), e: # don't see the UPER
    details = e.args[0]
    die(details)
except KeyboardInterrupt:
    die("CTRL/C pressed, exiting.")

Beispiel #8
0
die_on_error = False # if True, we will exit on sensor read error

try:
    with IoBoard() as u, I2C(u) as myi2c, Si7020(myi2c) as sensor1, Srf08(myi2c) as sensor2:
        for i in xrange(600):
            print"-----------------------------------------------",i
            try:
                temp = "t = %4.2fC " % sensor1.temperature()
                rh = "RH= %4.2f%%" % sensor1.humidity()
                print temp, rh
                mqttc.publish("8dev", temp + rh)

            except IoTPy_ThingError:
                if die_on_error:
                    die("Temperature/Humidity sensor reading error, exiting.")
                errmsg("Temperature/Humidity sensor reading error.")

            try:
                print "distance: %3dcm" % sensor2.distance(),
                print "light:", sensor2.light()
            except IoTPy_ThingError:
                if die_on_error:
                    die("Distance/Light sensor reading error, exiting")
                errmsg("Distance/Light sensor reading error.")
            sleep(1)
except (IoTPy_IOError, IoTPy_APIError), e: # don't see the I2C buss or UPER board
    details = e.args[0]
    die(details)
except KeyboardInterrupt:
    errmsg("CTRL/C pressed, exiting.")
Beispiel #9
0
from itertools import cycle
from time import sleep

from IoTPy.pyuper.ioboard import IoBoard
from IoTPy.pyuper.gpio import GPIO
from IoTPy.pyuper.utils import IoTPy_APIError, die

try:
    u = IoBoard()
except IoTPy_APIError, e: # seems can't establish connection with the UPER board
    details = e.args[0]
    die(details)

try:  # set GPIO on ground pin
    a = u.get_pin(GPIO, 20)
except IoTPy_APIError, e:
    details = e.args[0]
    print details

with u.get_pin(GPIO, 27) as r, u.get_pin(GPIO, 28) as g, u.get_pin(GPIO, 34) as b:
    b.mode(GPIO.PULL_DOWN)
    print b.read()
    b.mode(GPIO.PULL_UP)
    print b.read()
    try:
        for i in cycle([0,1]):
            r.write(i)
            g.write(i)
            b.write(i)
            sleep(0.5)
    except KeyboardInterrupt: