Esempio n. 1
0
 def __init__(self, cursor):
     threading.Thread.__init__(self)
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(17, 0)
     self.cursor = cursor
     self.start()
     self.shot = False
Esempio n. 2
0
def setup_servo():
    wiringpi.wiringPiSetupGpio()
    wiringpi.pinMode(18,2)      # hardware pwm only works on GPIO port 18  
    wiringpi.pwmSetMode(0)
    wiringpi.pwmSetClock(375)
    wiringpi.pwmSetRange(1024)
    wiringpi.pwmWrite(18,0)
Esempio n. 3
0
def initPorts():
	#
	# define constants
	#
	INPUT = 0
	OUTPUT = 1
	PUD_UP = 2
	#
	# use Broadcom GPIO pin scheme
	#
	gpio.wiringPiSetupGpio()
	
	# comparator output is PGOOD  - needs pull-up
	#
	gpio.pinMode(PGOOD,INPUT)
	gpio.pullUpDnControl(PGOOD,PUD_UP)
	#
	#
	gpio.pinMode(CSb,OUTPUT)
	gpio.pinMode(UDb,OUTPUT)
	#
	# cs* -> 1 to deselect; USb is don't care
	#
	gpio.digitalWrite(CSb,1)
	return
Esempio n. 4
0
def main():
    global lcd
    global inactivity_timer
    global motion_sensor
    global distance_sensor
    global lcd
    global buzzer
    global led
    global last_pullup_time
    global pullup_count_alltime
    global pullups_to_go
    global storage

    wiringpi.wiringPiSetupGpio()

    init_storage()

    inactivity_timer = InactivityTimer(wakeup, shutdown, config.SHUTDOWN_DELAY)
    motion_sensor = MotionSensor(wiringpi, config.MOTION, inactivity_timer.trigger)
    distance_sensor = DistanceSensor(wiringpi, config.SONIC_ECHO, config.SONIC_TRIG)
    lcd = Display(config.LCD_RS, config.LCD_E, config.LCD_D4, config.LCD_D5, config.LCD_D6, config.LCD_D7, config.LCD_K)
    buzzer = Buzzer(wiringpi, config.BUZZER)
    led = Led(wiringpi, config.LED_PIN)

    distance_resetted = True

    shutdown()

    while True:
        if inactivity_timer.is_active():
            distance = distance_sensor.measure()

            distance_str = "{:13.2f}".format(distance)

            if config.DEBUG:
                print(distance_str + " cm")
                # if wiringpi.millis() % 5 == 0:
                #     lcd.message(0, 0, distance_str + " cm")

            # only count a pullup if:
            # - distance is smaller than 5cm
            # - distance was resetted (athlete moved more than 20 cm away from sensor)
            # - last pullup was done more than 1 second ago
            if 0 < distance < config.COUNT_DISTANCE and distance_resetted and wiringpi.millis() > (last_pullup_time + config.RESET_TIME):
                buzzer.beep(5000)
                distance_resetted = False
                cnt = count_pullup()
                lcd.clear()
                lcd.message(0, 0, "Pullups: " + str(cnt).rjust(5))
                lcd.message(0, 1, "2do2day: " + str(pullups_to_go).rjust(5))
            elif distance > config.RESET_DISTANCE:
                distance_resetted = True

        delay_milli(100)

        inactivity_timer.loop()
        motion_sensor.sense()

        if config.DEBUG and inactivity_timer.is_active() == 1:
            print("shutting down in " + inactivity_timer.get_seconds_till_shutdown() + " seconds")
Esempio n. 5
0
    def __init__(self):
        led.wiringPiSetupGpio()
        led.pinMode(18, 2)      # sets GPIO 24 to output

        #self.pwmLed=pwmLed
        
        #self.ledPin=18
        self.pwmThread=threading.Thread(target=self.fade)
Esempio n. 6
0
 def initQTI(self,wiring=True):
     #pin = pinNum
     if wiring == True:
         wp.wiringPiSetup()
         wp.wiringPiSetupGpio()
         wp.wiringPiSetupPhys()
     else:
         GPIO.setmode(GPIO.BOARD)
def setup():
        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(25,1)        #red light
        wiringpi.digitalWrite(25,0)   #red is off
        wiringpi.pinMode(24,1)        #green light
        wiringpi.digitalWrite(24,0)   #green is off
      
        flash(2)
Esempio n. 8
0
def Main():
	print 'AR600 signal configuration tool.\nPlease follow instructions on screen.'
	print 'To cancel, kill this process via Ctrl+Z. Lazy I know :D'

	wiringpi.wiringPiSetupGpio()

	signals = [PWMSignal(5, 'Thro', True, 'right stick, horizontal', 'left', 'right'), 
		PWMSignal(6, 'Aile', False, 'left stick, vertical', 'up', 'down'), 
		PWMSignal(19, 'Elev', True, 'right stick, vertical', 'up', 'down'), 
		PWMSignal(26, 'Rudo', True, 'left stick, horizontal', 'left,', 'right'),
		PWMSignal(21, 'Gear', False, 'trainer binary switch', '0 (away from you)', '1 (towards you)'), 
		PWMSignal(20, 'Aux1', False, 'left trigger switch', 'towards you', 'default position (away from you)')]

	for signal in signals:

		print '-> Now configuring ' + signal.name

		print 'Please move ' + signal.descr + ', maximally ' + signal.descrMax + \
			', hold for 2 seconds and hit Ctrl+C.'
		try:
			while True:
				signal.Update()
		except KeyboardInterrupt:
			signal.SetMax()
		print 'Set: ' + str(signal.maxVal)

		print 'Please move ' + signal.descr + ', maximally ' + signal.descrMin + \
			', hold for 2 seconds and hit Ctrl+C.'
		try:
			while True:
				signal.Update()
		except KeyboardInterrupt:
			signal.SetMin()
		print 'Set: ' + str(signal.minVal)


		if not signal.input.hasNeutral:
			continue

		print 'Please move ' + signal.descr + ', to neutral position, hold for 2 seconds and hit Ctrl+C.'
		try:
			while True:
				signal.Update()
		except KeyboardInterrupt:
			signal.SetNeu()
		print 'Set: ' + str(signal.neuVal)




	f = open("radio.cfg", "w")
	for signal in signals:
		tuple = (signal.name, str(signal.maxVal), str(signal.minVal), str(signal.neuVal))
		f.write(",".join(tuple))
		f.write("\n")
	f.close()
	
	print 'Configuration data saved to radio.cfg'
Esempio n. 9
0
def Init():
	global on, timeOfLastChange
	wiringpi.wiringPiSetupGpio()
	wiringpi.pinMode(27, 1)
	wiringpi.pullUpDnControl(27, 1)
	wiringpi.digitalWrite(27, 1) # switch on LEDs
	on = True
	timeOfLastChange = time.time()
	procComms.PrintLog('Switched on LEDs.')
Esempio n. 10
0
    def __init__(self):
        wiringpi2.wiringPiSetupGpio()

        self.SPEAKER = 18
        self.MODE_PWM = 2

        wiringpi2.pinMode(self.SPEAKER, self.MODE_PWM)
        wiringpi2.pwmSetMode(wiringpi2.GPIO.PWM_MODE_MS)

        wiringpi2.pwmWrite(self.SPEAKER, 0)
Esempio n. 11
0
 def __init__(self, base0 = 27, base90 = 73):
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(18,2)
     wiringpi.pwmSetMode(0)
     wiringpi.pwmSetClock(400)
     wiringpi.pwmSetRange(1024)
     wiringpi.pwmWrite(18, 0)
     self.base0 = base0
     self.base90 = base90
     self.setAngle(90)
Esempio n. 12
0
 def __init__(self, forward, backward):
     self.forward = forward
     self.backward = backward
     self.status = 0
     
     wiringpi2.wiringPiSetupGpio()
     wiringpi2.pinMode(forward, 1) # sets GPIO forward to output  
     wiringpi2.pinMode(backward, 1) 
     wiringpi2.softPwmCreate(forward, 0, 100)
     wiringpi2.softPwmCreate(backward, 0, 100)
Esempio n. 13
0
	def __init__(self,in1,in2,in3):
		self.in1 = in1
		self.in2 = in2
		self.in3 = in3
		GPIO.setmode(GPIO.BCM)
		GPIO.setup(self.in1,GPIO.OUT)
		GPIO.setup(self.in2,GPIO.OUT)
                wiringpi.wiringPiSetupGpio()
                wiringpi.pinMode(self.in3, wiringpi.GPIO.PWM_OUTPUT)
                wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
                wiringpi.pwmSetClock(375)
                wiringpi.pwmWrite(self.in3,0)
Esempio n. 14
0
	def __init__(self, name, pinToWatch, triggerOnHigh = True, debounceTimeInSeconds = 0):
		self._watchPin = pinToWatch
		self._dataLock = Lock()
		self._name = name
		self._triggerOnHigh = triggerOnHigh
		self._debounceTimedelta = timedelta(seconds=debounceTimeInSeconds)

		wiringpi.wiringPiSetupGpio()
		wiringpi.piHiPri(99)
		wiringpi.wiringPiISR(self._watchPin, wiringpi.GPIO.INT_EDGE_BOTH, DoorbellSensor.gpioCallback, self)

		if bool(wiringpi.digitalRead(self._watchPin)) == self._triggerOnHigh:
			self._timeLastTriggered = datetime.today()
Esempio n. 15
0
def init():
    #Initialize wiringpi interface
    wiringpi.wiringPiSetupGpio()

    # Enter all known sensors into array
    sensors.append(Sensor(CENTER_TRIG, CENTER_ECHO, 0))
    #sensors.append(Sensor(CENTER_TRIG, RIGHT_SENSE_ECHO, 1))
    #sensors.append(Sensor(CENTER_TRIG, LEFT_SENSE_ECHO, -1))
    wiringpi.digitalWrite(OUTPUT_ENABLED, HIGH)

    for sensor in sensors: 
        wiringpi.pinMode(sensor.trigger, OUTPUT)
        wiringpi.pinMode(sensor.echo, OUTPUT)
Esempio n. 16
0
    def __init__(self):
        self.thrd_sleep_duration = 0.2  # sec
        self.light_pin = 18
        self.started = False
        self.exit_flag = threading.Event()
        self.brightness = 0.0  # 0.0 to 1.0
        self.ctrl_events = []

        if not TEST_MODE:
            IO.wiringPiSetupGpio()
            IO.pinMode(self.light_pin, IO.GPIO.PWM_OUTPUT)
            IO.pwmSetClock(1920)
            IO.pwmSetRange(100)
Esempio n. 17
0
    def __init__(self):
        wiringpi.wiringPiSetupGpio()

        # Set pin states
        wiringpi.pinMode(enable_led_a, 1)
        wiringpi.pinMode(enable_led_b, 1)
        wiringpi.pinMode(sensor, 0)
        wiringpi.pinMode(enable_motor_a, 1)
        wiringpi.pinMode(enable_motor_b, 1)

        wiringpi.digitalWrite(enable_led_a, 0)
        wiringpi.digitalWrite(enable_led_b, 0)
        wiringpi.digitalWrite(enable_motor_a, 0)
        wiringpi.digitalWrite(enable_motor_b, 0)
Esempio n. 18
0
        def setup(self, data, clock, latch):
                self.dataPin = data 
                self.clockPin = clock
                self.latchPin = latch
                
                wiringpi2.wiringPiSetupGpio()
                
                wiringpi2.pinMode(self.latchPin,1)
                wiringpi2.pinMode(self.dataPin,0)
                wiringpi2.pinMode(self.clockPin,1)

##                wiringpi2.digitalWrite(self.dataPin,0)
                wiringpi2.digitalWrite(self.clockPin,0)
                wiringpi2.digitalWrite(self.latchPin,1)
Esempio n. 19
0
def init():
	GPIO.setmode(GPIO.BCM)
	wiringpi.wiringPiSetupGpio()
	wiringpi.pinMode(LEFT_MOTOR_PWM, 2)
	wiringpi.pinMode(RIGHT_MOTOR_PWM, 2)
	wiringpi.pwmSetMode(0)
	wiringpi.pwmSetClock(CLK_DIVISOR)
	wiringpi.pwmSetRange(MAX_SPEED)
	wiringpi.pwmWrite(LEFT_MOTOR_PWM, 0)
	wiringpi.pwmWrite(RIGHT_MOTOR_PWM, 0)
	GPIO.setup(LEFT_MOTOR_A, GPIO.OUT)
	GPIO.setup(LEFT_MOTOR_B, GPIO.OUT)	
	GPIO.setup(RIGHT_MOTOR_A, GPIO.OUT)
	GPIO.setup(RIGHT_MOTOR_B, GPIO.OUT)
Esempio n. 20
0
	def __init__(self, name, pinToWatch, triggerOnHigh = True):
		self._watchPin = pinToWatch
		self._dataLock = Lock()
		self._name = name
		self._triggerOnHigh = triggerOnHigh

		wiringpi.wiringPiSetupGpio()
		wiringpi.piHiPri(99)
		wiringpi.wiringPiISR(self._watchPin, wiringpi.GPIO.INT_EDGE_BOTH, Sensor.gpioCallback, self)

		if bool(wiringpi.digitalRead(self._watchPin)) == self._triggerOnHigh:
			self._lastStatus = True
		else:
			self._lastStatus = False
			self._triggerEnded = datetime.today()
Esempio n. 21
0
def manageGpio(value, numOutput):
	#config gpios with wiringpi2 library
	wiringpi2.wiringPiSetupGpio()
	wiringpi2.pinMode(23, 1)
	wiringpi2.pinMode(24, 1)
	
	if value == '\x05' and numOutput == 'P1':
		wiringpi2.digitalWrite(23,1)
		wiringpi2.digitalWrite(24,0)
	elif value == '\x05' and numOutput == 'P2':
		wiringpi2.digitalWrite(23,0)
		wiringpi2.digitalWrite(24,1)
	else:
		wiringpi2.digitalWrite(23,0)
		wiringpi2.digitalWrite(24,0)
Esempio n. 22
0
def setupIO():
    # Initialisation des entrées sorties sur le GrovePi #
    grovepi.pinMode(relay_pin,"OUTPUT")
    grovepi.pinMode(RGB_pin,"OUTPUT")
    grovepi.pinMode(PIR_pin, "INPUT")
    grovepi.chainableRgbLed_init(RGB_pin,8)
    
    # On génère un PWM hardware de fréquence 50Hz #
    # La largeur de l'impulsion est entre 0,8 et 2ms #
    wiringPi.wiringPiSetupGpio()
    wiringPi.pinMode(PWM_GPIO, 2)
    wiringPi.pwmSetMode(0)
    wiringPi.pwmSetClock(384)
    wiringPi.pwmSetRange(1024)
    wiringPi.pwmWrite(PWM_GPIO,75)
Esempio n. 23
0
        def __init__(self):
                wiringPi.wiringPiSetupGpio()

                for i in PINS:
                        wiringPi.pinMode(i, 0)
                wiringPi.pinMode(CLOCK, 1)
                wiringPi.pinMode(ACK, 1)

                self.time0 = time.time()
                self.time1 = time.time()-self.time0
                self.time2 = time.time()-self.time0

                self.bits = [0 for i in range(0,10)]
                self.words = [self.bits[:] for i in range(0,10)]

                wiringPi.digitalWrite(ACK, 1)
                time.sleep(CLKSPD)
Esempio n. 24
0
def io_init():
  global io_initialized
  if io_initialized:
    return

  wiringpi2.wiringPiSetupGpio()
  wiringpi2.pinMode(12, wiringpi2.GPIO.PWM_OUTPUT)
  wiringpi2.pinMode(13, wiringpi2.GPIO.PWM_OUTPUT)

  wiringpi2.pwmSetMode(wiringpi2.GPIO.PWM_MODE_MS)
  wiringpi2.pwmSetRange(MAX_SPEED)
  wiringpi2.pwmSetClock(2)

  wiringpi2.pinMode(5, wiringpi2.GPIO.OUTPUT)
  wiringpi2.pinMode(6, wiringpi2.GPIO.OUTPUT)

  io_initialized = True
Esempio n. 25
0
def listener():
	rospy.init_node('listener', anonymous=True)

	rospy.Subscriber("chatter", String, callback)

	wiringpi.wiringPiSetupGpio()
	wiringpi.pinMode(pin,2)
	wiringpi.pwmSetMode(0)
	wiringpi.pwmSetClock(400)
	wiringpi.pwmSetRange(1024)
	wiringpi.pwmWrite(pin,0)

	wiringpi.pinMode(pin_dir[0],1)
	wiringpi.pinMode(pin_dir[1],1)

    # spin() simply keeps python from exiting until this node is stopped
	rospy.spin()
Esempio n. 26
0
def main():
    if DEBUG == 1:
        if not wiringpi2_module:
            print 'wirinpi2 not installed!'
    # Inizializza log
    flog = ET.parse(CFGFILENAME).find("log[@file]").attrib['file']
    # Lettura del tipo file di log (D per giornaliero, M per mensile)
    logtype = ET.parse(CFGFILENAME).find("log[@type]").attrib['type']
    # Istanzia log
    logobj = Log(flog,logtype)
    # Controlla la presenza della connessione ad internet.
    if not internet_alive():
        # Internet non disponibile!
        cnt = 1
        tcheck = 60
        while cnt < 3:
            # Calcolo tempo intervallo tentativi
            tcheck = tcheck * cnt
            logobj.write('Rilevato problema con connessione internet. Prossimo tentativo tra ' + str(tcheck/60) + ' minuto/i...')
            if DEBUG == 1:
                print 'Rilevato problema con connessione internet. Prossimo tentativo tra ' + str(tcheck/60) + ' minuto/i...'
            # Attendi...
            time.sleep(tcheck)
            # Incrementa contatore tentativi
            cnt = cnt + 1
            if DEBUG == 1:
                print cnt
            if not internet_alive():
                # Dopo il terzo tentativo riavvia il router.
                if cnt == 3:
                    # Inizializza pin GPIO come output
                    wiringpi.wiringPiSetupGpio()
                    wiringpi.pinMode(GPIO_ROUTER_ADDR, 1)
                    # Riavvia il router
                    wiringpi.digitalWrite(GPIO_ROUTER_ADDR, 1) # OFF
                    time.sleep(5)
                    wiringpi.digitalWrite(GPIO_ROUTER_ADDR, 0) # ON
                    logobj.write('Router riavviato. Arrivederci :)')
                    if DEBUG == 1:
                        print 'Router riavviato. Arrivederci :)'
            else:
                # Internet OK
                logobj.write('Internet OK. Arrivederci :)')
                if DEBUG == 1:
                    print 'Internet OK. Arrivederci :)'
                break
Esempio n. 27
0
def main():
    OUTPUT = 2
    PWM_PIN = 18
    SLEEP_TIME = 0.03

    wiringpi.wiringPiSetupGpio()
    wiringpi.pinMode(PWM_PIN, OUTPUT)

    for i in range(0, 1024, 16):
        print(i)
        wiringpi.pwmWrite(PWM_PIN, i)
        time.sleep(SLEEP_TIME)

    for i in range(1024, 0, -16):
        print(i)
        wiringpi.pwmWrite(PWM_PIN, i)
        time.sleep(SLEEP_TIME)
def initialize():
    """Set pins as outputs and start all lights in the off state."""
    if _EXPORT_PINS:
        logging.info("Running as non root user, disabling pwm mode on "
                     "all pins")

        for pin in xrange(GPIOLEN):
            PIN_MODES[pin] = "onoff"
            is_pin_pwm[pin] = False
        wiringpi.wiringPiSetupSys()
    else:
        # TODO(mdietz): Configrable pin mode or GPIO mode
        #wiringpi.wiringPiSetup()
        wiringpi.wiringPiSetupGpio()
        enable_device()

    set_all_pins_as_outputs()
    turn_off_all_lights()
Esempio n. 29
0
    def __init__(self):

        wiringpi2.wiringPiSetupGpio()

        self.SPEAKER = 18
        self.MODE_PWM = 2

        self.divisor = (19.2*(10**3))/440

        wiringpi2.pinMode(self.SPEAKER, self.MODE_PWM)
        wiringpi2.pwmSetMode(wiringpi2.GPIO.PWM_MODE_MS)

        screen = curses.initscr()
        curses.start_color()
        self.window = curses.newwin(10, 80, 5, 5)

        curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
Esempio n. 30
0
def Main():
	procComms.PrintLog('Initializing...')	

	wiringpi.wiringPiSetupGpio()

	inputs = []
	inputs.append(Input(5, 'Thro', True))
	inputs.append(Input(6, 'Aile', False))
	inputs.append(Input(19, 'Elev', True))
	inputs.append(Input(26, 'Rudo', True))
	inputs.append(Input(21, 'Gear', False))
	inputs.append(Input(20, 'Aux1', False))

	time.sleep(2) # wait for 2 secs for other subprocesses to initialize

	while keepRunning:
		for input in inputs:
			input.Update()
Esempio n. 31
0
import wiringpi2 as wiringpi
from time import sleep

wiringpi.wiringPiSetupGpio()  #setup for BCM mode
wiringpi.pinMode(18, 2)       #enable PWM on GPIO18
wiringpi.pwmWrite(18, 0)      #set duty cycle to 0 (range is 0-1024)

delay_time = 0.002

try:
    while True:
        for dc in range(0, 1025):
            wiringpi.pwmWrite(18, dc)
            sleep(delay_time)
        for dc in range(1024, -1, -1):
            wiringpi.pwmWrite(18, dc)
            sleep(delay_time)
 
except KeyboardInterrupt:
    pass

finally:
    wiringpi.pwmWrite(18, 0) #turn off PWM mode
    wiringpi.pinMode(18, 0)  #reset GPIO18 to input
Esempio n. 32
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import wiringpi2
import time

# GPIOの指定をGPIO番号に設定する。
if wiringpi2.wiringPiSetupGpio() == -1:
    sys.exit(1)

# 使用するGPIOポート
port = 18

# 指定のGPIOの出力方向を決める。
# GPIO.INPUT, GPIO.OUTPUT, GPIO.PWM_OUTPUT, GPIO_CLOCK
wiringpi2.pinMode(port, wiringpi2.GPIO.PWM_OUTPUT)

SLEEP_TIME = 0.01

val = 0
while True:
    try:
        for pw in range(1024):
            wiringpi2.pwmWrite(port, pw)
            time.sleep(SLEEP_TIME)
        for pw in range(1024 - 1, 0 - 1, -1):
            wiringpi2.pwmWrite(port, pw)
            time.sleep(SLEEP_TIME)
    except KeyboardInterrupt:
        break
    except:
Esempio n. 33
0
#!/usr/bin/env python

import rospy
import subprocess
from time import time, sleep, localtime
from sensor_msgs.msg import Imu, Temperature

from wiringpi2 import wiringPiSetupGpio, pinMode, digitalRead, digitalWrite, GPIO
wiringPiSetupGpio()

if rospy.has_param('/topic_ui/clk'):
    CLK = rospy.get_param('/topic_ui/clk')

if rospy.has_param('/topic_ui/dio'):
    DIO = rospy.get_param('/topic_ui/dio')
"""
      A
     ---
  F |   | B
     -G-
  E |   | C
     ---
      D

"""


class TM1637:
    I2C_COMM1 = 0x40
    I2C_COMM2 = 0xC0
    I2C_COMM3 = 0x80
Esempio n. 34
0
        except:
            ser = None
            print "Error opening serial port"
    try:
        ser.write(cmd)
    except:
        print "Error sending data to serial port"
        try:
            ser.close()
        except:
            print "Error closing port"
        ser = None


if __name__ == "__main__":
    wiringpi2.wiringPiSetupGpio()  # BCM numeration
    #motors pins set to output
    wiringpi2.pinMode(gpio_enableMotors, 1)
    wiringpi2.pinMode(gpio_leftPwm, 1)
    wiringpi2.pinMode(gpio_left1, 1)
    wiringpi2.pinMode(gpio_left2, 1)
    wiringpi2.pinMode(gpio_rightPwm, 1)
    wiringpi2.pinMode(gpio_right1, 1)
    wiringpi2.pinMode(gpio_right2, 1)
    wiringpi2.pinMode(gpio_lights, 1)
    stop()
    #enabling motor controller
    wiringpi2.digitalWrite(gpio_enableMotors, 1)
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(80)
    tornado.ioloop.IOLoop.instance().start()
Esempio n. 35
0
#	pwm_gpio18.py
#
#						Feb/20/2017
#
# --------------------------------------------------------------------
import sys
import RPi.GPIO as GPIO
from time import sleep
import wiringpi2 as wiringpi
# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
PWM0 = 18
PWM1 = 19

wiringpi.wiringPiSetupGpio()  # GPIO名で番号を指定する
wiringpi.pinMode(PWM0, wiringpi.GPIO.PWM_OUTPUT)  # PWM出力を指定
wiringpi.pinMode(PWM1, wiringpi.GPIO.PWM_OUTPUT)  # PWM出力を指定
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)  # 周波数を固定するための設定
wiringpi.pwmSetClock(375)  # 50 Hz。18750/(周波数) の計算値に近い整数
# PWMのピン番号18とデフォルトのパルス幅をデューティ100%を1024として指定
# ここでは6.75%に対応する69を指定
wiringpi.pwmWrite(PWM0, 69)
wiringpi.pwmWrite(PWM1, 69)

count = 0
try:
    while True:
        sys.stderr.write("%d\n" % count)
        count += 1
        wiringpi.pwmWrite(PWM0, 69)
Esempio n. 36
0
# SPI channle (0 or 1)
SPI_CH = 0

# pin base (above 64)
PIN_BASE=70

# GPIO number
LED_PIN = 25

# threshold
THRESHOLD = 200

# setup
wp.mcp3002Setup (PIN_BASE, SPI_CH)
wp.wiringPiSetupGpio()
wp.pinMode(LED_PIN, wp.GPIO.OUTPUT)

# if a sensor value is over THRESHOLD,
# flash led.
while True:
    value = wp.analogRead(PIN_BASE)
    print (value)

    if value > THRESHOLD:
      wp.digitalWrite(LED_PIN, wp.GPIO.HIGH)
      time.sleep(0.2)
      wp.digitalWrite(LED_PIN, wp.GPIO.LOW)
      time.sleep(0.2)
      requests.post("http://maker.ifttt.com/trigger/button_pressed/with/key/7nP8omSWbqca3Cdryst5c", json={"value1": "Yes"})
      connector = MySQLdb.connect(host="localhost", db="logging", user="******", passwd="choooh1031", charset="utf8")
Esempio n. 37
0
def initialize():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(outpin, GPIO.OUT)

    wiringpi.wiringPiSetupGpio()
    wiringpi.softToneCreate(outpin)
Esempio n. 38
0
 def set_pwm(self):
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(self.gpio_pin, 2)
     wiringpi.pwmSetMode(0)
     wiringpi.pwmSetRange(self.range)
     wiringpi.pwmWrite(self.gpio_pin, 0)
Esempio n. 39
0
import wiringpi2 as wiringpi
from time import *

MUSIC = 18
PWM = 2

wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(18, 2)  #sets MUSIC to pwm
wiringpi.pwmWrite(18, 0)
wiringpi.pwmWrite(18, 901)
sleep(1)
wiringpi.pwmWrite(18, 902)
sleep(1)
wiringpi.pwmWrite(18, 903)
sleep(1)
wiringpi.pwmWrite(18, 904)
sleep(1)
wiringpi.pwmWrite(18, 0)
Esempio n. 40
0
 def __init__(self):
     wp.wiringPiSetupGpio()
     wp.pinMode(22, 0)
     wp.pullUpDnControl(22, 2)
Esempio n. 41
0
import pygame, time, os, random
import wiringpi2 as io
from copy import deepcopy

pygame.init()  # initialise graphics interface
os.environ['SDL_VIDEO_WINDOW_POS'] = 'center'
pygame.display.set_caption("Control Central")
pygame.event.set_allowed(None)
pygame.event.set_allowed([pygame.KEYDOWN, pygame.QUIT, pygame.MOUSEBUTTONDOWN])
screen = pygame.display.set_mode([1050, 480], 0, 32)
textHeight = 22
font = pygame.font.Font(None, textHeight)
random.seed()

try:
    io.wiringPiSetupGpio()
except:
    print "start IDLE with 'gksudo idle' from command line"
    os._exit(1)

plugState = [False for n in range(0, 16)]
groupPins = [17, 17, 17, 17, 27, 27, 27, 27, 23, 23, 23, 23, 10, 10, 10, 10]
channelPins = [4, 18, 22, 24, 4, 18, 22, 24, 4, 18, 22, 24, 4, 18, 22, 24]
A_11Pin = 25
sendPin = 9
plugName = [
    "Lounge1", "Lounge2", "Dining Room", "Kitchen", "Bedroom 1", "Bedroom 2",
    "Bedroom 3", "Hall 1", "Landing", "Garage", "Porch", "Attic", "TV Lamp",
    "Kitchen Lamp", "Hall 2", "Computer Room"
]
plugPicture = pygame.image.load("images/plug.png").convert_alpha()
Esempio n. 42
0
def automatic():
    wiringpi.wiringPiSetupGpio()
    wiringpi.pinMode(17, 1)
    wiringpi.pinMode(27, 1)
    wiringpi.pinMode(22, 1)
    wiringpi.pinMode(5, 1)
    wiringpi.pinMode(6, 1)
    input = raw_input("run y/n")

    if input == "y":
        run = True
        wiringpi.digitalWrite(17, 0)
        wiringpi.digitalWrite(27, 0)
        wiringpi.digitalWrite(22, 0)
        wiringpi.digitalWrite(5, 0)
        wiringpi.digitalWrite(6, 0)
        while (run):
            try:
                wiringpi.digitalWrite(17, 1)
                sleep(0.004)
                wiringpi.digitalWrite(27, 1)
                sleep(0.004)
                wiringpi.digitalWrite(22, 1)
                sleep(0.004)
                wiringpi.digitalWrite(5, 1)
                sleep(0.004)
                wiringpi.digitalWrite(6, 1)
                print("HIGH")
                sleep(0.004)
                wiringpi.digitalWrite(17, 0)
                sleep(0.004)
                wiringpi.digitalWrite(27, 0)
                sleep(0.004)
                wiringpi.digitalWrite(22, 0)
                sleep(0.004)
                wiringpi.digitalWrite(5, 0)
                sleep(0.004)
                wiringpi.digitalWrite(6, 0)
                print("LOW")
                sleep(2)
                wiringpi.digitalWrite(17, 1)
                sleep(0.004)
                wiringpi.digitalWrite(27, 1)
                sleep(0.004)
                wiringpi.digitalWrite(22, 1)
                sleep(0.004)
                wiringpi.digitalWrite(5, 1)
                sleep(0.004)
                wiringpi.digitalWrite(6, 1)
                print("HIGH")
                sleep(0.004)
                wiringpi.digitalWrite(17, 0)
                sleep(0.004)
                wiringpi.digitalWrite(27, 0)
                sleep(0.004)
                wiringpi.digitalWrite(22, 0)
                sleep(0.004)
                wiringpi.digitalWrite(5, 0)
                sleep(0.004)
                wiringpi.digitalWrite(6, 0)
                print("LOW")
            except KeyboardInterrupt:
                run = False
                wiringpi.digitalWrite(17, 0)
                wiringpi.digitalWrite(27, 0)
                wiringpi.digitalWrite(22, 0)
                wiringpi.digitalWrite(5, 0)
                wiringpi.digitalWrite(6, 0)
                sleep(1)
                print("end")
Esempio n. 43
0
def setUpAllPins(pinConfig):
    wiringpi2.wiringPiSetupGpio()

    print("Loading GPIO pins...")
    for name, pin in pinConfig.items():
        setUpPin(name, pin)
Esempio n. 44
0
 def init_wiringPi( self ):
     wp.wiringPiSetupGpio()
     return
Esempio n. 45
0
import wiringpi2

#wiringpi2.wiringPiSetup() # For sequential pin numbering, one of these MUST be called before using IO functions
#wiringpi2.wiringPiSetupSys() # For /sys/class/gpio with GPIO pin numbering
#wiringpi2.wiringPiSetupGpio() # For GPIO pin numbering

wiringpi2.wiringPiSetupGpio()  # For GPIO pin numbering

led_output_port = 1

# MOTOR DRIVER PORTS

# enable A of the H-bridge
port_motor_left_pwm = 18

# input 1 of the H-bridge
port_motor_left_backward = 24

# input 2 of the H-bridge
port_motor_left_forward = 23

# enable B of the H-bridge
port_motor_right_pwm = 13

# input 3 of the H-bridge
port_motor_right_backward = 12

# input 4 of the H-bridge
port_motor_right_forward = 25

port_encoder_left_a = 19
Esempio n. 46
0
 def initialize(self):
     wiringpi2.wiringPiSetupGpio()
     wiringpi2.pinMode(port, wiringpi2.GPIO.INPUT)
Esempio n. 47
0
def automatic():
    wiringpi.wiringPiSetupGpio()
    wiringpi.pinMode(17, 1)
    wiringpi.pinMode(27, 1)
    wiringpi.pinMode(22, 1)
    wiringpi.pinMode(5, 1)
    wiringpi.pinMode(6, 1)

    TIMECONSTANT = 0.004
    cycles = 10000
    input = raw_input("run y/n")
    if input == "y":
        run = 0
        wiringpi.digitalWrite(17, 0)
        wiringpi.digitalWrite(27, 0)
        wiringpi.digitalWrite(22, 0)
        wiringpi.digitalWrite(5, 0)
        wiringpi.digitalWrite(6, 0)
        print("running {} cycles on all pins".format(cycles))

        while (run < cycles):
            try:
                wiringpi.digitalWrite(17, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(27, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(22, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(5, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(6, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(17, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(27, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(22, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(5, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(6, 0)
                print("HIGH")
                sleep(2)
                wiringpi.digitalWrite(17, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(27, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(22, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(5, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(6, 1)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(17, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(27, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(22, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(5, 0)
                sleep(TIMECONSTANT)
                wiringpi.digitalWrite(6, 0)
                print("LOW")
                sleep(TIMECONSTANT)
                run = run + 1

            except KeyboardInterrupt:
                run = cycles
                wiringpi.digitalWrite(17, 0)
                wiringpi.digitalWrite(27, 0)
                wiringpi.digitalWrite(22, 0)
                wiringpi.digitalWrite(5, 0)
                wiringpi.digitalWrite(6, 0)
                sleep(1)
                print("User ended premature")
    return
def setup():
    wiringpi2.wiringPiSetupGpio() # For GPIO pin numbering
    
    CommandeMoteurs(0, 0, tensionBatterie)
        #
        f = open('GPSdata!_Saiko00.txt', 'w')
        f.write("\n")
        f.write(str(time.ctime()) + "\n")
        check = 0
        #
        speedPrev = 0
        newTrack = 0
        goalComponentPrev = 0
        listPosition = [LatLon(0, 0)]
        #
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(LED_RED, GPIO.OUT)
        GPIO.setup(LED_GREEN, GPIO.OUT)
        GPIO.setup(LED_BLUE, GPIO.OUT)
        pi.wiringPiSetupGpio()
        pi.pinMode(SAIL_SERVO_PIN, 2)
        pi.pinMode(RUDDER_SERVO_PIN, 2)
        pi.pwmSetMode(0)
        pi.pwmSetRange(1024)
        pi.pwmSetClock(375)
        #

        sailValue = (SAIL_FULLCLOSE + SAIL_FULLOPEN) / 2
        if (SAIL_FULLCLOSE < 35 or SAIL_FULLOPEN > 55
                or SAIL_FULLCLOSE > SAIL_FULLOPEN):
            exit()
        sailCntl = SailController(sailValue)

        #
        time.sleep(30)
Esempio n. 50
0
    def __init__(self, player):
        """
        Class Initializer

        :param player: link to lockable MPD Client object used to communicate with MPD
        """
        ui.Scene.__init__(self)

        #setup LCD Light (GPIO 18 (PWM) is connected to LCD Backlight
        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(18,
                         wiringpi.PWM_OUTPUT)  # pwm only works on GPIO port 18

        # prepare signal handler for Ctrl+C and SIGTERM
        signal.signal(signal.SIGINT, self.signal_handler)
        signal.signal(signal.SIGTERM, self.signal_handler)

        # init MPD Player Interface
        self.player = player
        self.player.link_scene(self)

        # init last action timestamp
        self.last_action_ts = pygame.time.get_ticks()

        # load images
        self.img_prev = ui.get_image('rewind-icon_s')
        self.img_play = ui.get_image('play-icon_s')
        self.img_pause = ui.get_image('pause-icon_s')
        self.img_next = ui.get_image('forward-icon_s')

        label_height = ui.theme.current.label_height
        scrollbar_size = ui.SCROLLBAR_SIZE

        # create menu
        # create background image
        self.showing_splash = True  # remember we show splash screen image
        self.background = ui.ImageButton(
            ui.Rect(0, 16, 320, 215),
            ui.get_image('splash', '/home/pi/music/images/'))
        self.background.on_clicked.connect(self.button_click)
        self.add_child(self.background)

        # create label for currently playing song
        self.now_playing = ui.Label(ui.Rect(0, 0, 320, label_height), '')
        self.add_child(self.now_playing)

        # create play control buttons (prev, play/pause, next)
        self.buttons_visible = False

        self.btn_prev = ui.ImageButton(ui.Rect(20, 88, 64, 64), self.img_prev)
        self.btn_prev.on_clicked.connect(self.button_click)
        self.btn_prev.hidden = True  # initially hidden
        self.add_child(self.btn_prev)

        self.playicon = True  # initially we show the play icon (False means show Pause Icon)
        self.btn_play = ui.ImageButton(ui.Rect(120, 88, 64, 64), self.img_play)
        self.btn_play.on_clicked.connect(self.button_click)
        self.btn_play.hidden = True  # initially hidden
        self.add_child(self.btn_play)

        self.btn_next = ui.ImageButton(ui.Rect(220, 88, 64, 64), self.img_next)
        self.btn_next.on_clicked.connect(self.button_click)
        self.btn_next.hidden = True  # initially hidden
        self.add_child(self.btn_next)

        # create progress bar
        self.progress_view = ui.ProgressView(ui.Rect(0, 231, 320, 9))
        self.add_child(self.progress_view)
        self.progress_view.hidden = True

        self.set_lcd_brightness(self.DIM_BRIGHT)  #light LCD