def __init__(self): # set all pins to -1 (nothing selected), this is just information no real action on pins will be performed self.declaredPins = [] for a in range(32): self.declaredPins.append(-1) self.pwmPrecision = 255 numberOfTries = 1000 cnt = 0 closed = True # This array will keep interrupt object on corresponding pin number self.interrupts = [] for i in range(32): self.interrupts.append(None) while closed: try: self.u = IoBoard() print "opened port" closed = False weioRunnerGlobals.WEIO_SERIAL_LINKED = True except IoTPy_APIError, e: # seems can't establish connection with the UPER board #details = e.args[0] closed = True weioRunnerGlobals.WEIO_SERIAL_LINKED = False cnt = cnt + 1 if (cnt > numberOfTries): closed = False print "uper not present"
def __init__(self): self.declaredPins = [] self.pwmPrecision = 255 numberOfTries = 1000 cnt = 0 closed = True while closed: try: self.u = IoBoard() print "opened port" closed = False weioRunnerGlobals.WEIO_SERIAL_LINKED = True except IoTPy_APIError, e: # seems can't establish connection with the UPER board #details = e.args[0] closed = True weioRunnerGlobals.WEIO_SERIAL_LINKED = False cnt = cnt + 1 if (cnt > numberOfTries): closed = False print "uper not present"
# Authors : # 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
def __init__(self, serial_port=None): IoBoard.__init__(self, UPER1_PINOUT, serial_port)
def call_back2(): print "From call_back2..." try: green.write(0) sleep(0.2) green.write(1) print adc.read() except IoTPy_APIError, e: # don't see the UPER board details = e.args[0] die(details) try: u = IoBoard() except IoTPy_APIError, e: # seems can't establish connection with the UPER board details = e.args[0] die(details) red = u.get_pin(GPIO, 27) green = u.get_pin(GPIO, 28) adc = u.get_pin(ADC, 23) with u.get_pin(Interrupt, 40) as i1: i1.attach(Interrupt.EDGE_FALL, call_back1) print "Attached, detaching now on Interrupt object cleanup..." i1 = u.get_pin(Interrupt, 40) i1.attach(Interrupt.EDGE_CHANGE, call_back1)
def __init__(self, serial_port=None): IoBoard.__init__(self, WEIO_PINOUT, serial_port)
# # Authors : # 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
from IoTPy.pyuper.ioboard import IoBoard from time import sleep i = 0 while True: u = IoBoard() #info = u.get_device_info() i += 1 if not (i % 1): print i u.stop() #sleep(0.3)while True: """ with IoBoard() as u: info = u.get_device_info() i += 1 if not (i % 10): print i #sleep(0.3) with IoBoard() as u: while True: info = u.get_device_info() i += 1 if not (i % 10): print i #sleep(0.1) """
from IoTPy.pyuper.ioboard import IoBoard from IoTPy.pyuper.spi import SPI 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) with u.get_pin(GPIO, 18) as sdn, u.get_pin(GPIO, 1) as csn, SPI(u,1) as spi_port: sdn.mode(GPIO.OUTPUT) sdn.write(0) csn.mode(GPIO.OUTPUT) csn.write(0) result = spi_port.transaction('\x01\xF0\x00\x00', 1) csn.write(1) print "rezult len:", len(result) print "%r" % result print result
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:
from IoTPy.pyuper.ioboard import IoBoard u = IoBoard() u.reset()
from IoTPy.pyuper.ioboard import IoBoard from IoTPy.pyuper.i2c import I2C from IoTPy.pyuper.utils import IoTPy_IOError, IoTPy_ThingError, 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) interface = I2C(u) for address in xrange(0, 128): print address try: interface.transaction(address, '', 0) print "geras:", address except IoTPy_IOError, IoTPy_APIError: pass
from time import time from datetime import datetime from IoTPy.pyuper.ioboard import IoBoard from IoTPy.pyuper.interrupt import Interrupt from IoTPy.pyuper.utils import IoTPy_APIError, die, errmsg from IoTPy.pyuper.gpio import GPIO a = 0 previous_time = 0 try: u = IoBoard() except IoTPy_APIError, e: details = e.args[0] die(details) def call_back2(): global a global previous_time C=PINa.read() time_now = time() * 1000 #print time_now - previous_time if time_now - previous_time > 200: if C: a += 1 else: a -= 1 print a,"C=",C #else: #print "skipping" previous_time = time_now
### ### # # How to use servomotor.py # ### from IoTPy.pyuper.ioboard import IoBoard from IoTPy.pyuper.adc import ADC from IoTPy.pyuper.utils import IoTPy_APIError, die from time import sleep from IoTPy.things.servomotor import Servo try: u = IoBoard() except IoTPy_APIError, e: # seems can't establish connection with the board details = e.args[0] die(details) adc_pin=u.get_pin(ADC, 27) myservo = Servo(u,22) while True: val = adc_pin.read() degr = (val-0)*(180-0)/(1024-0)+0 myservo.write(degr) degr = myservo.read() print "servo degree=", degr sleep(0.1)
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)