Example #1
0
# -*- coding: latin-1 -*-
'''
Baseado no exemplo disponibilizado pela biblioteca
Exemplo de escrita dos dados da leitura do conversor ADC
em uma arquivo txt

Gustavo Voltani von Atzingen 15/04/2017

Curso IoT 2017 - IFSP Piracicaba
'''
import time
from wiringx86 import GPIOGalileo as GPIO

pinos = GPIO(debug=False)
pinos.pinMode(14, pinos.ANALOG_INPUT)

while 1:
    with open('dados.txt', 'a') as f:
        valor = pinos.analogRead(14)
        f.write(str(valor) + '\n')
    print str(valor) + '\n'
    time.sleep(1)
Example #2
0
# coding: latin1
'''
Baseado no exemplo disponibilizado pela biblioteca
Exemplo de manipulação de GPIO como entrada usando a bilbioteca wiringx86

Gustavo Voltani von Atzingen 15/04/2017
Updated: 28/09/2017

Curso IoT 2017 - IFSP Piracicaba
'''

import time
from wiringx86 import GPIOGalileo as GPIO

pinos = GPIO(debug=False)
numero_pino = 13

pinos.pinMode(numero_pino, pinos.INPUT)

try:
    while True:
        print pinos.digitalWrite(numero_pino)
        time.sleep(1)

except KeyboardInterrupt:
    print '\nLimpando o uso para fechar o programa'
    pinos.cleanup()
Example #3
0
import time
from upm import pyupm_temperature as upm 
from wiringx86 import GPIOGalileo as GPIO 

pinos = GPIO(debug=False)
pino_sensor_temperatura = 0
pino_cooler = 5
pino_sensor_luminosidade = 15
pino_LED = 4
pino_sensor_umidade = 16
pino_bomba = 6

pinos.pinMode(pino_sensor_luminosidade, pinos.ANALOG_INPUT)
pinos.pinMode(pino_LED, pinos.OUTPUT)
pinos.pinMode(pino_sensor_umidade, pinos.ANALOG_INPUT)
pinos.pinMode(pino_bomba, pinos.OUTPUT)
pinos.pinMode(pino_cooler, pinos.OUTPUT)

def leitura_temperatura():
	temperatura = upm.Temperature(pino_sensor_temperatura)
	celsius = temperatura.value()
	return celsius

def liga_cooler():
	pinos.digitalWrite(pino_cooler, pinos.HIGH)

def desliga_cooler():
	pinos.digitalWrite(pino_cooler, pinos.LOW)

def leitura_LDR():
	luminosidade = pinos.analogRead(pino_sensor_luminosidade)
Example #4
0
Professor: Gustavo Voltani von Atzingen
alterações: Giovana Tangerino
'''
from wiringx86 import GPIOGalileo as GPIO
from upm import pyupm_jhd1313m1 as lcd

#pinos GPIO
pino_led_red = 8  #D8
pino_led_green = 7  #D7
pino_led_blue = 6  #D6

# numeracao dos pinos conectados aos sensores de acordo com a bibliteca usada
pinos = GPIO(debug=False)
tela = lcd.Jhd1313m1(0, 0x3E, 0x62)

pinos.pinMode(pino_led_red, pinos.OUTPUT)
pinos.pinMode(pino_led_green, pinos.OUTPUT)
pinos.pinMode(pino_led_blue, pinos.OUTPUT)


def escreve_lcd(texto_linha1, texto_linha2):
    tela.clear()
    tela.setCursor(0, 0)
    tela.write(texto_linha1)
    tela.setCursor(1, 0)
    tela.write(texto_linha2)


def escreve_lcd_cor(texto_linha1, texto_linha2, cor):
    tela.clear()
    tela.setCursor(0, 0)
from flask import Flask, request, render_template, redirect
import time
from wiringx86 import GPIOGalileo as Galileo
from threading import Timer


plug_status = {'a':'off', 'b':'off', 'c':'off'}

gpio = Galileo(debug = False)

plug_a_ctrl = 9
plug_b_ctrl = 10
plug_c_ctrl = 11

gpio.pinMode(plug_a_ctrl, gpio.OUTPUT)
gpio.pinMode(plug_b_ctrl, gpio.OUTPUT)
gpio.pinMode(plug_c_ctrl, gpio.OUTPUT)

gpio.digitalWrite(plug_a_ctrl, gpio.HIGH)
gpio.digitalWrite(plug_b_ctrl, gpio.HIGH)
gpio.digitalWrite(plug_c_ctrl, gpio.HIGH)

class parse_command:
    global plug_a_ctrl
    global plug_b_ctrl
    global plug_c_ctrl


    @staticmethod
    def parse_name(name):
Example #6
0
import time
from upm import pyupm_temperature as upm
from upm import pyupm_servo as servo
from wiringx86 import GPIOGalileo as GPIO
from upm import pyupm_jhd1313m1 as lcd

pino_sensor_temperatura = 0
pino_rele = 5
pino_pot = 15
pino_servo = 8

pinos = GPIO(debug=False)
pinos.pinMode(pino_rele, pinos.OUTPUT)
pinos.pinMode(pino_pot, pinos.ANALOG_INPUT)
pinos.pinMode(pino_servo, pinos.OUTPUT)
temperatura = upm.Temperature(pino_sensor_temperatura)
sg_servo = servo.ES08A(pino_servo)
tela = lcd.Jhd1313m1(0, 0x3E, 0x62)


def leitura_temperatura():
    return temp.value()


def leitura_pot():
    resulado = pinos.analogRead(pino_pot)
    voltagem = resulado * 5.0 / 1023.0
    return voltagem


def liga_rele():
Example #7
0
# -*- coding: latin-1 -*-
'''
Curso IoT 2017 - IFSP Piracicaba
Professor: Gustavo Voltani von Atzingen
alterações: Giovana Tangerino
'''
from wiringx86 import GPIOGalileo as GPIO
from upm import pyupm_temperature as upm

# numeracao dos pinos conectados aos sensores de acordo com a bibliteca usada
pino_pot = 14  #Gbiblioteca PIOGalileo: A0=14, A1=15
pino_sensor_temperatura = 1  #biblioteca pyupm_temperature: A0=0, A1=1

pinos = GPIO(debug=False)
pinos.pinMode(pino_pot, pinos.ANALOG_INPUT)
temperatura = upm.Temperature(pino_sensor_temperatura)


def get_temp():
    return temperatura.value()


def get_pot():
    resultado_adc = pinos.analogRead(pino_pot)
    voltagem = resultado_adc * 5.0 / 1023.0
    return voltagem, resultado_adc
Example #8
0
# Import the time module enable sleeps between turning the led on and off.
import time

# Import the GPIOEdison class from the wiringx86 module.
from wiringx86 import GPIOGalileo as GPIO

# Create a new instance of the GPIOEdison class.
# Setting debug=True gives information about the interaction with sysfs.
gpio = GPIO(debug=True)
pin = 4
analogpin = 16  # 13 digital, Analog inputs: 14-A0,15-A1,16-A2,17-A3,18-A4,19-A5
state = gpio.HIGH

# Set pin 13 to be used as an output GPIO pin.
print 'Setting up pin %d' % pin
gpio.pinMode(pin, gpio.OUTPUT)
gpio.pinMode(analogpin, gpio.ANALOG_INPUT)

print 'Blinking pin %d now...' % pin
try:
    while (True):
        # Write a state to the pin. ON or OFF.
        gpio.digitalWrite(pin, state)
        value = gpio.analogRead(analogpin)
        temp = value * 5 / 1024.0
        temp_2 = temp - 0.5
        temp_3 = (temp_2 / 0.01)
        print "Value from " + str(analogpin) + " is: " + str(
            value) + " | temp: " + str(temp_3)

        # Toggle the state.
from wiringx86 import GPIOGalileo as Galileo

gpio = Galileo(debug = True)

def pinnumber(pin):
    if pin >= 14 or pin <=1:
	return "Pin is not defined";
    else:
	return pin;

def turnmode(level):
    if level == "on":
	level = gpio.HIGH
    elif level == "off":
	level = gpio.LOW
    else:
	return "Turn mode is not defined";
	
    return level;

while True:
    pin = int(raw_input("Enter pin number between 2-13: "))
    level = raw_input("Enter turn mode on/off: ")

    gpio.pinMode(pinnumber(pin), gpio.OUTPUT)
    gpio.digitalWrite(pinnumber(pin), turnmode(level))
Example #10
0
# coding: latin1
'''
Baseado no exemplo disponibilizado pela biblioteca
Exemplo de manipulação de GPIO como entrada usando a bilbioteca wiringx86

Gustavo Voltani von Atzingen 15/04/2017
Updated: 28/09/2017

Curso IoT 2017 - IFSP Piracicaba
'''

import time
from wiringx86 import GPIOGalileo as GPIO

pinos = GPIO(debug=False)
numero_pino = 13

pinos.pinMode(numero_pino, pinos.OUTPUT)

try:
    while True:
        pinos.digitalWrite(numero_pino, pinos.HIGH)
        time.sleep(1)
        pinos.digitalWrite(numero_pino, pinos.LOW)
        time.sleep(1)

except KeyboardInterrupt:
    print '\nLimpando o uso para fechar o programa'
    pinos.digitalWrite(numero_pino, pinos.LOW)
    pinos.cleanup()
Example #11
0
	A2 - 16
	A3 - 17
	A4 - 18
	A5 - 19
'''

# main instance
gpio = GPIO(debug=True)

# Hardware pin definitions
UVOUT = 14  # Analog A0 Output from the sensor
REF_3V3 = 15  # 3.3V power on the Arduino board

# setting pin type
# gpio.pinMode( _pin_, gpio.OUTPUT)
gpio.pinMode(UVOUT, gpio.ANALOG_INPUT)
gpio.pinMode(REF_3V3, gpio.ANALOG_INPUT)


def mapfloat(x, in_min, in_max, out_min, out_max):
    return float((x - in_min) * (out_max - out_min) / (in_max - in_min) +
                 out_min)


def averageAnalogRead(pin, avg=8):
    read_value = 0
    for read in range(1, avg):
        read_value += gpio.analogRead(pin)
    return float(read_value / avg)

Example #12
0
from time import time
import urllib2, json
from wiringx86 import GPIOGalileo as GPIO
pinos = GPIO(debug=False)
from openweather import openweather
with open('config.txt') as json_data:
    config = json.load(json_data)
piracicaba = openweather(config['api_key'], '3453643')
from upm import pyupm_jhd1313m1 as LCD
lcd = LCD.Jhd1313m1(0, 0x3E, 0x62)
from upm import pyupm_servo as servo
from upm import pyupm_temperature as upm
import threading

pino_sensor_temperatura = 0
pino_rele1 = 4
pino_servo = 5
pino_rele2 = 8
pino_pot = 15
pino_pot2 = 16
pino_pot3 = 17

pinos.pinMode(pino_rele1, pinos.OUTPUT)
pinos.pinMode(pino_rele2, pinos.OUTPUT)
pinos.pinMode(pino_pot, pinos.ANALOG_INPUT)
pinos.pinMode(pino_pot2, pinos.ANALOG_INPUT)
pinos.pinMode(pino_pot3, pinos.ANALOG_INPUT)
pinos.pinMode(pino_servo, pinos.PWM)
sg_servo = servo.ES08A(pino_servo)
pinos.digitalWrite(pino_rele1, pinos.LOW)
pinos.digitalWrite(pino_rele2, pinos.LOW)
Example #13
0
from wiringx86 import GPIOGalileo as GPIO
from upm import pyupm_jhd1313m1 as lcd

# definicoes do lcd
tela = lcd.Jhd1313m1(0, 0x3E, 0x62)
tela.clear()
tela.setCursor(0, 0)

# pinos fisicos conectados ao shield grove
pino_pot = 14
pino_botao = 5
pino_rele = 13

# cria o objeto para leitura do potenciometro
potenciometro = GPIO(debug=False)
potenciometro.pinMode(pino_pot, potenciometro.ANALOG_INPUT)

# cria o objeto para leitura do rele
rele = GPIO(debug=False)
rele.pinMode(pino_rele, rele.OUTPUT)

# cria o objeto para leitura do botao
botao = GPIO(debug=False)
botao.pinMode(pino_botao, botao.INPUT)


def leitura_pot():
    try:
        return potenciometro.analogRead(pino_pot)
    except Exception as e:
        print 'erro leitura_pot', e
def main(argv):
    gpio = GPIO(debug=True)
    pin = 13
    state = gpio.HIGH
    servo_pin = 9
    gpio.pinMode(pin, gpio.OUTPUT)
    gpio.pinMode(servo_pin, gpio.PWM)
    

    # PWM period for G2 is same for all pins so second call is redundant
    pwm_period = 3000000
    gpio.setPWMPeriod(servo_pin, pwm_period)

    # Turn on LED
    gpio.digitalWrite(pin, gpio.HIGH)

    # Read analog input from pin 14
    adc_l = 14 # A0

    # Set pin 14 to be used as an analog input GPIO pin.
    gpio.pinMode(adc_l, gpio.ANALOG_INPUT)

    # With a 100 Ohm resistor and 3.3K resistor and 10k Pot the min max vals 
    # read from the ADC are around
    min_val = 204
    max_val = 994
    val_range = float(max_val - min_val)

    # Servo min and max pulse in ms
    min_pulse = 500000
    max_pulse = 2500000
    pulse_range = float(max_pulse-min_pulse)
    

    print 'Analog reading from pin %d now...' % adc_l
    try:
        old_pulse_length = 0

        while(True):
            value_l = gpio.analogRead(adc_l)
            
            print value_l
            print ""

            norm_val = float(value_l - min_val) / val_range
            norm_val = min( max(0.0, norm_val), 1.0 )

            print norm_val

            # What is duty cycle?
            pulse_length = (norm_val * pulse_range) + min_pulse
            pulse_pct = float(abs(pulse_length - old_pulse_length)) / \
                        float(pulse_length) 

            # Only write new duty cycle if there is significant change from 
            # previous value 
            if pulse_pct > 0.02:
                gpio.analogWrite(servo_pin, \
                                 int(float(pulse_length)/pwm_period * 255.0))
            else:
                pass
                
            old_pulse_length = pulse_length
            

            time.sleep(0.2)

    except KeyboardInterrupt:
        gpio.analogWrite(servo_pin, 0)

        # Leave the led turned off.
        gpio.digitalWrite(pin, gpio.LOW)


    print '\nCleaning up...'
    gpio.cleanup()
Example #15
0
# -*- coding: latin-1 -*-
'''
Baseado no exemplo disponibilizado pela biblioteca wiringx86 para GalileoBoard
Exemplo de leitura do conversor ADC ("leitura analógica")

Gustavo Voltani von Atzingen 15/04/2017
Updated: 28/09/2017

Curso IoT 2017 - IFSP Piracicaba
'''
import time
from wiringx86 import GPIOGalileo as GPIO

pinos = GPIO(debug=False)  # Degub False para evitar info no terminal
pinos.pinMode(14, pinos.ANALOG_INPUT)  # A0 = 14, A1 = 15, ...

while 1:
    valor = pinos.analogRead(14)
    print valor
    time.sleep(1)
Example #16
0
def main(argv):
    gpio = GPIO(debug=True)
    pin = 13
    state = gpio.HIGH
    servo_pin = 9
    gpio.pinMode(pin, gpio.OUTPUT)
    gpio.pinMode(servo_pin, gpio.PWM)

    # PWM period for G2 is same for all pins so second call is redundant
    pwm_period = 3000000
    gpio.setPWMPeriod(servo_pin, pwm_period)

    # Turn on LED
    gpio.digitalWrite(pin, gpio.HIGH)

    # Read analog input from pin 14
    adc_l = 14  # A0

    # Set pin 14 to be used as an analog input GPIO pin.
    gpio.pinMode(adc_l, gpio.ANALOG_INPUT)

    # With a 100 Ohm resistor and 3.3K resistor and 10k Pot the min max vals
    # read from the ADC are around
    min_val = 204
    max_val = 994
    val_range = float(max_val - min_val)

    # Servo min and max pulse in ms
    min_pulse = 500000
    max_pulse = 2500000
    pulse_range = float(max_pulse - min_pulse)

    print 'Analog reading from pin %d now...' % adc_l
    try:
        old_pulse_length = 0

        while (True):
            value_l = gpio.analogRead(adc_l)

            print value_l
            print ""

            norm_val = float(value_l - min_val) / val_range
            norm_val = min(max(0.0, norm_val), 1.0)

            print norm_val

            # What is duty cycle?
            pulse_length = (norm_val * pulse_range) + min_pulse
            pulse_pct = float(abs(pulse_length - old_pulse_length)) / \
                        float(pulse_length)

            # Only write new duty cycle if there is significant change from
            # previous value
            if pulse_pct > 0.02:
                gpio.analogWrite(servo_pin, \
                                 int(float(pulse_length)/pwm_period * 255.0))
            else:
                pass

            old_pulse_length = pulse_length

            time.sleep(0.2)

    except KeyboardInterrupt:
        gpio.analogWrite(servo_pin, 0)

        # Leave the led turned off.
        gpio.digitalWrite(pin, gpio.LOW)

    print '\nCleaning up...'
    gpio.cleanup()