Ejemplo n.º 1
0
def init_PWM(_redPin = 23, _greenPin = 24, _bluePin = 25, _flashPin= 22, initDutyCycle = [100]*3, flashRate = 0): 
   global colorPins, colors, flashActive, flashPin 
 
   colorPins = [_redPin, _greenPin, _bluePin] #list for pins used in raspberry pi

   wiringpi2.wiringPiSetup() # Initialize using wiringPi pin numbering scheme   

   for dc in initDutyCycle: #Check for valid initial duty cycle
      if dc < 0 or dc > 255: return -1

   #Create intial PWM signals for input to LED strip
   for i in range(3):
      wiringpi2.softPwmCreate(colorPins[i], int(initDutyCycle[i]*100.0/255.0), 100)

   #Current RGB values of LED strip
   colors = list(initDutyCycle)

   #Create square wave for flashing beat
   flashPin = _flashPin
   wiringpi2.softToneCreate(flashPin)
   if flashRate != 0:
      wiringpi2.softToneWrite(flashPin, flashRate)
      flashActive = True
   else:
      wiringpi2.softToneStop(flashPin)
      flashActive = False

   #Use Colors.txt file to create list of preset color options
   readColorsFile()

   return 0
def set_pin_as_output(pin):
    """Set the specified pin as an output.

    :param pin: index of pin in cm.hardware.gpio_pins
    :type pin: int
    """
    if is_pin_pwm[pin]:
        wiringpi.softPwmCreate(cm.hardware.gpio_pins[pin], 0, _PWM_MAX)
    else:
        wiringpi.pinMode(cm.hardware.gpio_pins[pin], _GPIOASOUTPUT)
def set_pin_as_output(pin):
    """Set the specified pin as an output.

    :param pin: index of pin in cm.hardware.gpio_pins
    :type pin: int
    """
    if is_pin_pwm[pin]:
        wiringpi.softPwmCreate(cm.hardware.gpio_pins[pin], 0, _PWM_MAX)
    else:
        wiringpi.pinMode(cm.hardware.gpio_pins[pin], _GPIOASOUTPUT)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def __init__(self, r_pin, g_pin, b_pin):
     self.r_pin = r_pin
     self.b_pin = b_pin
     self.g_pin = g_pin
     self.r_pwm = wiringpi2.softPwmCreate(r_pin, 0, 100)
     self.g_pwm = wiringpi2.softPwmCreate(g_pin, 0, 100)
     self.b_pwm = wiringpi2.softPwmCreate(b_pin, 0, 100)
     self.red = 0
     self.green = 0
     self.blue = 0
     self.set(0,0,0)
Ejemplo n.º 6
0
 def __init__(self,p_pin,d1_pin,d2_pin):
     self.__speed = 0
     self.__p_pin = p_pin
     self.__d1_pin = d1_pin
     self.__d2_pin = d2_pin
     io1.pinMode(self.__d1_pin,1)
     io1.pinMode(self.__d2_pin,1)
     io1.pinMode(self.__p_pin,1)
     io1.softPwmCreate(self.__p_pin,0,100)
     io1.digitalWrite(self.__d1_pin,1)
     io1.digitalWrite(self.__d2_pin,1)
Ejemplo n.º 7
0
    def __init__(self,
                 pin=DEFAULT_PIN,
                 calibration_file=None,
                 smoothing=None,
                 wiringpi_obj=None,
                 zero_pin=None,
                 **kwargs):
        super(PWMCalibrator, self).__init__()

        if not SOFTPWM_SUPPORT and ((pin != WIRINGPI_PWM_PIN)
                                    or zero_pin != None):
            raise Exception(
                "No soft PWM support (is wiringpi2 installed?). Only pin 1 may be used."
            )

        self.pin = pin

        if wiringpi_obj is not None:
            self.wp = wiringpi_obj
        else:
            wiringpi.wiringPiSetup()

        # PWM: hardware or software?
        if (not SOFTPWM_SUPPORT) or (self.pin == WIRINGPI_PWM_PIN):
            wiringpi.pinMode(self.pin, wiringpi.GPIO.PWM_OUTPUT)
            self.pwm_write = wiringpi.pwmWrite
            self.pwm_max = PWM_MAX
        else:
            wiringpi.softPwmCreate(self.pin, 0, SOFT_PWM_MAX)
            self.pwm_write = wiringpi.softPwmWrite
            self.pwm_max = kwargs.get('soft_pwm_max', SOFT_PWM_MAX)

        # zero out any zero pins, as necessary
        # (this is used for bidirectional meters; by default the pi's pins
        # are in a high-impedence mode that will prevent adequate calibration)
        if zero_pin != None:
            if zero_pin == WIRINGPI_PWM_PIN:
                wiringpi.pinMode(zero_pin, wiringpi.GPIO.PWM_OUTPUT)
                wiringpi.pwmWrite(zero_pin, 0)
            else:
                wiringpi.softPwmCreate(zero_pin, 0, SOFT_PWM_MAX)
                wiringpi.softPwmWrite(zero_pin, 0)

        self.pwm_value = 0
        self.calibration = []
        if smoothing is True:
            self.smoothing = 0.005
        else:
            self.smoothing = smoothing

        if calibration_file is not None:
            self.calibration_file = calibration_file
        else:
            self.calibration_file = DEFAULT_CALIBRATION_FILENAME
Ejemplo n.º 8
0
 def __init__(self, r_pin, g_pin, b_pin):
     self.r_pin = r_pin
     self.b_pin = b_pin
     self.g_pin = g_pin
     self.r_pwm = wiringpi2.softPwmCreate(r_pin, 0, 100)
     self.g_pwm = wiringpi2.softPwmCreate(g_pin, 0, 100)
     self.b_pwm = wiringpi2.softPwmCreate(b_pin, 0, 100)
     self.red = 0
     self.green = 0
     self.blue = 0
     self.set(0, 0, 0)
Ejemplo n.º 9
0
 def camera(self, angle1, angle2):
     if angle1 < 0 or angle1 > 180 or angle2 < 0 or angle2 > 180:
         return False
     # TODO
     angle1 = int(127 + int(127 * float(angle1) / 180))
     angle2 = int(127 + int(127 * float(angle2) / 180))
     wiringpi2.pinMode(self.config.get("pin1_cam"), 1)
     wiringpi2.softPwmCreate(self.config.get("pin1_cam"), 0, 100)
     wiringpi2.softPwmWrite(self.config.get("pin1_cam"), angle1)
     wiringpi2.pinMode(self.config.get("pin2_cam"), 1)
     wiringpi2.softPwmCreate(self.config.get("pin2_cam"), 0, 100)
     wiringpi2.softPwmWrite(self.config.get("pin2_cam"), angle2)
     time.sleep(0.100)
Ejemplo n.º 10
0
def softPwm():
	print "SoftPwm Mode"

	wiringpi2.wiringPiSetup()
	wiringpi2.pinMode(PIN_TO_PWM,OUTPUT)
	wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters

	for time in range(0,4):
        	for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on
                	wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
                	wiringpi2.delay(10) # Delay for 0.2 seconds
        	for brightness in reversed(range(0,100)):
                	wiringpi2.softPwmWrite(PIN_TO_PWM,brightness)
                	wiringpi2.delay(10)
Ejemplo n.º 11
0
    def __init__(self, pid, default_value=None, max_value=None):
        super(GPIOPWMPin, self).__init__(pid)

        if default_value is None:
            self.default_value = self.DEFAULT_VALUE
        else:
            self.default_value = default_value

        if max_value is None:
            self.max_value = self.MAX_VALUE
        else:
            self.max_value = max_value

        wiringpi.wiringPiSetupPhys()
        wiringpi.softPwmCreate(pid, self.default_value, self.max_value)
Ejemplo n.º 12
0
def set_pin_as_output(pin):
    """Set the specified pin as an output.

    :param pin: index of pin in _GPIO_PINS
    :type pin: int
    """
    if _EXPORT_PINS and is_a_raspberryPI:
        # set pin as output for use in export mode
        subprocess.check_call([_GPIO_UTILITY_PATH, 'export',
                               str(_GPIO_PINS[pin]), 'out'])
    else:
        if is_pin_pwm[pin]:
            wiringpi.softPwmCreate(_GPIO_PINS[pin], 0, _PWM_MAX)
        else:
            wiringpi.pinMode(_GPIO_PINS[pin], _GPIOASOUTPUT)
Ejemplo n.º 13
0
def set_pin_as_output(pin):
    """Set the specified pin as an output.

    :param pin: index of pin in _GPIO_PINS
    :type pin: int
    """
    if _EXPORT_PINS and is_a_raspberryPI:
        # set pin as output for use in export mode
        subprocess.check_call(
            [_GPIO_UTILITY_PATH, 'export',
             str(_GPIO_PINS[pin]), 'out'])
    else:
        if is_pin_pwm[pin]:
            wiringpi.softPwmCreate(_GPIO_PINS[pin], 0, _PWM_MAX)
        else:
            wiringpi.pinMode(_GPIO_PINS[pin], _GPIOASOUTPUT)
Ejemplo n.º 14
0
	def __init__(self, pin=DEFAULT_PIN, calibration_file=None, smoothing=None, wiringpi_obj=None, zero_pin=None, **kwargs):
		super(PWMCalibrator, self).__init__()
		
		if not SOFTPWM_SUPPORT and ((pin!=WIRINGPI_PWM_PIN) or zero_pin!=None):
			raise Exception("No soft PWM support (is wiringpi2 installed?). Only pin 1 may be used.")

		self.pin = pin

		if wiringpi_obj is not None:
			self.wp = wiringpi_obj
		else:
			wiringpi.wiringPiSetup()
		
		# PWM: hardware or software?
		if (not SOFTPWM_SUPPORT) or (self.pin==WIRINGPI_PWM_PIN):
			wiringpi.pinMode(self.pin, wiringpi.GPIO.PWM_OUTPUT)
			self.pwm_write = wiringpi.pwmWrite
			self.pwm_max = PWM_MAX
		else:
			wiringpi.softPwmCreate(self.pin, 0, SOFT_PWM_MAX)
			self.pwm_write = wiringpi.softPwmWrite
			self.pwm_max = kwargs.get('soft_pwm_max', SOFT_PWM_MAX)		

		# zero out any zero pins, as necessary
		# (this is used for bidirectional meters; by default the pi's pins
		# are in a high-impedence mode that will prevent adequate calibration)
		if zero_pin!=None:
			if zero_pin==WIRINGPI_PWM_PIN:
				wiringpi.pinMode(zero_pin, wiringpi.GPIO.PWM_OUTPUT)
				wiringpi.pwmWrite(zero_pin, 0)
			else:
				wiringpi.softPwmCreate(zero_pin, 0, SOFT_PWM_MAX)
				wiringpi.softPwmWrite(zero_pin, 0)

		self.pwm_value = 0
		self.calibration = []
                if smoothing is True:
                        self.smoothing = 0.005
                else:	
		        self.smoothing = smoothing

		if calibration_file is not None:
			self.calibration_file = calibration_file
		else:
			self.calibration_file = DEFAULT_CALIBRATION_FILENAME
Ejemplo n.º 15
0
def setup():
    # use Gpio pin numbering
    # w.wiringPiSetupGpio()
    w.wiringPiSetupSys() # use the non-root mode. Needs to export pins via gpio first!

    # polarity pins are outputs:
    for pin in pins_pol:
        w.pinMode(pin, 1)           # defined as output 
        w.digitalWrite(pin,0)       # all output off

    # PWM pins:
    for pin in pins_pwm:
        w.softPwmCreate(pin,0,100)  #define pin as pwm output      

    # all magnets turned off
    magnet(0,0,0)
    magnet(1,0,0)
    magnet(2,0,0)
    magnet(3,0,0)
Ejemplo n.º 16
0
def io_init():
    global io_initialized
    if io_initialized:
        return

    wiringpi2.wiringPiSetupGpio()
    wiringpi2.pinMode(MODE, wiringpi2.GPIO.OUTPUT)
    wiringpi2.digitalWrite(MODE, LOW)
    wiringpi2.pwmSetMode(wiringpi2.GPIO.PWM_MODE_MS)
    wiringpi2.pwmSetRange(PWM_RANGE_HIGH)
    wiringpi2.pwmSetClock(2)
    wiringpi2.pinMode(AIN1, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(BIN1, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(AIN2, wiringpi2.GPIO.OUTPUT)
    wiringpi2.pinMode(BIN2, wiringpi2.GPIO.OUTPUT)
    wiringpi2.softPwmCreate(AIN2, PWM_RANGE_LOW, PWM_RANGE_HIGH)
    wiringpi2.softPwmCreate(BIN2, PWM_RANGE_LOW, PWM_RANGE_HIGH)

    io_initialized = True
Ejemplo n.º 17
0
def setup():
    GPIO.setmode(GPIO.BCM)
    wiringpi2.wiringPiSetupGpio()
    # Moters
    wiringpi2.pinMode(IN1, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN2, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN3, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN4, wiringpi2.GPIO.PWM_OUTPUT)
    # initialize stop
    wiringpi2.softPwmCreate(IN1, 100, 100)
    wiringpi2.softPwmCreate(IN2, 100, 100)
    wiringpi2.softPwmCreate(IN3, 100, 100)
    wiringpi2.softPwmCreate(IN4, 100, 100)
Ejemplo n.º 18
0
    def __init__(self):        
        self.drivePWMPin = 18
        self.drivePin1 = 23
        self.drivePin2 = 24
        
        self.steerPWMPin = 17
        self.steerPin1 = 27
        self.steerPin2 = 22

        wiringpi2.wiringPiSetupGpio()

        self.maxPwm = 50
        wiringpi2.pinMode(self.drivePin1, OUTPUT)
        wiringpi2.pinMode(self.drivePin2, OUTPUT)
        wiringpi2.pinMode(self.drivePWMPin, OUTPUT)
        wiringpi2.softPwmCreate(self.drivePWMPin, 0, self.maxPwm)

        wiringpi2.pinMode(self.steerPin1, OUTPUT)
        wiringpi2.pinMode(self.steerPin2, OUTPUT)
        wiringpi2.pinMode(self.steerPWMPin, OUTPUT)
Ejemplo n.º 19
0
    def __init__(self):
        self.drivePWMPin = 18
        self.drivePin1 = 23
        self.drivePin2 = 24

        self.steerPWMPin = 17
        self.steerPin1 = 27
        self.steerPin2 = 22

        wiringpi2.wiringPiSetupGpio()

        self.maxPwm = 50
        wiringpi2.pinMode(self.drivePin1, OUTPUT)
        wiringpi2.pinMode(self.drivePin2, OUTPUT)
        wiringpi2.pinMode(self.drivePWMPin, OUTPUT)
        wiringpi2.softPwmCreate(self.drivePWMPin, 0, self.maxPwm)

        wiringpi2.pinMode(self.steerPin1, OUTPUT)
        wiringpi2.pinMode(self.steerPin2, OUTPUT)
        wiringpi2.pinMode(self.steerPWMPin, OUTPUT)
Ejemplo n.º 20
0
def telmin():
    REF=3.3  # 5.p or 3.3
    mode=1
    w.wiringPiSetup()
    w.wiringPiSPISetup(0,1000000)
    w.pinMode(0,1)
    w.pinMode(2,1)
    w.pinMode(1,2)
    #w.softPwmCreate(1,0,100)
    w.softPwmCreate(2,0,100)

    w.digitalWrite(0,1)
    
    while 1:
        data1 = MCP3008(1)
        data7 = MCP3008(7)
        time.sleep(0.01)
        data11 = int(data1)-860;
        w.softPwmWrite(2,data11)
        data71 = int(((data7/20)*5.8)-225)
        w.pwmWrite(1,data71*10)
        print('%4.2f'%data11,'%4.2f'%data71,'%.2f'%(data1/1024*REF),"volt",'%.2f'%(data7/1024*REF),"volt")
Ejemplo n.º 21
0
def setup():
    GPIO.setmode(GPIO.BCM)
    wiringpi2.wiringPiSetupGpio()
    wiringpi2.pinMode(IN1, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN2, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN3, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN4, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.softPwmCreate(IN1, 0, 100)
    wiringpi2.softPwmCreate(IN2, 0, 100)
    wiringpi2.softPwmCreate(IN3, 0, 100)
    wiringpi2.softPwmCreate(IN4, 0, 100)
    GPIO.setup(spi_mosi, GPIO.OUT)
    GPIO.setup(spi_miso, GPIO.IN)
    GPIO.setup(spi_clk, GPIO.OUT)
    GPIO.setup(spi_ss, GPIO.OUT)
    GPIO.setup(sensor_switch, GPIO.OUT)
Ejemplo n.º 22
0
def setup():
    GPIO.setmode(GPIO.BCM)
    wiringpi2.wiringPiSetupGpio()
    # Moters
    wiringpi2.pinMode(IN1, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN2, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN3, wiringpi2.GPIO.PWM_OUTPUT)
    wiringpi2.pinMode(IN4, wiringpi2.GPIO.PWM_OUTPUT)
    # initialize stop
    wiringpi2.softPwmCreate(IN1, 100, 100)
    wiringpi2.softPwmCreate(IN2, 100, 100)
    wiringpi2.softPwmCreate(IN3, 100, 100)
    wiringpi2.softPwmCreate(IN4, 100, 100)
    # AD-converter
    GPIO.setup(spi_mosi, GPIO.OUT)
    GPIO.setup(spi_miso, GPIO.IN)
    GPIO.setup(spi_clk, GPIO.OUT)
    GPIO.setup(spi_ss, GPIO.OUT)
    GPIO.setup(sensorSwitch, GPIO.OUT)
    # parallel communication
    GPIO.setup(S0, GPIO.OUT)
    GPIO.setup(paraList[1:11], GPIO.IN)
    GPIO.output(S0, 0)
Ejemplo n.º 23
0
    def __init__(self):  
        wiringpi2.wiringPiSetupGpio() 
        
        self.redPin = 23 
        self.bluePin = 24 
        self.greenPin = 18 
        
        wiringpi2.pinMode(self.redPin, 1)
        wiringpi2.pinMode(self.bluePin, 1)
        wiringpi2.pinMode(self.greenPin, 1)
        wiringpi2.softPwmCreate(self.redPin,0,100) 
        wiringpi2.softPwmCreate(self.bluePin,0,100) 
        wiringpi2.softPwmCreate(self.greenPin,0,100) 
        
        self.redIsOn = False 
        self.blueIsOn = False 
        self.greenIsOn = False

        self.redLevel = 0
        self.blueLevel = 0
        self.greenLevel = 0

        print('Remote initiated.')
Ejemplo n.º 24
0
import wiringpi2 as wiringpi

#use Broadcom pin numbers
wiringpi.wiringPiSetupGpio()

SERVO_PIN = 25

# configure output on pin
wiringpi.pinMode(SERVO_PIN, 1)

# setup PWM 
wiringpi.softPwmCreate(SERVO_PIN, 0, 100)

while True:
  # increase duty cycle by 5, it will speed up the motor
  # or will increase LED brightness
  for i in range(5, 100, 5):
    wiringpi.softPwmWrite(SERVO_PIN, i)
    wiringpi.delay(500)

  # decrease duty cycle by 5, it will slow down the motor
  # or will decrease LED brightness
  for i in range(100, 5, -5):
    wiringpi.softPwmWrite(SERVO_PIN, i)
    wiringpi.delay(500)
Ejemplo n.º 25
0
#!/usr/bin/env python
# coding: Latin-1

# Load library functions we want
import SocketServer
import wiringpi2 as wiringpi

DRIVE_1 = 7
DRIVE_2 = 1
DRIVE_3 = 10
DRIVE_4 = 11

wiringpi.wiringPiSetup()
wiringpi.softPwmCreate(DRIVE_1, 0, 100)
wiringpi.softPwmWrite(DRIVE_1, 0)
wiringpi.softPwmCreate(DRIVE_2, 0, 100)
wiringpi.softPwmWrite(DRIVE_2, 0)
wiringpi.softPwmCreate(DRIVE_3, 0, 100)
wiringpi.softPwmWrite(DRIVE_3, 0)
wiringpi.softPwmCreate(DRIVE_4, 0, 100)
wiringpi.softPwmWrite(DRIVE_4, 0)

# Map of drives to pins
lDrives = [DRIVE_1, DRIVE_2, DRIVE_3, DRIVE_4]


# Function to set all drives off
def MotorOff():
    wiringpi.softPwmWrite(DRIVE_1, 0)
    wiringpi.softPwmWrite(DRIVE_2, 0)
    wiringpi.softPwmWrite(DRIVE_3, 0)
Ejemplo n.º 26
0
# Setup the various GPIO values, using the BCM numbers for now
SERVOA = 8
PWMA = 18
DRIVEA0 = 22
DRIVEA1 = 27
STANDBY = 23
PWMB = 4
DRIVEB0 = 24
DRIVEB1 = 25
A0 = False
A1 = False
B0 = False
B1 = False

#wiringpi2.softPwmCreate(SERVOA, 0, 100)
wiringpi2.softPwmCreate(PWMA, 0, 80)
wiringpi2.softPwmCreate(PWMB, 0, 80)

io.pinMode(DRIVEA0, io.OUTPUT)
io.pinMode(DRIVEA1, io.OUTPUT)
#io.pinMode(PWMA, io.PWM_OUTPUT)
io.pinMode(STANDBY, io.OUTPUT)
io.pinMode(DRIVEB0, io.OUTPUT)
io.pinMode(DRIVEB1, io.OUTPUT)
#io.pinMode(PWMB, io.PWM_OUTPUT)

# Set all the drives to 'off'
io.digitalWrite(DRIVEA0, A0)
io.digitalWrite(DRIVEA1, A1)
io.digitalWrite(STANDBY, io.HIGH)
io.digitalWrite(DRIVEB0, B0)
Ejemplo n.º 27
0
import RPi.GPIO as GPIO
import time
import wiringpi2

OUTPUT = 1

PIN_TO_PWM = 1

wiringpi2.wiringPiSetup()
wiringpi2.pinMode(PIN_TO_PWM, OUTPUT)
wiringpi2.softPwmCreate(
    PIN_TO_PWM, 0,
    100)  # Setup PWM using Pin, Initial Value and Range parameters

STEP = 2
DELAY = .5


def FlashDesk():
    for i in range(0, 5):
        for j in range(0, 100, STEP):
            wiringpi2.softPwmWrite(PIN_TO_PWM, j)
            wiringpi2.delay(50)

        for j in range(100, 0, (STEP * -1)):
            wiringpi2.softPwmWrite(PIN_TO_PWM, j)
            wiringpi2.delay(50)


wiringpi2.softPwmWrite(PIN_TO_PWM, 100)
while True:
Ejemplo n.º 28
0
import urllib2
import time
import wiringpi2 as wiringpi

wiringpi.wiringPiSetup()

# Initial LEDborg setup.
pRed = 0
pGreen = 2
pBlue = 3

red = 0
green = 0
blue = 0

wiringpi.softPwmCreate(pRed, 0, 100)
wiringpi.softPwmCreate(pGreen, 0, 100)
wiringpi.softPwmCreate(pBlue, 0, 100)

wiringpi.softPwmWrite(pRed, 0)
wiringpi.softPwmWrite(pGreen, 0)
wiringpi.softPwmWrite(pBlue, 0)

LED_MAX = 100

# User-edit Variables
delay = 3600
fileUrl = 'http://ftp.iinet.net.au/1mb.dat'
fileSize = 1048.576
speedtest = 0
maxSpeed = 1500.0
Ejemplo n.º 29
0
	def process_change(self, color, value):
		value = int(value)
		pin = 0
		if color == 'r':
			pin = red
		elif color == 'g':
			pin = green
		elif color == 'b':
			pin = blue
		if pin != 0 and value >= 0 and value <= 100:
			wpi.softPwmWrite(pin, value)


#Create a web server and define the handler to manage the
#incoming request
try:
	wpi.wiringPiSetup()
	wpi.softPwmCreate(red, 0, 100)
	wpi.softPwmCreate(green, 0, 100)
	wpi.softPwmCreate(blue, 0, 100)
	server = HTTPServer(('', PORT_NUMBER), reqHandler)
	print 'Started pwm_server on port ' , PORT_NUMBER
	server.serve_forever()

except KeyboardInterrupt:
	print '^C received, shutting down the web server'
	wpi.softPwmWrite(red, 0)
	wpi.softPwmWrite(green, 0)
	wpi.softPwmWrite(blue, 0)
	server.socket.close()
Ejemplo n.º 30
0
        LCD_LOCK.release()

# MAIN

# pin config
IO.pinMode(REDPIN, IO.OUTPUT)
IO.pinMode(YELPIN, IO.OUTPUT)
IO.pinMode(GRNPIN, IO.OUTPUT)
IO.pinMode(SRNPIN, IO.OUTPUT)
IO.pinMode(BTNPIN, IO.INPUT)

# audio, maps to existing pwm channel for line out audio jack
IO.pinMode(AUDIOPIN, IO.PWM_OUTPUT)

# Set PWM range to 100 (duty cycle can be 0-100)
wiringpi.softPwmCreate(REDPIN, 0, 100)
wiringpi.softPwmCreate(YELPIN, 0, 100)
wiringpi.softPwmCreate(GRNPIN, 0, 100)

lcd_init()

# Siren state machine functions
def siren_on (fsm):
    """Turn on Siren"""
    IO.digitalWrite(SRNPIN, IO.HIGH)
    time.sleep(1.7)

def siren_off (fsm):
    """Turn off Siren"""
    IO.digitalWrite(SRNPIN, IO.LOW)
    time.sleep(0.5)
Ejemplo n.º 31
0
# Libraries
import time
import wiringpi2 as wiringpi
import psutil
import atexit

# WiringPi setup
wiringpi.wiringPiSetup()
 
# Setup the LedBorg GPIO pins
PIN_RED = 0
PIN_GREEN = 2
PIN_BLUE = 3
LED_MAX = 100
 
wiringpi.softPwmCreate(PIN_RED,   0, LED_MAX)
wiringpi.softPwmCreate(PIN_GREEN, 0, LED_MAX)
wiringpi.softPwmCreate(PIN_BLUE,  0, LED_MAX)
wiringpi.softPwmWrite(PIN_RED,   0)
wiringpi.softPwmWrite(PIN_GREEN, 0)
wiringpi.softPwmWrite(PIN_BLUE,  0)
 
# A function to set the LedBorg colours
def SetLedBorg(red, green, blue):
    wiringpi.softPwmWrite(PIN_RED,   int(red   * LED_MAX))
    wiringpi.softPwmWrite(PIN_GREEN, int(green * LED_MAX))
    wiringpi.softPwmWrite(PIN_BLUE,  int(blue  * LED_MAX))
 
# A function to turn the LedBorg off
def LedBorgOff():
    SetLedBorg(0, 0, 0)
Ejemplo n.º 32
0
print "Setting GPIO"
gpio.wiringPiSetupGpio()

#Establish use of pins
GPIO.setup(Trig, GPIO.OUT) #pin of HC-SR04
GPIO.setup(Echo, GPIO.IN) #pin of HC-SR04

gpio.pinMode(17,1) #LPOWER PWM
gpio.pinMode(18,1) #RPOWER PWM

gpio.pinMode(22,1) #DIR
gpio.pinMode(23,1) #DIR


gpio.softPwmCreate(17,0,100)
gpio.softPwmCreate(18,0,100)
print "GPIO Ok"

print"Waiting for connection"
connection, clientAddress = server.accept()

def saveInFile(right, left, InFront, back):
	#Open File and Save info
	fo = open("info.txt", "wb")
	strWrite = "RIGHT: " + str(right)+ "\n" + "LEFT: " + str(left) +"\n" +"FRONT: " + str(InFront) +"\n" + "BACK: " +str(back)
	fo.write(strWrite)
	

def getDistance():   
	   GPIO.output(Trig, False) 
Ejemplo n.º 33
0
#Practica 2 - Control de Servos (Version en Python con control por teclas)
#Grupo 5 
import wiringpi2
from tkinter import *

wiringpi2.wiringPiSetup() #hacemos setup con los valores de
#Elegimos el modo OUTPUT (1) para ambos pines 0 y 1 
wiringpi2.pinMode(0,1)
wiringpi2.pinMode(1,1)
#creamos el PWM en pin 1 y 0 con rango 100 y valor inicial 0
wiringpi2.softPwmCreate(0,0,100) 
wiringpi2.softPwmCreate(1,0,100)

#Definimos funciones para 4 direcciones de movimiento 
# El valor de bloqueo de posicion es 15 y menor de esto gira en sentido opuesto a horario
# y mayor que 15 gira en sentido horario.
def adelante():
    wiringpi2.softPwmWrite(1,14)
    wiringpi2.softPwmWrite(0,16)
def parar():
    wiringpi2.softPwmWrite(1,0)
    wiringpi2.softPwmWrite(0,0)
def derecha():
    wiringpi2.softPwmWrite(1,16)
    wiringpi2.softPwmWrite(0,16)
def izquierda():
    wiringpi2.softPwmWrite(1,14)
    wiringpi2.softPwmWrite(0,14)
def atras():
    wiringpi2.softPwmWrite(0,14)
    wiringpi2.softPwmWrite(1,16)
Ejemplo n.º 34
0
redFront = 6
greenFront = 7
blueFront = 8
wiringpi2.wiringPiSetup()
wiringpi2.pinMode(redRight, output)
wiringpi2.pinMode(blueRight, output)
wiringpi2.pinMode(greenRight, output)
wiringpi2.pinMode(redLeft, output)
wiringpi2.pinMode(blueLeft, output)
wiringpi2.pinMode(greenLeft, output)
wiringpi2.pinMode(redFront, output)
wiringpi2.pinMode(blueFront, output)
wiringpi2.pinMode(greenFront, output)


wiringpi2.softPwmCreate(redRight, 0, 100)
wiringpi2.softPwmCreate(blueRight, 0, 100)
wiringpi2.softPwmCreate(greenRight, 0, 100)
wiringpi2.softPwmCreate(redLeft, 0, 100)
wiringpi2.softPwmCreate(blueLeft, 0, 100)
wiringpi2.softPwmCreate(greenLeft, 0, 100)
wiringpi2.softPwmCreate(redFront, 0, 100)
wiringpi2.softPwmCreate(blueFront, 0, 100)
wiringpi2.softPwmCreate(greenFront, 0, 100)


def total(b):
    wiringpi2.softPwmWrite(redLeft, b)
    wiringpi2.softPwmWrite(greenLeft, b)
    wiringpi2.softPwmWrite(blueLeft, b)
    wiringpi2.softPwmWrite(redRight, b)
Ejemplo n.º 35
0
    return ip_addr

# MAIN

# pin config
IO.pinMode(REDPIN, IO.OUTPUT)
IO.pinMode(YELPIN, IO.OUTPUT)
IO.pinMode(GRNPIN, IO.OUTPUT)
IO.pinMode(SRNPIN, IO.OUTPUT)
IO.pinMode(BTNPIN, IO.INPUT)

# audio, maps to existing pwm channel for line out audio jack
IO.pinMode(AUDIOPIN, IO.PWM_OUTPUT)

# Set PWM range to 100 (duty cycle can be 0-100)
wiringpi.softPwmCreate(REDPIN, 0, 100)
wiringpi.softPwmCreate(YELPIN, 0, 100)
wiringpi.softPwmCreate(GRNPIN, 0, 100)

LCD = Lcd(LCD_ROWS, LCD_CHARS, LCD_BITS, PIN_LCD_RS, PIN_LCD_E, PINS_LCD_DB)
SPEECH = Speech()

# Siren state machine functions
def siren_on (fsm):
    """Turn on Siren"""
    IO.digitalWrite(SRNPIN, IO.HIGH)
    time.sleep(1.7)

def siren_off (fsm):
    """Turn off Siren"""
    IO.digitalWrite(SRNPIN, IO.LOW)
Ejemplo n.º 36
0
def setPinConfig(EN, INA, INB):
    wiringpi.pinMode(EN, OUTPUT)
    wiringpi.pinMode(INA, OUTPUT)
    wiringpi.pinMode(INB, OUTPUT)
    wiringpi.softPwmCreate(EN, 0, 255)
Ejemplo n.º 37
0
	def __init__(self, pin): 
		self.pin = pin
		self.mode = self.SOFT
		wiringpi2.pinMode(self.pin,self.SOFT_PWM_OUTPUT)
		wiringpi2.softPwmCreate(self.pin, 0, 100) # Whats with the reverse Direction?? 
Ejemplo n.º 38
0
import wiringpi2
import sys

OUTPUT = 1
PIN_TO_PWM = 1  # pin 1 to output pwm

# wiringpi2.wiringPiSetup()
wiringpi2.wiringPiSetupPhys()
wiringpi2.pinMode(PIN_TO_PWM, OUTPUT)
wiringpi2.softPwmCreate(PIN_TO_PWM, 0, 100)

time = wiringpi2.millis()
print "----------milliseconds-------------"
print time
print "-----------------------------------"
time = wiringpi2.micros()
print "----------microseconds-------------"
print time
print "-----------------------------------"
Ejemplo n.º 39
0
# import the necessary packages
from collections import deque
import numpy as np
#import argparse
import json
#import imutils
import cv2
# Import PWM library
import wiringpi2
OUTPUT=1
PIN_TO_PWM = 30
wiringpi2.wiringPiSetup()
wiringpi2.pinMode(PIN_TO_PWM,OUTPUT)
wiringpi2.digitalWrite(PIN_TO_PWM,1)
wiringpi2.softPwmCreate(PIN_TO_PWM,0,1023)
min=10000000000
#greenLower = (29, 86, 6)
#greenUpper = (64, 255, 255)
greenLower = np.array([75,100,100])
greenUpper = np.array([140,255,255])
camera = cv2.VideoCapture(0)
camera.set(3,640)
camera.set(3,480)
minlist=[]
print camera.get(cv2.CAP_PROP_FRAME_WIDTH)
print camera.get(cv2.CAP_PROP_FRAME_HEIGHT)

while True:
	# grab the current frame
	(grabbed, frame) = camera.read()
	hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
Ejemplo n.º 40
0
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        wiringpi2.wiringPiSetupGpio()

        self.redPin = 23
        self.bluePin = 24
        self.greenPin = 18

        wiringpi2.pinMode(self.redPin, 1)
        wiringpi2.pinMode(self.bluePin, 1)
        wiringpi2.pinMode(self.greenPin, 1)
        wiringpi2.softPwmCreate(self.redPin, 0, 100)
        wiringpi2.softPwmCreate(self.bluePin, 0, 100)
        wiringpi2.softPwmCreate(self.greenPin, 0, 100)

        self.checkBoxBox = gtk.HBox(False, 0)
        self.sliderBox = gtk.HBox(False, 0)
        self.bigBox = gtk.VBox(False, 0)

        self.window.set_border_width(50)
        self.red = gtk.CheckButton("Red", False)
        self.red.connect("toggled", self.buttonToggled, "red")
        self.green = gtk.CheckButton("Green", False)
        self.green.connect("toggled", self.buttonToggled, "green")
        self.blue = gtk.CheckButton("Blue", False)
        self.blue.connect("toggled", self.buttonToggled, "blue")
        self.window.connect("delete-event", self.cleanupHandler)

        self.window.set_title("Magical Light Box")

        self.redIsOn = False
        self.blueIsOn = False
        self.greenIsOn = False
        self.redSlider = gtk.VScale()
        self.greenSlider = gtk.VScale()
        self.blueSlider = gtk.VScale()

        buttonList = [self.red, self.green, self.blue]
        sliderList = [self.redSlider, self.greenSlider, self.blueSlider]
        for button in buttonList:
            self.checkBoxBox.pack_start(button, False, False, 10)
            button.show()

        for slider in sliderList:
            slider.set_range(0, 100)
            slider.set_inverted(True)
            slider.set_round_digits(0)
            slider.set_increments(1, 100)
            slider.set_size_request(35, 150)

        self.redSlider.connect("value-changed", self.sliderMoved, "red")
        self.greenSlider.connect("value-changed", self.sliderMoved, "green")
        self.blueSlider.connect("value-changed", self.sliderMoved, "blue")

        for slider in sliderList:  #I can probs merge these loops
            self.sliderBox.pack_start(slider, True, True, 10)
            slider.show()

        self.bigBox.pack_start(self.checkBoxBox, False, False, 10)
        self.checkBoxBox.show()

        self.bigBox.pack_start(self.sliderBox, False, False, 10)
        self.sliderBox.show()
        self.window.add(self.bigBox)
        self.bigBox.show()
        self.window.show()
Ejemplo n.º 41
0
# -*- coding: utf-8 -*-
import sys
import wiringpi2
import time

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

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

RANGE = 100 # PWMに指定する値の最大値

# softPwmの設定 
wiringpi2.softPwmCreate(port, 0, RANGE)  # ポート、初期値、最大値

SLEEP_TIME = 0.01

val = 0
while True:
    try:
        for pw in range(100):
            wiringpi2.softPwmWrite(port, pw)
            time.sleep(SLEEP_TIME)
        for pw in range(100-1, 0-1, -1):
            wiringpi2.softPwmWrite(port, pw)
            time.sleep(SLEEP_TIME)
    except KeyboardInterrupt:
        break
    except:
 def __init__(self): 
     self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
     wiringpi2.wiringPiSetupGpio() 
     
     self.redPin = 23 
     self.bluePin = 24 
     self.greenPin = 18 
     
     wiringpi2.pinMode(self.redPin, 1)
     wiringpi2.pinMode(self.bluePin, 1)
     wiringpi2.pinMode(self.greenPin, 1)
     wiringpi2.softPwmCreate(self.redPin,0,100) 
     wiringpi2.softPwmCreate(self.bluePin,0,100) 
     wiringpi2.softPwmCreate(self.greenPin,0,100) 
     
     self.checkBoxBox=gtk.HBox(False,0) 
     self.sliderBox=gtk.HBox(False,0) 
     self.bigBox=gtk.VBox(False,0) 
     
     self.window.set_border_width(50) 
     self.red=gtk.CheckButton("Red",False) 
     self.red.connect("toggled",self.buttonToggled, "red") 
     self.green=gtk.CheckButton("Green",False) 
     self.green.connect("toggled",self.buttonToggled, "green") 
     self.blue=gtk.CheckButton("Blue",False) 
     self.blue.connect("toggled",self.buttonToggled, "blue") 
     self.window.connect("delete-event", self.cleanupHandler) 
     
     self.window.set_title("Magical Light Box") 
     
     self.redIsOn = False 
     self.blueIsOn = False 
     self.greenIsOn = False
     self.redSlider = gtk.VScale() 
     self.greenSlider = gtk.VScale() 
     self.blueSlider = gtk.VScale() 
     
     buttonList=[self.red,self.green,self.blue] 
     sliderList=[self.redSlider,self.greenSlider,self.blueSlider] 
     for button in buttonList: 
         self.checkBoxBox.pack_start(button,False,False,10) 
         button.show() 
         
     for slider in sliderList: 
         slider.set_range(0,100) 
         slider.set_inverted(True) 
         slider.set_round_digits(0) 
         slider.set_increments(1,100) 
         slider.set_size_request(35,150) 
         
     self.redSlider.connect("value-changed", self.sliderMoved , "red") 
     self.greenSlider.connect("value-changed", self.sliderMoved , "green") 
     self.blueSlider.connect("value-changed", self.sliderMoved , "blue") 
     
     for slider in sliderList: #I can probs merge these loops
         self.sliderBox.pack_start(slider,True,True,10) 
         slider.show() 
         
     self.bigBox.pack_start(self.checkBoxBox,False,False,10) 
     self.checkBoxBox.show() 
     
     self.bigBox.pack_start(self.sliderBox,False,False,10) 
     self.sliderBox.show() 
     self.window.add(self.bigBox) 
     self.bigBox.show() 
     self.window.show() 
Ejemplo n.º 43
0
#Practica 2 - Control de Servos (Version en Python con control por teclas)
#Grupo 5
import wiringpi2
from tkinter import *

wiringpi2.wiringPiSetup()  #hacemos setup con los valores de
#Elegimos el modo OUTPUT (1) para ambos pines 0 y 1
wiringpi2.pinMode(0, 1)
wiringpi2.pinMode(1, 1)
#creamos el PWM en pin 1 y 0 con rango 100 y valor inicial 0
wiringpi2.softPwmCreate(0, 0, 100)
wiringpi2.softPwmCreate(1, 0, 100)


#Definimos funciones para 4 direcciones de movimiento
# El valor de bloqueo de posicion es 15 y menor de esto gira en sentido opuesto a horario
# y mayor que 15 gira en sentido horario.
def adelante():
    wiringpi2.softPwmWrite(1, 14)
    wiringpi2.softPwmWrite(0, 16)


def parar():
    wiringpi2.softPwmWrite(1, 0)
    wiringpi2.softPwmWrite(0, 0)


def derecha():
    wiringpi2.softPwmWrite(1, 16)
    wiringpi2.softPwmWrite(0, 16)
Ejemplo n.º 44
0
# This is not really necessary for our purposes

# Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm
# softPwm uses a fixed frequency
import wiringpi2 as wpi

MODE = 1 # output mode

PIN = 1

wpi.wiringPiSetup()
wpi.pinMode(PIN, MODE)
wpi.softPwmCreate(PIN, 0, 100) # Setup PWM using Pin, Initial Value and Range parameters
print("PWM setup of pin {0} complete".format(PIN))

wpi.softPwmWrite(PIN, 25) # 25 is the duty cycle, must be between 0 and Range

while True:
	pass
Ejemplo n.º 45
0
pin6 = 6
pin7 = 7
pin8 = 8
wiringpi2.wiringPiSetup()
wiringpi2.pinMode(pin0,output)
wiringpi2.pinMode(pin1,output)
wiringpi2.pinMode(pin2,output)
wiringpi2.pinMode(pin3,output)
wiringpi2.pinMode(pin4,output)
wiringpi2.pinMode(pin5,output)
wiringpi2.pinMode(pin6,output)
wiringpi2.pinMode(pin7,output)
wiringpi2.pinMode(pin8,output)


wiringpi2.softPwmCreate(pin0,0,100)
wiringpi2.softPwmCreate(pin1,0,100)
wiringpi2.softPwmCreate(pin2,0,100)
wiringpi2.softPwmCreate(pin3,0,100)
wiringpi2.softPwmCreate(pin4,0,100)
wiringpi2.softPwmCreate(pin5,0,100)
wiringpi2.softPwmCreate(pin6,0,100)
wiringpi2.softPwmCreate(pin7,0,100)
wiringpi2.softPwmCreate(pin8,0,100)

while True:
    color = raw_input("Please enter a color: ")
    if color == "blue":
        myChar = raw_input("Please enter a number between 0 and 100: ")
        for brightness in range(int(myChar)):
            wiringpi2.softPwmWrite(pin1,brightness)
Ejemplo n.º 46
0
DRIVE_4 = 11    # GPIO 7


# Map of functions to drive pins
leftDrive = DRIVE_1                     # Drive number for left motor
rightDrive = DRIVE_4                    # Drive number for right motor
penDrive = DRIVE_3                      # Drive number for pen solenoid

# my adaptation based on forum post and leftward tracking!!!
# Set the drive power for both motors, 1 to 100
leftDriveLevel  = 100                    # PWM drive for the left motor when on
rightDriveLevel = 74                   # PWM drive for the right motor when on

# Setup the software PWMs for 0 to 100
wiringpi.wiringPiSetup()
wiringpi.softPwmCreate(leftDrive, 0, 100)
wiringpi.softPwmWrite(leftDrive, 0)
wiringpi.softPwmCreate(rightDrive, 0, 100)
wiringpi.softPwmWrite(rightDrive, 0)

# Setup the solenoid drive pin
wiringpi.pinMode(penDrive, 1)           # Set as an output pin

# Functions for the robot to perform
def MoveForward(n):
    """Move forward for 'n' seconds"""
    wiringpi.softPwmWrite(leftDrive, leftDriveLevel)
    wiringpi.softPwmWrite(rightDrive, rightDriveLevel)
    time.sleep(n)
    wiringpi.softPwmWrite(leftDrive, 0)
    wiringpi.softPwmWrite(rightDrive, 0)
Ejemplo n.º 47
0
# softPwm uses a fixed frequency
import wiringpi2

OUTPUT = 1

# GPIO17 = GPIO_GEN0 = P1.11, connecting a red led
PIN_TO_PWM = 0

wiringpi2.wiringPiSetup()
wiringpi2.pinMode(PIN_TO_PWM,OUTPUT)
wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters

for time in range(0,4):
        for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on
                wiringpi2.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle
                wiringpi2.delay(10) # Delay for 0.2 seconds
        for brightness in reversed(range(0,100)):
                wiringpi2.softPwmWrite(PIN_TO_PWM,brightness)
                wiringpi2.delay(10)
Ejemplo n.º 48
0
 def GPIOsetup(self):
   wiringpi2.wiringPiSetupPhys()
   wiringpi2.softPwmCreate(PWM_PIN_ENA,ON_TIME1,RANGE)
   wiringpi2.softPwmCreate(PWM_PIN_ENB,ON_TIME2,RANGE)
   for gpio in self.pins:
     wiringpi2.pinMode(gpio,OUT)