def checkThenSetByte(dataVar): gpio = GPIO(debug=False) for x in range(0,8): if x==0: pin=2 elif x==1: pin=3 elif x==2: pin=4 elif x==3: pin=5 elif x==4: pin=6 elif x==5: pin=13 else: break gpio.pinMode(pin,gpio.OUTPUT) if checkBit(dataVar,x)>0: print("on") gpio.digitalWrite(pin, gpio.HIGH) if pin==13: print('indikator on') else: print("off") gpio.digitalWrite(pin, gpio.LOW) if pin==13: print('indikator off') if debugMode:print("seharusnya setelah di set, disini dicek lagi benar2 on apa tidak")
def defineIO(): gpio = GPIO(debug=False) if debugMode: print 'setting up io pin' gpio.pinMode(13,gpio.OUTPUT) gpio.pinMode(2,gpio.OUTPUT) gpio.pinMode(3,gpio.OUTPUT) gpio.pinMode(4,gpio.OUTPUT) gpio.pinMode(5,gpio.OUTPUT) gpio.pinMode(6,gpio.OUTPUT) if debugMode: print 'successfull...'
def start_stream(sensor_pin=14, fs=10): """ Reads values from analog pin 14 and forwards them to a LSL-stream. """ # Setup the LSL stream uuid = binascii.b2a_hex(os.urandom(3)) stream_info = lsl.StreamInfo('luminosity', 'analog', 1, fs, 'float32', uuid) stream_outlet = lsl.StreamOutlet(stream_info) # Setup GPIO gpio = GPIO(debug=False) gpio.pinMode(sensor_pin, gpio.ANALOG_INPUT) interval = 1.0 / fs try: while True: value = gpio.analogRead(sensor_pin) stream_outlet.push_sample([value]) time.sleep(interval) except KeyboardInterrupt: print("\nCleaning up...") gpio.cleanup()
#!/usr/bin/python3 import sys sys.path.append("../gpio") import subprocess import threading import time import os from wiringx86 import GPIOGalileoGen2 as GPIO gpio = GPIO(debug=False) user_pin = 0 gpio.pinMode(user_pin, gpio.OUTPUT) class user(object): def __init__(self, path, MAC, name, last_ip="none"): self.connected = False self.scripts_path = path self.last_connected = 0 self.name = name self.mac_addr = MAC self.ip = "" self.last_ip = last_ip self.tries = 0 def validate_ip(self): valid = self.ip.split('.') if len(valid) == 4:
# -*- 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)
def __init__(self, pin, unit="c", debug=False): self.gpio = GPIO(debug=False) self.unit = unit self.pin = pin self.gpio.pinMode(self.pin, self.gpio.ANALOG_INPUT)
class Board: gpio = GPIO(debug=False)
def __init__(self, pin_): self.gpio = GPIO(debug=False) self.gpio.pinMode(pin_, self.gpio.OUTPUT)
# -*- coding: utf-8 -*- # # 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(
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
# -*- 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)
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 __init__(self, pin): self.gpio = GPIO(debug=False) self.pin = pin self.gpio.pinMode(pin, self.gpio.INPUT)