# 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()
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))
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): if name == "a": plug = plug_a_ctrl elif name == "b": plug = plug_b_ctrl
# 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. state = gpio.LOW if state == gpio.HIGH else gpio.HIGH # Sleep for a while. time.sleep(0.5) # When you get tired of seeing the led blinking kill the loop with Ctrl-C. except KeyboardInterrupt:
# 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()
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)
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()
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()