コード例 #1
0
ファイル: rgb_led.py プロジェクト: pdsherman/RaspberryPi
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)
コード例 #3
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)
コード例 #4
0
ファイル: motor.py プロジェクト: nielsdb/zeppelin
 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)
コード例 #5
0
ファイル: rgbled.py プロジェクト: dwblair/py-gaugette
 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)
コード例 #6
0
ファイル: motor_lib.py プロジェクト: cheetahray/Shanghai
 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)
コード例 #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
コード例 #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)
コード例 #9
0
ファイル: Camera.py プロジェクト: hackEns/Jarvis
 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)
コード例 #10
0
ファイル: softPwm.py プロジェクト: masterky/Python-RCCarRepo
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)
コード例 #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)
コード例 #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)
コード例 #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)
コード例 #14
0
ファイル: __init__.py プロジェクト: sbma44/pwm_calibrate
	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
コード例 #15
0
ファイル: gpio.py プロジェクト: ledo0071/rpi-ferro-vis
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)
コード例 #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
コード例 #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)
コード例 #18
0
ファイル: car.py プロジェクト: derekhe/self-driving-car
    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)
コード例 #19
0
ファイル: car.py プロジェクト: houcy/self-driving-car-1
    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)
コード例 #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")
コード例 #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)
コード例 #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)
コード例 #23
0
ファイル: Remote.py プロジェクト: ayerobot/magical-light-box
    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.')
コード例 #24
0
ファイル: pwm.py プロジェクト: lukaszo/rpitips-examples
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)
コード例 #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)
コード例 #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)
コード例 #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:
コード例 #28
0
ファイル: pingborg.py プロジェクト: vSanjo/pingborg
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
コード例 #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()
コード例 #30
0
ファイル: xfd.py プロジェクト: JKrag/extremefeedbacklamp
        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)
コード例 #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)
コード例 #32
0
ファイル: Server.py プロジェクト: lgutie16/Python
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) 
コード例 #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)
コード例 #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)
コード例 #35
0
ファイル: xfd.py プロジェクト: dvaske/extremefeedbacklamp
    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)
コード例 #36
0
def setPinConfig(EN, INA, INB):
    wiringpi.pinMode(EN, OUTPUT)
    wiringpi.pinMode(INA, OUTPUT)
    wiringpi.pinMode(INB, OUTPUT)
    wiringpi.softPwmCreate(EN, 0, 255)
コード例 #37
0
ファイル: Servo.py プロジェクト: masterky/Python-RCCarRepo
	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?? 
コード例 #38
0
ファイル: time.py プロジェクト: Match-Yang/WiringCB-python
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 "-----------------------------------"
コード例 #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)
コード例 #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()
コード例 #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:
コード例 #42
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() 
コード例 #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)
コード例 #44
0
ファイル: pwm.py プロジェクト: Harry73/IGVC2017
# 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
コード例 #45
0
ファイル: light2.py プロジェクト: EPHorizon/Project_Terreo
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)
コード例 #46
0
ファイル: TurtleBorgPwm.py プロジェクト: kstolzenberg/drawBot
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)
コード例 #47
0
ファイル: pwm.py プロジェクト: tomxue/Pi___LED-control
# 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)
コード例 #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)