def __init__(self, gpio_in, devices=1, dinpin='GPIO-E', cspin='GPIO-D', clkpin='GPIO-C', intensity=5, scanlimit=7): """Constructor""" global gpio gpio = gpio_in global DIN global CS global CLK DIN = GPIO.gpio_id(dinpin) CS = GPIO.gpio_id(cspin) CLK = GPIO.gpio_id(clkpin) global numOfDevices numOfDevices = devices for i in range(0,numOfDevices): self.shutDown(False,i+1) for i in range(0,numOfDevices): self.setScanLimit(scanlimit,i+1) for i in range(0,numOfDevices): self.setIntensity(intensity,i+1) self.clearDisplays() global Characters Characters = AL()
import spidev import time from libsoc import gpio from gpio_96boards import GPIO from dweet import Dweet VOLUME = GPIO.gpio_id('GPIO_CS') #SENSOR VOLUME DAGUA TEMPERATURA = GPIO.gpio_id('GPIO_CS') #SENSOR DE TEMPERATURA SOL = GPIO.gpio_id('GPIO_CS') #SENSOR DE LUMINOSIDADE HUMIDADE = GPIO.gpio_id('GPIO_CS') #SENSOR DE HUMIDADE ILUMINACAO = GPIO.gpio_id('GPIO_C') #LED IRRIGACAO = GPIO.gpio_id('GPIO_B') #RELE - LIGADO A VALVULA SOLENOIDE pins = ( (VOLUME, 'out'), (TEMPERATURA, 'out'), (SOL, 'out'), (IRRIGACAO, 'out'), (ILUMINACAO, 'out'), (HUMIDADE, 'out'), ) spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 10000 spi.mode = 0b00 spi.bits_per_word = 8 dweet = Dweet()
msg['To'] = ", ".join(recipients) msg['Subject'] = subject msg.attach(MIMEText(message, 'plain')) image = MIMEImage(img_data, name='snapshot.png') msg.attach(image) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(fromaddr, pwd) text = msg.as_string() server.sendmail(fromaddr, recipients, text) server.quit() except socket.gaierror: print("Network down, can't send email...") pin = GPIO.gpio_id('GPIO-B') pins = ( (pin, 'in'), ) cam = SimpleCV.Camera() last_detection = True detection_enabled = True IMAGE_PATH = "/home/linaro/motion_detection.png" with GPIO(pins) as gpio: while True: # If motion detection enabled AND pin is high, take picture and send to alert recipients with open('settings.json', 'r') as settingsfile: data = json.load(settingsfile) if not data['motion_detection']: if detection_enabled:
#!/usr/bin/env python #Declaracao e importacao das Bibliotecas from dweet import Dweet import spidev import time from libsoc import gpio from gpio_96boards import GPIO #Declaracao e definição das Entradas e Saidas GPIO_CS = GPIO.gpio_id('GPIO_CS') RELE = GPIO.gpio_id('GPIO_A') BOTAO = GPIO.gpio_id('GPIO_C') pins = ((GPIO_CS, 'out'), (RELE, 'out'), (BOTAO, 'in')) #Definição de parâmetros para portas analógicas spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 10000 spi.mode = 0b00 spi.bits_per_word = 8 #Declaração de uma variável Dweet para interface com sistema # de nuvem dweet = Dweet() #Declaração de variáveis alarme_bebe = 0 reset_nuvem = 0 bam_nuvem = 0
from bluetooth import * import sys import time from gpio_96boards import GPIO GPIO_A = GPIO.gpio_id('GPIO_A') pins = ((GPIO_A, 'out'), ) def blink(gpio): gpio.digital_write(GPIO_A, GPIO.HIGH) time.sleep(1) gpio.digital_write(GPIO_A, GPIO.LOW) if sys.version < '3': input = raw_input addr = None if len(sys.argv) < 2: print("no device specified. Searching all nearby bluetooth devices for") print("the SampleServer service") else: addr = sys.argv[1] print("Searching for SampleServer on %s" % addr) # search for the SampleServer service uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee" service_matches = find_service(uuid=uuid, address=addr) if len(service_matches) == 0:
import spidev import time from libsoc import gpio from gpio_96boards import GPIO GPIO_CS = GPIO.gpio_id('GPIO_CS') LED = GPIO.gpio_id('GPIO_A') pins = ( (GPIO_CS, 'out'), (LED, 'out'), ) 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)
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)
#GPIO Library=================================== import time from gpio_96boards import GPIO GPA = GPIO.gpio_id('GPIO_A') GPB = GPIO.gpio_id('GPIO_B') GPC = GPIO.gpio_id('GPIO_C') GPD = GPIO.gpio_id('GPIO_D') def gpio_h(gpid): pins = ((gpid, 'out'), ) with GPIO(pins) as gpio: gpio.digital_write(gpid, GPIO.HIGH) def gpio_l(gpid): pins = ((gpid, 'out'), ) with GPIO(pins) as gpio: gpio.digital_write(gpid, GPIO.LOW) def gpio_r(gpid): pins = ((gpid, 'in'), ) with GPIO(pins) as gpio: data = gpio.digital_read(gpid) return data #gpio_h(GPC) #time.sleep(1) #gpio_l(GPC)
import time from gpio_96boards import GPIO PortaLed = GPIO.gpio_id('GPIO_E') Btn = GPIO.gpio_id('GPIO_A') pins = ((PortaLed, 'out'),(Btn, 'in'),) def readDigital(gpio): digital = [0,0] digital[0] = gpio.digital_read(PortaLed) digital[1] = gpio.digital_read(Btn) return digital def piscaled(gpio): gpio.digital_write(PortaLed, GPIO.HIGH) print('Led Turn Off') time.sleep(1) gpio.digital_write(PortaLed, GPIO.LOW) print('Led Turn On') time.sleep(1) while True: with GPIO(pins) as gpio: digital = readDigital(gpio) if digital[1]==1: print('Pisca led acionado') piscaled(gpio) time.sleep(1)
from dweet import Dweet import spidev import time from libsoc import gpio from gpio_96boards import GPIO GPIO_CS = GPIO.gpio_id('GPIO_CS') RELE = GPIO.gpio_id('GPIO_A') LED = GPIO.gpio_id('GPIO_C') TOQUE = GPIO.gpio_id('GPIO_E') pins = ( (GPIO_CS, 'out'), (LED, 'out'), (RELE, 'out'), (TOQUE, 'in'), ) sensibilidade = 400 temperatura = 19 dwligatoque = 0 spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 10000 spi.mode = 0b00 spi.bits_per_word = 8 dweet = Dweet()
import spidev import time from libsoc import gpio from gpio_96boards import GPIO GPIO_A = GPIO.gpio_id('GPIO_B') pins = ((GPIO_A, 'out'), ) spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 10000 spi.mode = 0b00 spi.bits_per_word = 8 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 while True: with GPIO(pins) as gpio: value = readadc(gpio) print("value = %d" % value) print(" ---------------------- ")
#!/usr/bin/python import time from gpio_96boards import GPIO GPIO_A = GPIO.gpio_id('GPIO_A') pins = ((GPIO_A, 'out'), ) GPIO_B = GPIO.gpio_id('GPIO_B') pins = ((GPIO_B, 'in'), ) def blink(gpio): gpio.digital_write(GPIO_A, GPIO.HIGH) time.sleep(1) gpio.digital_write(GPIO_A, GPIO.LOW) time.sleep(1) alto = gpio.digital_read(GPIO_B) if __name__ == '__main__': import argparse parser = argparse.ArgumentParser( description='Blink LED on GPIO A (pin 23)') args = parser.parse_args() with GPIO(pins) as gpio: blink(gpio)
import time import signal import json import threading import os from gpio_96boards import GPIO #serial communication settings data = json.load(open('config.json')) usb_setting = data['usb_setting'] se = serial.Serial(usb_setting, 115200) sensor_count = int(data['sensor_count']) print(sensor_count) #GPIO settings GPIO_A = GPIO.gpio_id('GPIO_A') GPIO_B = GPIO.gpio_id('GPIO_B') GPIO_C = GPIO.gpio_id('GPIO_C') GPIO_D = GPIO.gpio_id('GPIO_D') GPIO_E = GPIO.gpio_id('GPIO_E') GPIO_H = GPIO.gpio_id('GPIO_H') GPIO_K = GPIO.gpio_id('GPIO_K') pins_a = ((GPIO_A, 'in'), ) pins_b = ((GPIO_B, 'in'), ) pins_c = ((GPIO_C, 'in'), ) pins_d = ((GPIO_D, 'in'), ) pins_e = ((GPIO_E, 'in'), ) pins_h = ((GPIO_H, 'in'), ) pins_k = ((GPIO_K, 'in'), )
#Initializing config parser to load configurations. parser = SafeConfigParser() parser.read('/home/linaro/latest/IIOT-Projects/config.ini') # REST API url to start the screen transition for moisture # and REST API url to update the flag state of the drought_screen_transition whenever the mosture back to normal highMoistureScreenTransitionAPI = parser.get( 'resturls', 'highMoistureScreenTransitionAPI') droughtScreenTransitionAPI = parser.get('resturls', 'droughtScreenTransitionAPI') #Initializing logger logger = logging.getLogger(__name__) logging.basicConfig(stream=sys.stdout, level=logging.INFO) gpio_c = GPIO.gpio_id('GPIO_K') gpio_d = GPIO.gpio_id('GPIO_L') pins = ((gpio_c, 'out'), (gpio_d, 'out')) green = 0 red = 0 blue = 0 with GPIO(pins) as gpio: screenTransit = False # configuring certificates for making secure connection to the greengrass rootCAPath = parser.get('certsinfo', 'rootcapath') privateKeyPath = parser.get('certsinfo', 'rgbprivatekeypath')
#!/usr/bin/env python from dweet import Dweet import time from gpio_96boards import GPIO GPIO_A = GPIO.gpio_id('GPIO_A') GPIO_C = GPIO.gpio_id('GPIO_C') GPIO_E = GPIO.gpio_id('GPIO_E') pins = ( (GPIO_A, 'out'),(GPIO_C, 'out'),(GPIO_E, 'in'), ) dweet = Dweet() def liga(): gpio.digital_write(GPIO_A, GPIO.HIGH) gpio.digital_write(GPIO_C, GPIO.HIGH) dweet.dweet_by_name(name="iplug", data={"button":1}) resposta = dweet.latest_dweet(name="iplug") #print resposta['with'][0]['content']['button'] def desliga(): gpio.digital_write(GPIO_A, GPIO.LOW) gpio.digital_write(GPIO_C, GPIO.LOW)
# from ggts import gTTS from gpio_96boards import GPIO import cv2 import json import os import requests import sys import time DEVICE_NUMBER = 0 IMAGE_FILE = "output.jpg" API = "http://ec2-18-219-99-191.us-east-2.compute.amazonaws.com:5000/verify" no_face = True GPIO_A = GPIO.gpio_id('GPIO_A') GPIO_C = GPIO.gpio_id('GPIO_C') GPIO_E = GPIO.gpio_id('GPIO_E') GPIO_I = GPIO.gpio_id('GPIO_I') GPIO_K = GPIO.gpio_id('GPIO_K') light_pins = ( (GPIO_A, 'out'), ) gpioc = ((GPIO_C, 'out'),) gpioe = ((GPIO_E, 'out'),) gpioi = ((GPIO_I, 'out'),) gpiok = ((GPIO_K, 'out'),) steps = 0 direction = 1
#Initiallizing config parser to load configurations parser = SafeConfigParser() parser.read('/home/linaro/latest/IIOT-Projects/config.ini') #REST API url to start the screen transition for temperature #and REST API url to update the flag state of the fan_screen_transition when ever the temperature back to normal screenTransitionAPI = parser.get('resturls', 'screenTransitionAPI') changeFanScreenTransitionStateAPI = parser.get( 'resturls', 'changeFanScreenTransitionStateAPI') #Initializing logger logger = logging.getLogger(__name__) logging.basicConfig(stream=sys.stdout, level=logging.INFO) gpio_f = GPIO.gpio_id('GPIO_G') pins = ((gpio_f, 'out'), ) with GPIO(pins) as gpio: # configuring certificates for making secure connection to the greengrass rootCAPath = parser.get('certsinfo', 'rootcapath') privateKeyPath = parser.get('certsinfo', 'fanprivatekeypath') certificatePath = parser.get('certsinfo', 'fancertificatepath') host = parser.get('hostinfo', 'hostip') host_port = parser.get('hostinfo', 'hostport') clientId = parser.get('deviceinfo', 'fanawsdeviceclientid') subscribeTopic = parser.get('mqttinfo', 'fansubscribe_topic') # This function handle keyboard interrupt def signal_handler(signal, frame): gpio.digital_write(gpio_f, 0)
#!/usr/bin/python import time import subprocess import numpy as np import matplotlib.pyplot as plt from scipy.fftpack import fft from scipy.io.wavfile import read from sklearn.preprocessing import normalize from math import floor from gpio_96boards import GPIO GPIO_C = GPIO.gpio_id ('GPIO_C') # TODO switchPin GPIO_E = GPIO.gpio_id ('GPIO_E') # corr tiltPin GPIO_G = GPIO.gpio_id ('GPIO_G') # corr tiltDirPin # declaring GPIO pins as input or output pins = ( (GPIO_C, 'in'), (GPIO_E, 'out'), (GPIO_G, 'out') ) def switch(gpio): gpio.digital_write(GPIO_A, GPIO.LOW) while True: if gpio.digital_read(GPIO_C) == GPIO.HIGH: gpio.digital_write(GPIO_A, GPIO.HIGH) subprocess.call("./recordScript.sh") if getObject(): #bottle object
import spidev import time from libsoc import gpio from gpio_96boards import GPIO POTENCIOMETRO = GPIO.gpio_id('GPIO_CS') #analogica ADC1 LED = GPIO.gpio_id('GPIO_A') #Porta Digital pins = ( (POTENCIOMETRO, 'out'), (LED, 'out'), ) 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
#!/usr/bin/env python from dweet import Dweet import spidev #lib import time from gpio_96boards import GPIO TEMP = GPIO.gpio_id('GPIO_CS') pins = ((TEMP, 'out'), ) 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 #cria o objeto de comunicacao com o portal dweet dweet = Dweet() #le a temperatudo no conectaor ADC2 e retorna o float def readTemperature(gpio): r = spi.xfer2([0x01, 0xA0, 0x00]) gpio.digital_write(TEMP, GPIO.HIGH) #liga o termometro adcout = (r[1] << 8) & 0b1100000000 adcout = adcout | (r[2] & 0xff) adc_temp = (adcout * 5.0 / 1023 - 0.5) * 100 gpio.digital_write(TEMP, GPIO.LOW) print("Temperatura.:%2.1f" % adc_temp)
import spidev import time from libsoc import gpio from gpio_96boards import GPIO GPIO_CS = GPIO.gpio_id('GPIO_CS') pins = ((GPIO_CS, 'out'),) spi = spidev.SpiDev() spi.open(0,0) spi.max_speed_hz = 10000 spi.mode = 0b00 spi.bits_per_word = 8 def readTemparature(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_A, GPIO.HIGH) adcout = (r[1] << 8) & 0b1100000000 adcout = adcout | (r[2] & 0xff) adc_temp = (adcout *5.0/1023-0.5)*100 return adc_temp
#!/usr/bin/python import time from gpio_96boards import GPIO GPIO_A = GPIO.gpio_id('GPIO-A') pins = ( (GPIO_A, 'out'), ) def blink(gpio): for i in range(5): gpio.digital_write(GPIO_A, GPIO.HIGH) time.sleep(i) gpio.digital_write(GPIO_A, GPIO.LOW) time.sleep(1) if __name__ == '__main__': import argparse parser = argparse.ArgumentParser( description='Blink LED on GPIO A (pin 23)') args = parser.parse_args() with GPIO(pins) as gpio: blink(gpio)
import spidev import time from libsoc import gpio from dweet import Dweet from gpio_96boards import GPIO GPIO_CS = GPIO.gpio_id('GPIO_CS') BUTTON = GPIO.gpio_id('GPIO_A') RELE = GPIO.gpio_id('GPIO_C') LED = GPIO.gpio_id('GPIO_E') pins = ( (GPIO_CS, 'out'), (RELE, 'out'), (LED, 'out'), (BUTTON, 'in'), ) spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 10000 spi.mode = 0b00 spi.bits_per_word = 8 dweet = Dweet() def readTemp(gpio): gpio.digital_write(GPIO_CS, GPIO.HIGH)
import time from gpio_96boards import GPIO PortaLed = GPIO.gpio_id('GPIO_E') pins = ((PortaLed, 'out'), ) def piscaled(gpio): gpio.digital_write(PortaLed, GPIO.HIGH) print('Led Turn Off') time.sleep(1) gpio.digital_write(PortaLed, GPIO.LOW) print('Led Turn On') time.sleep(1) while True: with GPIO(pins) as gpio: piscaled(gpio)
import spidev import time from libsoc import gpio from gpio_96boards import GPIO GPIO_CS = GPIO.gpio_id('GPIO_CS') RELE = GPIO.gpio_id('GPIO_A') pins = ((GPIO_CS, 'out'),(RELE, 'out'),) spi = spidev.SpiDev() spi.open(0,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:
import requests, json import serial import time from gpio_96boards import GPIO LEFT = GPIO.gpio_id('GPIO_B') RIGHT = GPIO.gpio_id('GPIO_A') pins = ((LEFT, 'out'), (RIGHT, 'out')) def blink(pin): with GPIO(pins) as gpio: for i in range(3): gpio.digital_write(pin[0], GPIO.HIGH) time.sleep(i) gpio.digital_write(pin[0], GPIO.LOW) time.sleep(1) while True: try: signals = json.loads(requests.get('http://983f4cb9.ngrok.io').text) if signals['right']: blink(pins[1]) reqeusts.get('http://983f4cb9.ngrok.io/right') elif signals['left']: reqeusts.get('http://983f4cb9.ngrok.io/left') blink(pins[0]) time.sleep(1)
def led_print_numbers(numbers): numbers = str(numbers) try: for i in range(0, len(numbers)): led.printNumber(numbers[i], False, 1) time.sleep(LED_SCROLL_PAUSE) finally: led.clearDisplays() led.cleanup() if __name__ == '__main__': global DIN global CS global CLK DIN = GPIO.gpio_id('GPIO-E') CS = GPIO.gpio_id('GPIO-D') CLK = GPIO.gpio_id('GPIO-C') global pins print DIN pins = ( (DIN, 'out'), (CS, 'out'), (CLK, 'out') ) with GPIO(pins) as gpio: numOfDevices = 2 led = LEDBlock(gpio, numOfDevices, 'GPIO-E', 'GPIO-D', 'GPIO-C') while 1 is 1: with open('sensordata.json', 'r') as datafile:
import spidev import time from libsoc import gpio from gpio_96boards import GPIO from dweet import Dweet TEMP = GPIO.gpio_id('GPIO_CS') RELE = GPIO.gpio_id('GPIO_A') LED = GPIO.gpio_id('GPIO_C') pins = ((TEMP, 'in'), (RELE, 'out'), (LED, 'out'),) spi = spidev.SpiDev() spi.open(0,0) spi.max_speed_hz = 10000 spi.mode = 0b00 spi.bits_per_word = 8 dweet = Dweet() def readDigital(gpio): dados = [0,0] dados[0] = gpio.digital_read(LED) dados[1] = gpio.digital_read(RELE) return digital def writeDigital(gpio, dados): escreve = dados gpio.digital_write(LED, escreve[0])