Exemplo n.º 1
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)
Exemplo n.º 2
0
Arquivo: adc.py Projeto: Capt-Cpt/weio
# 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)
Exemplo n.º 3
0
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

PINb = u.get_pin(GPIO, 1)
PINb.mode(GPIO.PULL_UP)
PINa = u.get_pin(GPIO, 2)
PINa.mode(GPIO.PULL_UP)

i2 = u.get_pin(Interrupt, 1)
i2.attach(Interrupt.EDGE_RISE, call_back2)



print "program started"

while True :
	pass
Exemplo n.º 4
0
		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)
i1.detach()

i1 = u.get_pin(Interrupt, 40)
i1.attach(Interrupt.EDGE_RISE, call_back1)
Exemplo n.º 5
0
Arquivo: adc.py Projeto: seipekm/weio
# 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)
Exemplo n.º 6
0
###
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)
    ###
    #sleep(1)
    #myservo.writeMilliseconds(1.5)
    #sleep(1)
    #val = myservo.readMilliseconds()
    #print "duty in ms =", val
Exemplo n.º 7
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:
Exemplo n.º 8
0
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