예제 #1
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)
예제 #2
0
def speed(left, right):
	left_a = GPIO.LOW
	left_b = GPIO.LOW
	left_pwm = abs(left)

	right_a = GPIO.LOW
	right_b = GPIO.LOW
	right_pwm =abs(right)

	if left < 0:
		left_a = GPIO.HIGH
	elif left > 0:
		left_b = GPIO.HIGH
	
	if right < 0:
		right_a = GPIO.HIGH
	elif right > 0:
		right_b = GPIO.HIGH

	if(left_pwm > 1):
		left_pwm = MAX_SPEED
	else:
		left_pwm = int(left_pwm*MAX_SPEED)
	if right_pwm > 1:
		right_pwm = MAX_SPEED
	else:
		right_pwm = int(right_pwm*MAX_SPEED)
	
	GPIO.output(LEFT_MOTOR_A, left_a)
	GPIO.output(LEFT_MOTOR_B, left_b)
	GPIO.output(RIGHT_MOTOR_A, right_a)
	GPIO.output(RIGHT_MOTOR_B, right_b)
	wiringpi.pwmWrite(LEFT_MOTOR_PWM, left_pwm)
	wiringpi.pwmWrite(RIGHT_MOTOR_PWM, right_pwm)
예제 #3
0
    def _playLoop(self, freq, music):
        divisor = (19.2*(10**3))/freq
        Music = import_module(music)

        wiringpi2.pwmSetClock(int(divisor))

        for note, beat in Music.melody:
            if note == ' ':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
            else:
                period, dutyCycle = self._calcParams(note)
                wiringpi2.pwmSetRange(period)
                wiringpi2.pwmWrite(self.SPEAKER, dutyCycle)

            wiringpi2.delay(Music.tempo*beat)

            if note[len(note)-1:] == ':':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(Music.tempo)
            elif note[len(note)-1:] == ';':
                wiringpi2.pwmWrite(self.SPEAKER, 0)
                wiringpi2.delay(int(Music.tempo/2))

        # Make sure that music stop
        wiringpi2.pwmWrite(self.SPEAKER, 0)
    def setFanSpeed(self):
        START = 650      #  this value is minimal pwm value that can start the fan, depends on the fan and transistors used
        LO_TEMP = 45.0   #  minimal temperature that turns on the fan 
        HI_TEMP = 55.0   #  when core temperature is higher than this the fan operates at full speed
        tempDiff = HI_TEMP - LO_TEMP
        
        temp = self.readtemp()

        if self.PWMmode:                                
          if temp < LO_TEMP:
              pwm = 0
          elif temp > HI_TEMP:
              pwm = 1023
          else:        
              pwm = (1023-START)/tempDiff * temp - ((1023-START)/tempDiff)*LO_TEMP + START
              pwm = int(pwm)
          wiringpi2.pwmWrite(1, pwm)
          return pwm
        
        elif not self.PWMmode:
          if self.fanRunning:
            if temp <= LO_TEMP:
              wiringpi2.digitalWrite(1, 0)
              self.fanRunning = False
              return(0)
            else: return(1023)
          elif not self.fanRunning:
            if temp > HI_TEMP:
              wiringpi2.digitalWrite(1, 1)
              self.fanRunning = True
              return(1023)
            else: return(0)
예제 #5
0
	def __init__(self):
		Pi_rev = wiringpi2.piBoardRev()	#@TODO: use this?
		self.GPIOS = {
			'internal_buzzer': 11,
			'latch': 7,
			'unlock_LED': 15,
			'deny_LED': 13,
			'buzzer': 12, 
			'doorStatus1': 19,
			'doorStatus2': 21,
		}
		
		#set up I/O pins
		wiringpi2.wiringPiSetupPhys()
		wiringpi2.pinMode(self.GPIOS['unlock_LED'], 1)
		wiringpi2.pinMode(self.GPIOS['deny_LED'], 1)
		wiringpi2.pinMode(self.GPIOS['latch'], 1)
		wiringpi2.pinMode(self.GPIOS['internal_buzzer'], 1)
		wiringpi2.pinMode(self.GPIOS['doorStatus1'], 0)
		wiringpi2.pinMode(self.GPIOS['doorStatus2'], 0)
		
		GPIO.setup(9, GPIO.IN)  
		GPIO.setup(10, GPIO.IN)  
		#GPIO.add_event_detect(9, GPIO.FALLING, callback=self.arm_security, bouncetime=300)
		#Set up Hardware PWM - Only works on GPIO 18 (Phys 12)
		wiringpi2.pwmSetMode(0)				# set PWM to markspace mode
		wiringpi2.pinMode(self.GPIOS['buzzer'], 2)      # set pin to PWM mode
		wiringpi2.pwmSetClock(750)   			# set HW PWM clock division (frequency)
		wiringpi2.pwmWrite(self.GPIOS['buzzer'], 0)
		
		proc = subprocess.Popen(['nfc-list'], stderr=subprocess.PIPE)
		result = proc.stderr.read()
		self.PN532 = False if 'Timeout' in result else True
		if not self.PN532:
			self.nfc = NFC.MFRC522()
예제 #6
0
def callback(data):
	rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)
	
	if data.data == 'a' :
		print "Left"
		wiringpi.digitalWrite(pin_dir[0], 1)
		wiringpi.digitalWrite(pin_dir[1], 0)
	elif data.data == 'w':
		print "Forward"
		wiringpi.digitalWrite(pin_dir[0], 1)
		wiringpi.digitalWrite(pin_dir[1], 1)
	elif data.data == 'd':
		print "Right"
		wiringpi.digitalWrite(pin_dir[0], 0)
		wiringpi.digitalWrite(pin_dir[1], 1)
	elif data.data == 's':
		print "Stop"
		wiringpi.digitalWrite(pin_dir[0], 0)
		wiringpi.digitalWrite(pin_dir[1], 0)

	global dt

	dt = dt + 100
	if dt > dtMax:
		dt = dtMin

	print(dt)
	wiringpi.pwmWrite(pin, dt)
예제 #7
0
	def rotate(self, speed):
                if speed > 0:
                        wiringpi.pwmWrite(1self.in3, speed)
                        GPIO.output(self.in1,GPIO.HIGH)
                        GPIO.output(self.in2,GPIO.LOW)
                elif speed = 0:
                        wiringpi.pwmWrite(1self.in3, speed)
                        GPIO.output(self.in1,GPIO.LOW)
                        GPIO.output(self.in2,GPIO.LOW)
예제 #8
0
파일: pi.py 프로젝트: nalajcie/gPhotoBooth
 def __init__(self, external_lights):
     super(Lights, self).__init__()
     self.external_lights = external_lights
     # hardware PWM led (and power off lights)
     wiringpi2.pinMode(self.LIGHTS_PIN, wiringpi2.GPIO.PWM_OUTPUT)
     wiringpi2.pwmWrite(self.LIGHTS_PIN, self.PWM_VAL_MAX)
     if self.external_lights:
         wiringpi2.pinMode(self.EXTERNAL_LIGHTS_PIN, wiringpi2.GPIO.OUTPUT)
         wiringpi2.digitalWrite(self.EXTERNAL_LIGHTS_PIN, 1)
예제 #9
0
파일: lcd.py 프로젝트: Pahkel/pcd8544-1
def set_brightness(led_value):
    if  LED == 1:
        if (0 <= led_value < 1023):
            wiringpi.pwmWrite(LED,led_value)
    else:
        if led_value == 0:
            wiringpi.digitalWrite(LED, OFF)
        else:
            wiringpi.digitalWrite(LED, ON)
예제 #10
0
    def __init__(self, freq = 100.0):
        self.freq = freq
        output_pins.append(12)
        wp.pinMode(12, PWM)
        wp.pwmSetRange(4000) #range can go up to 4096, 4000 is good because it's large and a multiple of 100
        clock = 19.2e6 / (4000.0 * freq) #set the divisor so the frequency comes out right
        wp.pwmSetClock(int(clock)) #this function needs an int
	wp.pwmSetMode(0) # necessary or else it's in a weird mode where nothing works
	wp.pwmWrite(12, 0) # stop for safety
예제 #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)
예제 #12
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)
예제 #13
0
 def fade(self,direction):
     if direction:
         for i in range(1000,-1,-1):
             #self.pwmLed.ChangeDutyCycle(i)
             led.pwmWrite(18,i)
             time.sleep(0.005)
     else:
         for i in range(0,1001,1):
             #self.pwmLed.ChangeDutyCycle(i)
             led.pwmWrite(18,i)
             time.sleep(0.005)
def power(duty, sens):
    if int(sens) < 90:
        wiringpi2.digitalWrite(2, 1)
        wiringpi2.digitalWrite(3, 0)
        print "sens normal"
    elif int(sens) > 90:
        wiringpi2.digitalWrite(2, 0)
        wiringpi2.digitalWrite(3, 1)
        print "sens inverse"
    wiringpi2.pwmWrite(1, int(duty))
    return "Changement puissance"
예제 #15
0
	def setBuzzerOn(self, buzzerOn):
		'''
		Set buzzer state

		Args:
		  buzzerOn (bool): True to turn on buzzer, False to turn off
		'''
		if buzzerOn:
			wiringpi2.pwmWrite(self.GPIOS['buzzer'], 100)
		else:
			wiringpi2.pwmWrite(self.GPIOS['buzzer'], 0)
예제 #16
0
    def set(self, speed):
        if speed > 1.0:
            speed = 1.0
        if speed < -1.0:
            speed = -1.0
        # this results in speeds from 500 (fastest allowed forward)
        # to 700 (fastest allowed reverse)
        # the theoretical maxima are 400 forward and 800 reverse
        duty_cycle = 600 - (100 * speed)
	wp.pwmWrite(12, int(duty_cycle)) # this also wants an int
        return duty_cycle    
예제 #17
0
    def set_value(self, target, dt):
        # limit the target value to the range -1 .. 1
        if target > 1:
            target = 1
        if target < -1:
            target = -1
        
        # set direction
        if target > 0:
            # forward_value
            backward_value = wiringpi2.GPIO.LOW
            forward_value = wiringpi2.GPIO.HIGH
        elif target < 0:
            # backward_value
            backward_value = wiringpi2.GPIO.HIGH
            forward_value = wiringpi2.GPIO.LOW
        else:
            backward_value = wiringpi2.GPIO.LOW
            forward_value = wiringpi2.GPIO.LOW

        if self.backward_value != backward_value:
            wiringpi2.digitalWrite(self.backward_port, backward_value)
        if self.forward_value != forward_value:
            wiringpi2.digitalWrite(self.forward_port, forward_value)
        self.backward_value = backward_value
        self.forward_value = forward_value

        # set power
        if target < 0:
            target = -target
        
        # find interpolation range
        for idx, val in enumerate(self.mapping_u):
            print idx, val
            if val > target*100.0:
                # found
                break
        if idx <= 0:
            idx = 1
        if idx > len(self.mapping_u):
            idx = len(self.mapping_u)
        # interpolate
        u1 = float(self.mapping_u[idx - 1])
        u2 = float(self.mapping_u[idx])
        p1 = float(self.mapping_pwm[idx - 1])
        p2 = float(self.mapping_pwm[idx])
        power_percent = p1 + (target * 100.0 - u1) * (p2 - p1) / (u2 - u1)
        self.logger.debug("{}: target={} idx={} u1={:5.2f} u2={:1f} p1={:1f} p2={:4f}".format(self.name, idx, target, u1, u2, p1, p2))
        
        # scale to pwm_range
        power = int(self.pwm_range * power_percent / 100)
        wiringpi2.pwmWrite(self.pwm_port, power)

        self.logger.debug("{}: target={:5.3f} backward_value={:1d} forward_value={:1d} power={:2.0f} %={:4d}/{:4d}".format(self.name, target, backward_value, forward_value, power_percent, power, self.pwm_range))
예제 #18
0
    def pwm_fast_ramp( self ):
        # A somewhat contrived example, this will create 'ramp'
        # by changing the PWM output from zero to max as fast as
        # possible.
        start = time.clock()

        # modulate the PWM signal as fast as possible
        for i in range(1024):
            wp.pwmWrite( 18, i )

        # return the elapsed time
        return time.clock() - start
예제 #19
0
def softPwm():
	print "SoftPwm Mode"

	wiringpi2.wiringPiSetup()
	wiringpi2.pinMode(PIN_TO_PWM,SET_PWM)
	wiringpi2.pwmSetMode(PWM_MODE_MS)	
	#wiringpi2.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters
	#wiringpi2.softServoSettup()
	#softServoWrite()
	wiringpi2.pwmWrite(PIN_TO_PWM, 900) 	
	wiringpi2.delay(150)
	print "PWM is in NEUTRAL"
예제 #20
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)
예제 #21
0
	def rotate(self, speed):
		speedi = int(speed)
		if speed >= 0:
			wiringpi.pwmWrite(self.in3, speedi)
			GPIO.output(self.in1,GPIO.HIGH)
			GPIO.output(self.in2,GPIO.LOW)
		elif speed < 0:
			if speedi < -1024:
				speedi = -1024
			wiringpi.pwmWrite(self.in3, math.fabs(speedi))
			GPIO.output(self.in1,GPIO.LOW)
			GPIO.output(self.in2,GPIO.HIGH)
예제 #22
0
def cleanup():
	wiringpi.pwmWrite(LEFT_MOTOR_PWM, 0)
	wiringpi.pwmWrite(RIGHT_MOTOR_PWM, 0)
	wiringpi.pinMode(LEFT_MOTOR_PWM, 0)
	wiringpi.pinMode(RIGHT_MOTOR_PWM, 0)
	GPIO.output(LEFT_MOTOR_A, GPIO.LOW)
	GPIO.output(LEFT_MOTOR_B, GPIO.LOW)	
	GPIO.output(RIGHT_MOTOR_A, GPIO.LOW)
	GPIO.output(RIGHT_MOTOR_B, GPIO.LOW)
	GPIO.setup(LEFT_MOTOR_A, GPIO.IN)
	GPIO.setup(LEFT_MOTOR_B, GPIO.IN)	
	GPIO.setup(RIGHT_MOTOR_A, GPIO.IN)
	GPIO.setup(RIGHT_MOTOR_B, GPIO.IN)
예제 #23
0
    def setSpeed(self, speed):
        if speed < 0:
            speed = -speed
            dir_value = 1
        else:
            dir_value = 0

        if speed > MAX_SPEED:
            speed = MAX_SPEED

        io_init()
        wiringpi2.digitalWrite(self.dir_pin, dir_value)
        wiringpi2.pwmWrite(self.pwm_pin, speed)
예제 #24
0
def talker():
    signal.signal(signal.SIGINT, signal_handler)
    time.sleep(1)
    setup_servo()
    pub = rospy.Publisher('servo_ulta', Range, queue_size=10)
    rospy.init_node('servo_ultra', anonymous=True, disable_signals=False )
    rate = rospy.Rate(10) # 10hz
    ultrasonic_number = 1
    
    pause_time = 0.1
    delay_ultrasonic = 0.11
    STEP_ANGLE = 10

    CURR_ANGLE = (90.0 * math.pi) / 180.0

    mindt = 0.65
    maxdt = 2.48
    dt = [mindt, maxdt]
    extremes = [int(x * 1024.0 / 20.0) for x in dt]

    dt_range = extremes[1] - extremes[0]
    dt_step = int((dt_range / 180.0) * STEP_ANGLE)

    br = tf.TransformBroadcaster()

    while not rospy.is_shutdown():
        #broadcast_transforms()

        # Move servo to counter-clockwise extreme.
        wiringpi.pwmWrite(18, extremes[1])
        sleep(0.2)
        CURR_ANGLE = (90.0 * math.pi) / 180.0

        for i in range(extremes[1],extremes[0],-dt_step):         # 1025 because it stops at 1024
            wiringpi.pwmWrite(18,i)
            sleep(pause_time)
            br.sendTransform((0.15, 0.0, 0.0),tf.transformations.quaternion_about_axis(CURR_ANGLE, (0, 0, 1)), rospy.Time.now(), "1", "base_link")
            data = Range()
            data.header.frame_id = "1"
            data.header.stamp = rospy.Time.now()
            data.radiation_type = 0
            data.min_range = 0.05 
            data.max_range = 2.0
            data.field_of_view = 0.164
            try :
                data.range = float(get_us_data_from(ultrasonic_number)) /100.0
            except IOError:
                subprocess.call(['i2cdetect', '-y', '1'])
                data.range = 0.0
            pub.publish(data)
            CURR_ANGLE -= (STEP_ANGLE * math.pi) / 180.0
예제 #25
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)
예제 #26
0
def SetSP(servoID, setPoint):

	if not on: return

	if setPoint < 0 or setPoint > 1:
		procComms.PrintLog('Servo SetPoint value out of range.')
		return

	pin = 0
	if servoID == 1: pin = 13
	elif servoID == 2: pin = 18
	else: return

	sp = setPoint * (max - min) + min
	wiringpi.pwmWrite(pin, int(sp))
예제 #27
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)
예제 #28
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()
예제 #29
0
파일: pwm.py 프로젝트: MagorokuYohei/hoby
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)
예제 #30
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
예제 #31
0
# Tendo que o clock base do pwm é 19.2mhz:
# divisor = (19.2x1000)/440
# divisor = 43.6363636364

divisor = (19.2 * (10**3)) / 440
wiringpi2.pwmSetClock(int(divisor))


def calcParams(freq):
    period = (1 / freq) * (10**6)
    dutyCycle = period / 2
    return (int(period), int(dutyCycle))


try:
    while True:
        for freq in range(500, 1001, 1):
            period, dutyCycle = calcParams(freq)
            wiringpi2.pwmSetRange(period)
            wiringpi2.pwmWrite(SPEAKER, dutyCycle)
            wiringpi2.delay(1)
        for freq in range(1000, 499, -1):
            period, dutyCycle = calcParams(freq)
            wiringpi2.pwmSetRange(period)
            wiringpi2.pwmWrite(SPEAKER, dutyCycle)
            wiringpi2.delay(1)
except KeyboardInterrupt:
    wiringpi2.pwmWrite(SPEAKER, 0)
    wiringpi2.pinMode(SPEAKER, 0)
    exit(0)
예제 #32
0
wiringpi.pwmSetMode(0)
wiringpi.pwmSetClock(pwm_clock)
wiringpi.pwmSetRange(pwm_range)

#led
faceFoundPin = 5
wiringpi.pinMode(faceFoundPin, 1)

faceLost = True
faceLostStart = -1
faceLostPwm = -1
faceLostTimeout = 5

time_start = time.time()

wiringpi.pwmWrite(pwm_pin_horizontal, dt_horizontal)
wiringpi.pwmWrite(pwm_pin_vertical, dt_vertical)

time.sleep(0.2)


def transmitMoveOrder(horizontal, vertical):
    global dt_horizontal
    dt_horizontal = 150 + horizontal
    if dt_horizontal > dt_max:
        dt_horizontal = dt_max
    if dt_horizontal < dt_min:
        dt_horizontal = dt_min
    wiringpi.pwmWrite(pwm_pin_horizontal, int(dt_horizontal))

    global dt_vertical
 def fullClose(self):
     self.value = SAIL_FULLCLOSE
     pi.pwmWrite(SAIL_SERVO_PIN, self.value)
예제 #34
0
파일: servo.py 프로젝트: eggtart93/Phantom
 def servoturn(self,angle):
     dutyCycle = int(angle/180.0*(0.14*1024)) + 6
     wiringpi.pwmWrite(SERVO_PIN,dutyCycle)
예제 #35
0
 def set_right_speed(self, dc):
     wp.pwmWrite(19, dc)
예제 #36
0
 def set_left_speed(self, dc):
     self.prev[0] = dc / self.max
     wp.pwmWrite(18, dc)
예제 #37
0
파일: pwm_led.py 프로젝트: ecelis/sck
import wiringpi2
import sys
pin = 31

wiringpi2.wiringPiSetupPhys()
wiringpi2.pinMode(pin, 2)  #PWM_OUTPUT

#wiringpi2.pwmSetClock(0); #24M/120=200k
#range = 255
#HZ = 200k/(255+1) = 781hz

while 1:
    for brightness in range(0, 255):
        wiringpi2.pwmWrite(pin, brightness)
        wiringpi2.delay(10)
        print brightness
    for brightness in range(0, 255):
        wiringpi2.pwmWrite(pin, 255 - brightness)
        wiringpi2.delay(10)
        hello = 255 - brightness
        print hello
예제 #38
0
 def set_right_speed(self, dc):
     self.prev[1] = dc / self.max
     wp.pwmWrite(19, dc)
 def __init__(self, initValue):
     self.value = initValue
     pi.pwmWrite(SAIL_SERVO_PIN, self.value)
예제 #40
0
 def pwmwrite(self):
     wiringpi.pwmWrite(self.pin, self.dt)
     print "PIN " + str(self.pin) + "DT = " + str(self.dt)
예제 #41
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import time
import wiringpi2 as wipi

PIN = 12  # BCM GPIO 18
wipi.wiringPiSetupPhys()
wipi.pinMode(PIN, 2)

i = 0
while True:
    wipi.pwmWrite(PIN, i % 1024)
    i += 1
    time.sleep(0.01)
    print(i)
예제 #42
0
파일: dest.py 프로젝트: gogoin/netboat
#-*-coding:utf-8 -*-

import wiringpi2 as wiringpi
import FaBo9Axis_MPU9250
import time
import serial
import sys
from math import degrees, radians, atan, atan2, sin, cos, pi, asin, sqrt

#initialize setting
wiringpi.wiringPiSetup()  #initialize wiringPi
wiringpi.pinMode(23, 2)  # alternative function = PWM
wiringpi.pinMode(26, 2)  # alternative function = PWM
wiringpi.pwmSetMode(0)
wiringpi.pwmSetRange(12000)
wiringpi.pwmWrite(23, 700)
wiringpi.pwmWrite(26, 900)
mpu9250 = FaBo9Axis_MPU9250.MPU9250()  #mpu9250 initialize
ser = serial.Serial('/dev/ttyAMA0', 9600)  #gps serial port

#initialize variable
speed = 0
angle = 2
state = 0


def SpeedWrite(speed):  #desire speed
    if speed > 10:
        print 'speed cannot be greater than 10.'
    elif speed > 0:
        wiringpi.pwmWrite(23, 880 + (speed - 1) * 10)
예제 #43
0
 def set_left_speed(self, dc):
     wp.pwmWrite(18, dc)
예제 #44
0
# 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:
        raise

sys.exit(0)

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
예제 #45
0

web_server = Bottle()

@web_server.route('/sensors')
def sensors():
    global controlThread
    logDataSetBuffer = controlThread.getLogDataSetBuffer()
    # return the logDataSetBuffer's latest state
    response.content_type = "application/json"    
    return dumps(logDataSetBuffer, default=lambda o: o.__dict__)

bottle_thread = Thread(target=web_server.run, kwargs=dict(host='0.0.0.0', port=8080, debug=True))
bottle_thread.daemon = True
bottle_thread.start()

try:
    while True:
        time.sleep(1)

except (KeyboardInterrupt, SystemExit):
    print "caught exception, exiting..."
    wiringpi2.pwmWrite(ports.port_motor_left_pwm, 0)
    wiringpi2.pwmWrite(ports.port_motor_right_pwm, 0)
    wiringpi2.digitalWrite(ports.port_motor_left_backward, wiringpi2.GPIO.LOW)
    wiringpi2.digitalWrite(ports.port_motor_left_forward, wiringpi2.GPIO.LOW)
    wiringpi2.digitalWrite(ports.port_motor_right_backward, wiringpi2.GPIO.LOW)
    wiringpi2.digitalWrite(ports.port_motor_right_forward, wiringpi2.GPIO.LOW)

    sys.exit(1)
예제 #46
0
import wiringpi2 as GPIO
import time

r = 200;
div = 100;
outPin = 1;

GPIO.wiringPiSetup()
GPIO.pinMode(outPin,2)
GPIO.pwmSetMode(0)
GPIO.pwmSetClock(div)
GPIO.pwmSetRange(r)

for duty in range(r,0,-1):
    GPIO.pwmWrite(1,duty)
    if not duty%20:
        print str(int(float(duty)/float(r)*100)) + "%"
    time.sleep(0.01)

for duty in range(0,r+1):
    GPIO.pwmWrite(1,duty)
    if not duty%20:
        print str(int(float(duty)/float(r)*100)) + "%"
    time.sleep(0.01)