Beispiel #1
0
def readadc(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
    r = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)

    led_status = "Desligado"

    if adcout > sensibilidade:

        gpio.digital_write(LED, GPIO.HIGH)
        led_status = "Ligado"

    else:
        gpio.digital_write(LED, GPIO.LOW)
        led_status = "Apagado"

    print(adcout)
    print("Status do LED:%s" % led_status)

    return r
Beispiel #2
0
def readPotenciometro(gpio):

    r = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(POTENCIOMETRO, GPIO.HIGH)  #liga o potenciometro
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    print("Valor do Pot.:%d" % adcout)
    return adcout
Beispiel #3
0
def ligarele():

    gpio.digital_write(RELE, GPIO.HIGH)

    #dweet.dweet_by_name(name="iplug_sabrina_q3", data={"rele":1})
    #resposta = dweet.latest_dweet(name="iplug_sabrina_q3")
    #print resposta['with'][0]['content']['button']

    return ligarele()
Beispiel #4
0
def readLumi(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.002)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
    r = spi.xfer2([0x01, 0x80, 0x00])
    gpio.digital_write(GPIO_CS, GPIO.HIGH)

    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    if (adcout < 200):
        gpio.digital_write(LED, GPIO.HIGH)
        print("Luz Ambiente Acesa")
    else:
        gpio.digital_write(LED, GPIO.LOW)
        print("Luz Ambiente Apagada")
    return adcout
Beispiel #5
0
def Man_Des():

    #gpio.digital_write(LED, GPIO.LOW)
    gpio.digital_write(RELE, GPIO.LOW)
    alarme = 0
    dweet.dweet_by_name(name="bmfmata",
                        data={
                            "alarme": alarme,
                            "temp": vtemp,
                            "lumi": vlumi,
                            "bam_nuvem": bam_nuvem,
                            "bebe": alarme_bebe,
                            "reset": reset_nuvem,
                            "estado": estado_am,
                            "liga_des": ld_nuvem,
                        })
    print "Ar Condicionado Desligado"
    print("Temperatura: %2.1f" % vtemp)
    print("Luminosidade: %2.1f \n" % vlumi)
Beispiel #6
0
def Aut_Liga():

    #gpio.digital_write(LED, GPIO.HIGH)
    gpio.digital_write(RELE, GPIO.HIGH)
    alarme = 1
    dweet.dweet_by_name(name="bmfmata",
                        data={
                            "alarme": alarme,
                            "temp": vtemp,
                            "lumi": vlumi,
                            "bam_nuvem": bam_nuvem,
                            "bebe": alarme_bebe,
                            "reset": reset_nuvem,
                            "estado": estado_am,
                            "liga_des": ld_nuvem,
                        })
    print "Sistema Automatico! \n"
    print "Ar Condicionado Ligado"
    print("Temperatura: %2.1f" % vtemp)
    print("Luminosidade: %2.1f \n" % vlumi)
Beispiel #7
0
def readadc(gpio):
    gpio.digital_write(GPIO_A, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_A, GPIO.LOW)
    r = spi.xfer2([0x01, 0x80, 0x00])
    gpio.digital_write(GPIO_A, GPIO.HIGH)
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    return adcout
Beispiel #8
0
def lerpot(gpio):

	gpio.digital_write(GPIO_CS, GPIO.HIGH)
	time.sleep(0.0002)
	gpio.digital_write(GPIO_CS, GPIO.LOW)
	r = spi.xfer2([0x01, 0xA0, 0x00])
	gpio.digital_write(GPIO_CS, GPIO.HIGH)
	ptvalor = (r[1] << 8) & 0b1100000000
	ptvalor = ptvalor | (r[2] & 0xff)		
	print ("Valor do Potenciometro.:%d" %ptvalor)
Beispiel #9
0
def readtemp(gpio):

	gpio.digital_write(GPIO_CS, GPIO.HIGH)
	time.sleep(0.0002)
	gpio.digital_write(GPIO_CS, GPIO.LOW)
	r = spi.xfer2([0x01, 0xA0, 0x00])
	gpio.digital_write(GPIO_CS, GPIO.HIGH)
	adcout = (r[1] << 8) & 0b1100000000
	adcout = adcout | (r[2] & 0xff)		
	print ("Valor do Pot.:%d" %adcout)
	return adcout
Beispiel #10
0
def readTemp(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
    r = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    adc_temp = (((adcout * 5.0) / 1023) - 0.5) * 100
    return adc_temp
Beispiel #11
0
def readHum(gpio):

    gpio.digital_write(HUMIDADE, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(HUMIDADE, GPIO.LOW)
    r = spi.xfer2([0x01, (8 + 1) << 4, 0x00])  #ADC1
    gpio.digital_write(HUMIDADE, GPIO.HIGH)

    adcout = (r[1] << 8) & 0b1100000000
    adcout3 = adcout | (r[2] & 0xff)

    return adcout3
Beispiel #12
0
def luminosidade(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.5)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
    r2 = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(GPIO_CS, GPIO.HIGH)

    adcout = (r2[1] << 8) & 0b1100000000
    adcout = adcout | (r2[2] & 0xff)

    return adcout
Beispiel #13
0
def readVol(gpio):

    gpio.digital_write(VOLUME, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(VOLUME, GPIO.LOW)
    r = spi.xfer2([0x01, (8 + 3) << 4, 0x00])  #ADC3
    gpio.digital_write(VOLUME, GPIO.HIGH)

    adcout = (r[1] << 8) & 0b1100000000
    adcout3 = adcout | (r[2] & 0xff)

    return adcout3
Beispiel #14
0
def readhumidade(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
    r = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    adcout = (adcout / 1023) * 100
    print("Valor da Humidade.:%d %%" % adcout)
    return adcout
Beispiel #15
0
def temperatura(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
    r1 = spi.xfer2([0x01, 0x80, 0x00])
    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    adcout = (r1[1] << 8) & 0b1100000000
    adcout = adcout | (r1[2] & 0xff)

    adc_temp = (adcout * 5.0 / 1023 - 0.5) * 100

    return adc_temp
Beispiel #16
0
def readLumi(gpio):

    gpio.digital_write(SOL, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(SOL, GPIO.LOW)
    r = spi.xfer2([0x01, (8 + 2) << 4, 0x00])  #ADC2
    gpio.digital_write(SOL, GPIO.HIGH)

    adcout = (r[1] << 8) & 0b1100000000
    adcout2 = adcout | (r[2] & 0xff)

    #print("Luminosidade: %d" %adcout)
    return adcout2
Beispiel #17
0
def readTemp(gpio):

    gpio.digital_write(TEMPERATURA, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(TEMPERATURA, GPIO.LOW)
    r = spi.xfer2([0x01, (8 + 0) << 4, 0x00])  #ADC0
    gpio.digital_write(TEMPERATURA, GPIO.HIGH)

    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    adc_temp = (adcout * 5.0 / 1023 - 0.5) * 100

    return adc_temp
Beispiel #18
0
def readadc(gpio):

    gpio.digital_write(GPIO_A, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_A, GPIO.LOW)
    r = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(GPIO_A, GPIO.HIGH)
    print(r)
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    adc_temp = (adcout * 5.0 / 1023 - 0.5) * 100
    print(adc_temp)
    return r
Beispiel #19
0
def readVol(gpio):

    gpio.digital_write(VOLUME, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(VOLUME, GPIO.LOW)
    r = spi.xfer2([0x01, (8 + 3) << 4, 0x00])
    gpio.digital_write(VOLUME, GPIO.HIGH)

    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    adc_temp = (adcout * 5.0 / 1023 - 0.5) * 100

    #print("Temperatura:%2.1f " %adc_temp)
    return adc_temp
Beispiel #20
0
def readpot(gpio):
    gpio.digital_write(GPIO_A, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_A, GPIO.LOW)
    r = spi.xfer2([0x01, 0x80, 0x00])
    gpio.digital_write(GPIO_A, GPIO.HIGH)
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    return adcout

    if adcout > 500.0:
	with GPIO(pins) as gpio:
	  blink(gpio)
    return adcout
Beispiel #21
0
def desligarele():

    gpio.digital_write(RELE, GPIO.LOW)
Beispiel #22
0
spi.max_speed_hz = 10000
spi.mode = 0b00
spi.bits_per_word = 8

def readtemp(gpio):

	gpio.digital_write(GPIO_CS, GPIO.HIGH)
	time.sleep(0.0002)
	gpio.digital_write(GPIO_CS, GPIO.LOW)
	r = spi.xfer2([0x01, 0xA0, 0x00])
	gpio.digital_write(GPIO_CS, GPIO.HIGH)
	adcout = (r[1] << 8) & 0b1100000000
	adcout = adcout | (r[2] & 0xff)		
	print ("Valor do Pot.:%d" %adcout)
	return adcout
	
while True:
	with GPIO(pins) as gpio:
		value = readtemp(gpio)
		if value > 500:
			gpio.digital_write(RELE, GPIO.HIGH)
		else:
			gpio.digital_write(RELE, GPIO.LOW)		

		time.sleep(0.5)




	
Beispiel #23
0
def desliga():

    gpio.digital_write(RELE, GPIO.LOW)
    print "Sistema Desligado"
Beispiel #24
0
def liga():

    gpio.digital_write(RELE, GPIO.HIGH)
    print "Sistema Ligado"
Beispiel #25
0
def ligaled():

    gpio.digital_write(LED, GPIO.HIGH)
Beispiel #26
0
def writeDigital(gpio, digital):
    write = digital
    gpio.digital_write(ILUMINACAO, write[0])
    gpio.digital_write(IRRIGACAO, write[1])

    return digital
Beispiel #27
0
)

spi = spidev.SpiDev()  #biblioteca SPI para acessar os pinos ADC1 e ADC2
spi.open(0, 0)  #acessando ADC2
spi.max_speed_hz = 10000
spi.mode = 0b00
spi.bits_per_word = 8


def readPotenciometro(gpio):

    r = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(POTENCIOMETRO, GPIO.HIGH)  #liga o potenciometro
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    print("Valor do Pot.:%d" % adcout)
    return adcout


while True:
    with GPIO(pins) as gpio:
        value = readPotenciometro(
            gpio)  # le o valor do potenciometro e coloca na variavel
        if value > 500:
            gpio.digital_write(
                LED, GPIO.HIGH)  # liga o led para valores maiores que 500
        else:
            gpio.digital_write(LED, GPIO.LOW)  # desliga o LED

        time.sleep(0.5)  #tempo de espera para proximo loop
Beispiel #28
0
import spidev
import time
from libsoc import gpio

from gpio_96boards import GPIO

TOQUE = GPIO.gpio_id('GPIO_A')
RELAY = GPIO.gpio_id('GPIO_C')

pins = ((TOQUE, 'in'), (RELAY, 'out'),)

with GPIO(pins) as gpio:
	while True:

		button_value = gpio.digital_read(TOQUE)

		if button_value == 1:
			gpio.digital_write(RELAY, 1)
		else:
			gpio.digital_write(RELAY, 0)

		print("Status do Rele: %d" %button_value)

		time.sleep(1)
Beispiel #29
0
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 10000
spi.mode = 0b00
spi.bits_per_word = 8


def readpotenc(gpio):

    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    time.sleep(0.0002)
    gpio.digital_write(GPIO_CS, GPIO.LOW)
    r = spi.xfer2([0x01, 0xA0, 0x00])
    gpio.digital_write(GPIO_CS, GPIO.HIGH)
    adcout = (r[1] << 8) & 0b1100000000
    adcout = adcout | (r[2] & 0xff)
    print("Valor do Potenciometro.:%d" % adcout)
    return adcout


while True:
    with GPIO(pins) as gpio:
        value = readpotenc(gpio)
        if value > 500:
            gpio.digital_write(LED, GPIO.HIGH)
        else:
            gpio.digital_write(LED, GPIO.LOW)

        time.sleep(0.5)
Beispiel #30
0
def desligaled():

    gpio.digital_write(LED, GPIO.LOW)