예제 #1
0
def smoothentry():
    if __name__ == "__main__":

        #print('test')

        #use 'GPIO naming'
        wiringpi.wiringPiSetupGpio()
        #print('test')

        #set #18 to be pwm output
        wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)
        #print('test')

        #set the pwm mode to milliseconds style
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
        #print('test1')

        #divide down clock
        wiringpi.pwmSetClock(192)
        wiringpi.pwmSetRange(2000)

        delay_period = 0.1
        #print('test')
        personPresent = person_present()
        if personPresent == True:
            servo('down')
            success = check_in()
            temp = get_temperature()
            if success == True and temp == True:
                display_success_lcd()

            else:
                display_failure_lcd()
예제 #2
0
    def __init__(self, servoOffset):

        io.setmode(io.BCM)

        io.setup(self.in1_pin, io.OUT)
        io.setup(self.in2_pin, io.OUT)
        io.setup(self.enable1_pin, io.OUT)
        io.setup(self.in3_pin, io.OUT)
        io.setup(self.in4_pin, io.OUT)
        io.setup(self.enable2_pin, io.OUT)

        self.servoOffset = servoOffset

        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(self.servo_pin, wiringpi.GPIO.PWM_OUTPUT)
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
        wiringpi.pwmSetClock(192)
        wiringpi.pwmSetRange(2000)
        wiringpi.pwmWrite(self.servo_pin, 140 - self.servoOffset)

        io.output(self.enable1_pin, True)  #left
        io.output(self.enable2_pin, True)  # right

        self.speed1 = io.PWM(self.enable1_pin, 50)
        self.speed2 = io.PWM(self.enable2_pin, 50)

        self.speed1.start(int(0))  #left
        self.speed2.start(int(0))  #right
        print("ininted motors")
예제 #3
0
    def __init__(self, servo_motor_pin1):
        self.motor_pin1 = servo_motor_pin1

        pi.pinMode(self.motor_pin1, pi.GPIO.PWM_OUTPUT)
        pi.pwmSetMode(pi.GPIO.PWM_MODE_MS)
        pi.pwmSetRange(ServoMotor.RANGE)
        pi.pwmSetClock(ServoMotor.clock)
예제 #4
0
def init_servo(servo1, servo2):
    wiringpi.wiringPiSetupGpio()
    wiringpi.pinMode(servo1, 2)
    wiringpi.pinMode(servo2, 2)
    wiringpi.pwmSetMode(0)
    wiringpi.pwmSetRange(1024)
    wiringpi.pwmSetClock(375)
예제 #5
0
def main():
    #all needs to run automatically
    port0 = '/dev/ttyUSB0'
    port1 = '/dev/ttyUSB1'
    port2 = '/dev/ttyUSB2'
    ##
    th_cl1 = TestThread(port1, './original_data/data1208.csv')
    th_cl1 = TestThread(port1, './original_data/data1208.csv')

    #th_cl1.start()
    #th_cl2.start()

    f = open('./original_data/data1209.csv', 'w')
    ##
    servo_pin = 18

    param = sys.argv
    set_degree = int(param[1])
    print(set_degree)

    wiringpi.wiringPiSetupGpio()

    wiringpi.pinMode(servo_pin, 2)

    wiringpi.pwmSetMode(0)
    wiringpi.pwmSetRange(1024)
    wiringpi.pwmSetClock(375)


    while True:
        try:
            ser = serial.Serial(port0, 38400, timeout=10)  # 10s-timeout baudrate=38400
            ser.write(b'<RM,>??\r\n')  # send command (CR+LF)
            line = ser.readline()
            line = str(datetime.datetime.now()) + str(",") + line.decode('utf-8')
            line = line.split(',')

            velocity = float(line[2])
            temp = float(line[5])

            print('CPU_temperature' + '/' + line[0] + ',' + line[2] + ','
                    + line[3] + ',' + line[4] + ',' + line[5])
            f.write(line[0] + ',' + line[2] + ','
                    + line[3] + ',' + line[4] + ',' + line[5] + "\n")

            if temp >= 35.0:
#                print('too hot')
                wiringpi.pwmWrite(servo_pin, set_degree + 5)
#                LED(11, True)
            else:
#                print('oh.. cool')
#                move_deg = int (81+41/90*set_degree)

                wiringpi.pwmWrite(servo_pin, set_degree)
#                LED(11, False)

            time.sleep(5)

        except IndexError:
            pass
예제 #6
0
    def __init__(self, device_name, device_config):
        super(Fan, self).__init__(device_type='exhaust',
                                  device_name=device_name,
                                  device_config=device_config)
        self.fwd_pin = int(device_config['fwd_pin'])
        self.bwd_pin = int(device_config['bwd_pin'])
        self.pwm_pin = int(device_config['pwm_pin'])

        # Prepare pins for output/pwm
        wiringpi.pinMode(self.fwd_pin, 1)
        wiringpi.pinMode(self.bwd_pin, 1)
        wiringpi.pinMode(self.pwm_pin, 2)
        wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)

        # Prepare PWM specs
        self.range = 240  # 20Khz
        self.clock = 4  # Must be at least 2
        wiringpi.pwmSetClock(self.clock)
        wiringpi.pwmSetRange(self.range)
        #freq = 19200000 / self.clock / self.range
        #print("Frequency:", freq)

        # Initialize to off
        self.data['speed'] = 0
        self.off()
예제 #7
0
    def __init__(self,
                 bus=None,
                 step='Full',
                 flat_declination=138,
                 delay_period=0.005):

        self.stepper_pos = 0
        self.step = step
        GPIO.output(self.MODE, self.RESOLUTION[step])
        self.step_count = self.SPR * self.Res_adj[step]
        self.delay = .0208 / (self.Res_adj[step] * 12)
        #self.bus = smbus.SMBus(1)    # or bus = smbus.SMBus(0) for older version boards
        self.bus = bus
        self.Device_Address = 0x1e  # HMC5883L magnetometer device address
        self.Magnetometer_Init(bus)  # initialize HMC5883L magnetometer
        self.delay_period = delay_period
        self.flat_declination = flat_declination

        # use 'GPIO naming'
        wiringpi.wiringPiSetupGpio()

        # set #18 to be a PWM output
        wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)

        # set the PWM mode to milliseconds stype
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

        # divide down clock
        wiringpi.pwmSetClock(192)
        wiringpi.pwmSetRange(2000)

        ####
        wiringpi.pwmWrite(18, self.flat_declination)
        heading_angle = self.get_heading()
def Gpio_Intent(status, room):
    wiringpi.wiringPiSetupGpio()

    wiringpi.pinMode(18, 2)  # pwm mode = 2
    wiringpi.pwmSetMode(0)

    # pwmFrequency in Hz = 19.2e6 Hz / pwmClock / pwmRange.
    wiringpi.pwmSetRange(4096)
    wiringpi.pwmSetClock(4095)
    if status in STATUSON:
        wiringpi.pwmWrite(18, 4096)
        return statement('turning {} blue L E D'.format(status))
    elif status in STATUSOFF:
        wiringpi.pwmWrite(18, 0)
        return statement('turning {} blue L E D'.format(status))
    elif status in STATUSTOGGLE:
        wiringpi.pwmWrite(18, 2048)
        return statement('{}ing blue L E D'.format(status))
    elif status in STATUSCMD:
        serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
        if status == 'a':
            wiringpi.serialPuts(serial, 'a')
        elif status == 'be':
            wiringpi.serialPuts(serial, 'b')
        elif status == 'see':
            wiringpi.serialPuts(serial, 'c')
        wiringpi.serialClose(serial)
        return statement(
            'Trying to send command ASCII character {}'.format(status))
    else:
        return statement('Sorry not possible.')
예제 #9
0
    def __init__(self):

        # setting up the GPIO settings for the pwm
        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

        # pwm frequency in Hz: 19,200,000 / pwmSetClock / pwmSetRange
        # 19,200,000 / 10 / 1000 = 1920
        wiringpi.pwmSetClock(10)
        wiringpi.pwmSetRange(1000)

        # sets gpio to BCM pinout
        gpio.setmode(gpio.BCM)

        # gpio.setup(0, gpio.IN, pull_up_down=gpio.PUD_UP)
        gpio.setup(4, gpio.IN, pull_up_down=gpio.PUD_UP)
        gpio.setup(27, gpio.IN, pull_up_down=gpio.PUD_UP)

        # this variable is for making sure only one press is logged
        # when a switch is pressed
        switchState = 0
        motorState = 1  #Motor on initially

        # initialization for filling
        gpio.setup(26, gpio.OUT)
예제 #10
0
 def __init__(self,
              en_pin: int,
              slew_pin: int,
              pwm_pin: int,
              forward_pin: int,
              reverse_pin: int,
              sf_pin: int,
              name: str = 'Motor'):
     self.pwm_pin = pwm_pin
     self.forward_pin = forward_pin
     self.reverse_pin = reverse_pin
     self.en_pin = en_pin
     self.slew_pin = slew_pin
     self.sf_pin = sf_pin
     self.max_speed = 480
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(12, wiringpi.GPIO.PWM_OUTPUT)
     wiringpi.pinMode(13, wiringpi.GPIO.PWM_OUTPUT)
     wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
     wiringpi.pwmSetRange(self.max_speed)
     wiringpi.pwmSetClock(2)
     wiringpi.pinMode(self.forward_pin, wiringpi.GPIO.OUTPUT)
     wiringpi.pinMode(self.reverse_pin, wiringpi.GPIO.OUTPUT)
     wiringpi.pinMode(self.en_pin, wiringpi.GPIO.OUTPUT)
     wiringpi.pinMode(self.slew_pin, wiringpi.GPIO.OUTPUT)
     wiringpi.pinMode(self.sf_pin, wiringpi.GPIO.INPUT)
예제 #11
0
def setupPWM(motor11, motor12, motor21, motor22, motor31, motor32, motor41, motor42):

    # setup wiringpi and pwm outputs
    wiringpi.wiringPiSetup()

    wiringpi.pinMode(motor11, 1)
    wiringpi.pinMode(motor12, 1)
    wiringpi.pinMode(motor21, 1)
    wiringpi.pinMode(motor22, 1)
    wiringpi.pinMode(motor31, 1)
    wiringpi.pinMode(motor32, 1)
    wiringpi.pinMode(motor41, 1)
    wiringpi.pinMode(motor42, 1)

    wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
    wiringpi.pwmSetClock(2)
    wiringpi.pwmSetRange(1000)

    wiringpi.softPwmCreate(motor11, 0, 100)
    wiringpi.softPwmCreate(motor12, 0, 100)
    wiringpi.softPwmCreate(motor21, 0, 100)
    wiringpi.softPwmCreate(motor22, 0, 100)
    wiringpi.softPwmCreate(motor31, 0, 100)
    wiringpi.softPwmCreate(motor32, 0, 100)
    wiringpi.softPwmCreate(motor41, 0, 100)
    wiringpi.softPwmCreate(motor42, 0, 100)

    wiringpi.softPwmWrite(motor11, 100)
    wiringpi.softPwmWrite(motor12, 100)
    wiringpi.softPwmWrite(motor21, 100)
    wiringpi.softPwmWrite(motor22, 100)
    wiringpi.softPwmWrite(motor31, 100)
    wiringpi.softPwmWrite(motor32, 100)
    wiringpi.softPwmWrite(motor41, 100)
    wiringpi.softPwmWrite(motor42, 100)
 def act(self, client_address, state, name):
     print("State", state, "from client @", client_address)
     # GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
     # GPIO.setup(int(7), GPIO.OUT)   ## Setup GPIO Pin to OUTPUT
     # GPIO.output(int(7), state) ## State is true/false
     """if name=="kitchen":
         GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
         GPIO.setup(int(7), GPIO.OUT)   ## Setup GPIO Pin to OUTPUT
         GPIO.output(int(7), state) ## State is true/false
     elif name =="living room":
         GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
         GPIO.setup(int(11), GPIO.OUT)   ## Setup GPIO Pin to OUTPUT
         GPIO.output(int(11), state) ## State is true/false
     """
     if name=="light":
         wiringpi.wiringPiSetupGpio()
         wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)
         wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
         wiringpi.pwmSetClock(192)
         wiringpi.pwmSetRange(2000)
         delay_period = 0.15
         if state:
             wiringpi.pwmWrite(18, 111)
             time.sleep(delay_period)
             wiringpi.pwmWrite(18, 90)
         else:
             wiringpi.pwmWrite(18, 45)
             time.sleep(delay_period)
             wiringpi.pwmWrite(18, 90)
     else:
         print("Device not found!")
     return True
예제 #13
0
    def __init__(self, logger):
        self.log = logger

        self.log.info("Initializeing PWM Controller")

        self.duty_cycle = 0
        self.pwm_range = 128
        self.pwm_clock = 6
        self.tach_last_time = 0.0
        self.power_state = 0
        self.enable_power_control = True
        self.min_pwm_val = -1
        self.tach_speed_calc = 0 

        #Check we are a Raspberry PI
        try:
            GPIO.setmode(GPIO.BCM)
            GPIO.setup(PWMFanController.TACH_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
            GPIO.add_event_detect(PWMFanController.TACH_PIN, GPIO.FALLING, callback=self.tachCallback, bouncetime=1)
            wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
            wiringpi.wiringPiSetupGpio()
            wiringpi.pinMode(PWMFanController.POWER_PIN, wiringpi.OUTPUT)
            self.setPowerState(False)
            wiringpi.pinMode(PWMFanController.PWM_PIN,2)
            wiringpi.pwmSetRange(self.pwm_range)
            wiringpi.pwmSetClock(self.pwm_clock) # Equals 19200000 / PWM_CLOCK / PWM_RANGE
            
            self.enabled = True
        except Exception, e:
            self.log.error(e)
            self.log.error("Could not initialize PWM controller")
            self.enabled = False
def io_init_motor_drive():
    """
    Checks and initializes all GPIO pins for motor drivers.
    Note:
        This must be initialized before constructing a MotorDriver object.
    """

    global IO_INITIALIZED
    if IO_INITIALIZED:
        return

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

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

    wiringpi.pinMode(22, wiringpi.GPIO.OUTPUT)
    wiringpi.pinMode(23, wiringpi.GPIO.OUTPUT)
    wiringpi.pinMode(24, wiringpi.GPIO.OUTPUT)
    wiringpi.pinMode(25, wiringpi.GPIO.OUTPUT)

    IO_INITIALIZED = True
예제 #15
0
def gpioSetup():
    # Access global variables
    global dcRange
    global clockDivisor
    global pwm
    global pwm2

    try:
        # Setup board pin layout
        wiringpi.wiringPiSetup()
        wiringpi.pinMode(1, wiringpi.PWM_OUTPUT)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(13, GPIO.OUT)
        GPIO.setup(19, GPIO.OUT)
        pwm = GPIO.PWM(13, 1000)

        # Set output to mark:space mode (to avoid frequency change)
        wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)

        # Set output to approximately 100 kHz
        wiringpi.pwmSetClock(2)
        wiringpi.pwmSetRange(dcRange)

        # Initialize duty cycles
        wiringpi.pwmWrite(1, 0)
        pwm.start(50)
        # pwmWrite requires numbers in range [0, dcRange]
    finally:
        print("Completed setup")
예제 #16
0
    def __init__(self,
                 PIN_IN1_L=5,
                 PIN_IN2_L=6,
                 PIN_IN1_R=7,
                 PIN_IN2_R=8,
                 PIN_VREF_L=12,
                 PIN_VREF_R=13):
        self.PIN_IN1_L = PIN_IN1_L
        self.PIN_IN1_R = PIN_IN1_R
        self.PIN_IN2_L = PIN_IN2_L
        self.PIN_IN2_R = PIN_IN2_R
        self.PIN_VREF_L = PIN_VREF_L
        self.PIN_VREF_R = PIN_VREF_R
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.PIN_IN1_L, GPIO.OUT)
        GPIO.setup(self.PIN_IN2_L, GPIO.OUT)
        GPIO.setup(self.PIN_IN1_R, GPIO.OUT)
        GPIO.setup(self.PIN_IN2_R, GPIO.OUT)

        wp.wiringPiSetupGpio()
        wp.pinMode(self.PIN_VREF_L, wp.GPIO.PWM_OUTPUT)
        wp.pinMode(self.PIN_VREF_R, wp.GPIO.PWM_OUTPUT)
        wp.pwmSetMode(wp.PWM_MODE_MS)
        wp.pwmSetRange(Drive.MaxdutyRange)
        wp.pwmSetClock(400)
예제 #17
0
    def motor2():
        import wiringpi

        import time

        import sys

        # GPIO number
        servo_pin  =  18
        # kakudo set
        # set_degree = 90 def

        param = sys.argv
        set_degree = 0

        wiringpi.wiringPiSetupGpio()
        # PWM output
        wiringpi.pinMode( servo_pin, 2 )

        # motor PWM set
        wiringpi.pwmSetMode(0)
        wiringpi.pwmSetRange(1024)
        wiringpi.pwmSetClock(375)

        # -90 ~ 90 only move

            # PWM use number
        move_deg = int( 81 + 41 / 90 * set_degree )
            # send PWM motor move
        wiringpi.pwmWrite( servo_pin, move_deg )
        
        return 0
예제 #18
0
파일: cannon.py 프로젝트: hishigeki/raspi
    def __init__(self):

        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(self.PIN_PWM, wiringpi.GPIO.PWM_OUTPUT)
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
        wiringpi.pwmSetClock(375)

        wiringpi.pwmWrite(self.PIN_PWM, self.FRONT)
예제 #19
0
 def stop(self):
     if self.hw:
         wpi.pwmSetMode(wpi.PWM_MODE_BAL)
         wpi.pwmSetClock(0)
         wpi.pwmSetRange(1024)
         wpi.pinMode(self.PIN_SERVO, wpi.INPUT)
     else:
         self.pwm.stop()
예제 #20
0
    def setup(self, pin, mode):
        wpi.pinMode(self.MAP[mode])
        if mode == modes.PWM:
            wpi.pwmSetMode(wpi.PWM_MODE_MS)
            wpi.pwmSetClock(int(19200000 * self._wrapper.PWM_FREQ) // 2)
            wpi.pwmSetRange(int(19200000 * self._wrapper.PWM_FREQ))

        return True
예제 #21
0
    def __init__(self):
        wiringpi.wiringPiSetup()
        wiringpi.pinMode(1, wiringpi.GPIO.PWM_OUTPUT)
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

        # divide down clock
        wiringpi.pwmSetClock(192)
        wiringpi.pwmSetRange(2000)
예제 #22
0
	def __init__(self, pin):
		self.PWM_PIN = pin
		wiringpi.wiringPiSetupGpio()   #winringPiの初期設定
		wiringpi.pinMode(self.PWM_PIN, wiringpi.GPIO.PWM_OUTPUT)
		#「Balanced」→「mark:space」Modeに変更
		wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
		# 周波数を50Hzにすると、18750/周波数=375
		wiringpi.pwmSetClock(375)
예제 #23
0
def initialize_servo():
    # use 'GPIO naming'
    wiringpi.wiringPiSetupGpio()
    wiringpi.pinMode(servo_pin, wiringpi.GPIO.PWM_OUTPUT)
    wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

    # divide down clock
    wiringpi.pwmSetClock(192)
    wiringpi.pwmSetRange(2000)
예제 #24
0
    def initialize(self):
        wiringpi.wiringPiSetupGpio()

        wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)

        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)

        wiringpi.pwmSetClock(192)
        wiringpi.pwmSetRange(2000)
예제 #25
0
 def __init__(self):
     wp.wiringPiSetupGpio()
     wp.softPwmCreate(MOTOR_PWM, 0, 100)
     wp.pinMode(MOTOR_OUTA, GPIOMODE_OUT)
     wp.pinMode(MOTOR_OUTB, GPIOMODE_OUT)
     wp.pinMode(STEERING_PORT, GPIOMODE_PWM)
     wp.pwmSetMode(0)
     wp.pwmSetRange(1024)
     wp.pwmSetClock(375)
예제 #26
0
    def __init__(self):
        self.pwm0_pin = Pins.get_pin("pwm0")
        wiringpi.pwmSetMode(0)  # PWM_MODE_MS = 0
        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(self.pwm0_pin,
                         2)  # pwm only works on GPIO port 18 out of the box

        wiringpi.pwmSetClock(5)  # this parameters correspond to 25kHz
        wiringpi.pwmSetRange(1000)
예제 #27
0
파일: hw.py 프로젝트: kevinkahn/softconsole
def initOS():
	os.environ['SDL_FBDEV'] = '/dev/fb1'
	os.environ['SDL_MOUSEDEV'] = '/dev/input/touchscreen'
	os.environ['SDL_MOUSEDRV'] = 'TSLIB'
	os.environ['SDL_VIDEODRIVER'] = 'fbcon'

	wiringpi.wiringPiSetupGpio()
	wiringpi.pinMode(18, 2)
	wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)  # default balanced mode makes screen dark at about 853/1024
	wiringpi.pwmWrite(18, 1024)
예제 #28
0
파일: tv.py 프로젝트: cbott/monochromecast
    def __init__(self):
        wiringpi.wiringPiSetup()  # initialize wiringpi with default pin numbering
        wiringpi.pinMode(TV_Controller.PW_EN_PIN, wiringpi.OUTPUT)
        wiringpi.pinMode(TV_Controller.DIM_PIN, wiringpi.PWM_OUTPUT)

        wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)  # Mark:space mode, unclear what this is
        wiringpi.pwmSetRange(TV_Controller.PWM_RANGE)
        wiringpi.pwmSetClock(TV_Controller.PWM_CLOCK)
        self.set_brightness(1)
        self.enable_system()
예제 #29
0
 def __init__(self):
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(PIN, wiringpi.GPIO.PWM_OUTPUT)
     wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
     # Duty Cycle=100%の時に1024
     wiringpi.pwmSetRange(1024)
     # PWM周波数
     # PWMコントローラの動作クロック周波数19.2MHz / PWM信号の周波数50Hz
     #   x レンジ1024= 393
     wiringpi.pwmSetClock(393)
예제 #30
0
파일: test.py 프로젝트: mpmiyata/nordichack
def init():
    wiringpi.wiringPiSetupGpio()

    wiringpi.pinMode(PWM_PIN, wiringpi.PWM_OUTPUT)
    wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
    wiringpi.pwmSetClock(3840)
    wiringpi.pwmSetRange(250)

    wiringpi.pinMode(SPEED_SENSE_PIN, wiringpi.INPUT)
    wiringpi.pullUpDnControl(SPEED_SENSE_PIN, PUD_DOWN)
예제 #31
0
 def __init__(self, pin):
     """ 初期化メソッド """
     self.pin = pin  # GPIOピン
     self._degree = 0  # 角度の初期値
     # wiringpiの初期化
     # wiringpi.wiringPiSetupGpio() は __init__.py で実行済み
     wiringpi.pinMode(self.pin, wiringpi.PWM_OUTPUT)
     wiringpi.pwmSetMode(0)
     wiringpi.pwmSetRange(1024)
     wiringpi.pwmSetClock(self.PWM_CLOCK)
예제 #32
0
 def __init__(self, filter_pos, pin=18, pwmc=192, pwmr=2000):
     self.pin = pin
     wiringpi.wiringPiSetupGpio()
     wiringpi.pinMode(self.pin, wiringpi.GPIO.PWM_OUTPUT)
     wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
     wiringpi.pwmSetClock(pwmc)
     wiringpi.pwmSetRange(pwmr)
     self.N = len(filter_pos)
     self.filter_pos = filter_pos
     self.pos = 0
     wiringpi.pwmWrite(self.pin, self.pos)
	def __init__(self):
		# GPIO番号でピンを指定
		wiringpi.wiringPiSetupGpio()

		self.servos = []
		for index in RPiDirectServoController.PIN_MAP.iterkeys():
			pin = RPiDirectServoController.PIN_MAP[index]
			# サーボを作る
			self.servos.append(SG90Direct(pin, self.getPartName(index), RPiDirectServoController.PWM_COUNTUP_FREQUENCY, RPiDirectServoController.PWM_CYCLE_RANGE))

		wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
		wiringpi.pwmSetClock(RPiDirectServoController.PWM_COUNTUP_FREQUENCY)
		wiringpi.pwmSetRange(RPiDirectServoController.PWM_CYCLE_RANGE)
	def __init__(self, outputPinA, outputPinB, pwmPin):

		self.outA = outputPinA
		self.outB = outputPinB
		wp.pinMode(self.outA, OUTPUT_MODE)
		wp.pinMode(self.outB, OUTPUT_MODE)
		self.forward()

		wp.pwmSetMode(0)
		wp.pwmSetClock(400)
		wp.pwmSetRange(PWM_MAX)

		self.pwm = pwmPin
		wp.pinMode(self.pwm, PWM_MODE)
		self.speed = PWM_MIN
		self.setSpeed(self.speed)
def io_init():
  global io_initialized
  if io_initialized:
    return

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

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

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

  io_initialized = True
예제 #36
0
    def initialize_state(self):
        self._not_initialized = False
        self._MAX_SPEED = self.config.get('max_motor_speed', 10)
        self._MIN_SPEED = self._MAX_SPEED * -1
        self.MIN_SERVO = self.config.get('min_servo', 100)
        self.MAX_SERVO = self.config.get('max_servo', 100)
        self.ZERO_SERVO = self.config.get('zero-servo', 150)
        self._INITIAL_SERVO = 100
        gears = 5
        for index in range(1, gears + 1):
            self.gear_lookup[index] = int((self._MAX_SPEED / gears) * index)
        logger.info('Setting gears: ' + str(self.gear_lookup))

        if self.use_motors or self.use_servo:
            res = wiringpi.wiringPiSetupGpio()
            if res != 0:
                logger.error('Could not set up software PWM')
        if self.use_motors:
            logger.info('Setting up Motor Software-Based PWM')
            # a cluster of horrible looking code, should be refactored but is it single use???
            wiringpi.pinMode(self.m1conf.get('en_pin'), wiringpi.GPIO.OUTPUT)
            wiringpi.pinMode(self.m1conf.get('dir_pin'), wiringpi.GPIO.OUTPUT)
            wiringpi.pinMode(self.m2conf.get('en_pin'), wiringpi.GPIO.OUTPUT)
            wiringpi.pinMode(self.m2conf.get('dir_pin'), wiringpi.GPIO.OUTPUT)
            logger.info('Pull both motors out of low-power mode')
            wiringpi.digitalWrite(self.m1conf.get('en_pin'), 1)
            wiringpi.digitalWrite(self.m2conf.get('en_pin'), 1)
            logger.info('Set up motor software pwm')
            wiringpi.softPwmCreate(self.m1conf.get('pwm_pin'), 0, self._MAX_SPEED)
            wiringpi.softPwmCreate(self.m2conf.get('pwm_pin'), 0, self._MAX_SPEED)
            wiringpi.softPwmWrite(self.m1conf.get('pwm_pin'), 0)
            wiringpi.softPwmWrite(self.m2conf.get('pwm_pin'), 0)
            logger.info('Setting motor speeds to zero.')
        if self.use_servo:
            logger.info('Setting up Servo Hardware-Based PWM')
            wiringpi.pinMode(self.servo_gpio_pin, wiringpi.GPIO.PWM_OUTPUT)
            wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
            wiringpi.pwmSetClock(192)
            wiringpi.pwmSetRange(2000)
            logger.info('Servo config done')
            wiringpi.pwmWrite(self.servo_gpio_pin, self.ZERO_SERVO)
            logger.info('Setting servo speed to zero.')
예제 #37
0
    def __init__(self, sensor_pin=27, detector_delay=1, settletime=0.01):
        """ Initialize the tripwire.  See module documentation for the details
            of the parameter settings used here.
        """
        self.sensor_pin = sensor_pin
        self.detector_delay = detector_delay
        self.logger = logging.getLogger('main.tripwire')

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.sensor_pin, GPIO.IN)
        
        wiringpi.wiringPiSetupGpio()
        wiringpi.pinMode(PWM_PIN, 2)
        # Choose mark-space mode for better frequency control
        wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
        wiringpi.pwmSetRange(2)
        wiringpi.pwmSetClock(253)
        
        wiringpi.pwmWrite(PWM_PIN, 1) # set duty cycle to 1 over range=2, or 50%
        
        time.sleep(settletime) # I'm not sure how long is necessary,
                                  # the demodulator datasheet
                                  # suggests at least 0.0004 s
        self.logger.info('IRon curtain initialized.')
예제 #38
0
                playerState.pause()
#            elif lastEvent == eventPrefix + "<b>CE_Automate<li>resumed</b>" or 
            elif lastEvent == eventPrefix + "<b>playeractions<li>playback_resumed</b>":
                playerState.resume()
            else:
                rootLogger.warn("Event not recognized: " + lastEvent)

PWM_FREQ = config.getfloat('lights', 'pwm_freq')

TL_PWM = 1 # gpio pin 12 = wiringpi no. 1 (BCM 18)

# Initialize PWM output for theater lights
wiringpi.wiringPiSetup()

if config.get('lights', 'pwm_mode') == 'HW':
    wiringpi.pwmSetMode(0) # PWM_MODE_MS
    wiringpi.pwmSetClock(math.trunc(18750 / PWM_FREQ))
    wiringpi.pinMode(TL_PWM, 2)     # PWM mode
    wiringpi.pwmWrite(TL_PWM, 0)    # OFF
elif config.get('lights', 'pwm_mode') == 'SW':
    wiringpi.pinMode(TL_PWM, 1)     # Software PWM mode
    wiringpi.softPwmCreate(TL_PWM, 0, 100) # Setup PWM using Pin, Initial Value and Range parameters
else:
    rootLogger.error("Invalid pwm_mode: {0}. Exiting...".format(config.get('lights', 'pwm_mode')))

def updateLights():
    global tlConfig
    STEP_INTERVAL = 1 / PWM_FREQ # how often
    STEP_BRIGHTNESS = 1 / (tlConfig.lightsFadeTime * PWM_FREQ) # how much
    
    currentBrightness = 1.00
예제 #39
0
PWM_MODE_MS = 0
PWM_PIN=18
ROTATE_NEUTRAL = 90
PWM_RANGE = 1024
PWM_CLOCK = 375
TICK_S = 0.5
MESSAGE_DELIM = ';'

last_ts = 0

# can call wiringPiSetupSys() if we've previously exported GPIO pins
wiringpi.wiringPiSetupGpio()

# use PWM on port 18
wiringpi.pinMode(PWM_PIN, 2)
wiringpi.pwmSetMode(PWM_MODE_MS)
wiringpi.pwmSetClock(PWM_CLOCK)
wiringpi.pwmSetRange(PWM_RANGE)

rotation = ROTATE_NEUTRAL

def angle_to_duty_cycle(angle=0):
	# 2.5ms of 20ms pulse is full 180deg swing
	ubound = 0.1
	offset = 0.5/20 * PWM_RANGE
	# set duty cycle as 0-180deg expressed as 0-1024
	return int(offset + float(angle) / 180 * ubound * PWM_RANGE)

def on_connect(aioClient):
	global last_ts
    	rotate_arm(ROTATE_NEUTRAL)
예제 #40
0
import wiringpi as wPi
from time import sleep

pin = 18
wPi.wiringPiSetupGpio()

wPi.pinMode(pin, 2)
wPi.pwmSetMode(wPi.PWM_MODE_MS)
wPi.pwmSetClock(1920)
wPi.pwmSetRange(200)

def killing():
    print("killing")
    wPi.pwmWrite(pin, 0)
    wPi.pinMode(pin, 0)

try:
    for i in range(10):
        print(i)
        wPi.pwmWrite(pin, 15)
        sleep(0.5)
        wPi.pwmWrite(pin, 20)
        sleep(0.5)
        wPi.pwmWrite(pin, 10)
        sleep(0.5)
    killing()

except KeyboardInterrupt:
    killing()
	def setPwm(self):
		wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
		wiringpi.pwmSetClock(self.CLOCK)
		wiringpi.pwmSetRange(self.RANGE)
예제 #42
0
파일: servo.py 프로젝트: mnrozhkov/candybot
import wiringpi
import time
import math

#use BCM pin numbers
wiringpi.wiringPiSetupGpio()

# setup WiringPi PWM
SERVO_PIN = 18
PWM_DIVISOR = 384 # clock at 50kHz (20us tick)
PWM_RANGE = 1000  # range at 1000 ticks (20ms)

# setup pin as an output
wiringpi.pinMode(SERVO_PIN, 2)
wiringpi.pwmSetMode(0)
wiringpi.pwmSetClock(PWM_DIVISOR)
wiringpi.pwmSetRange(PWM_RANGE)
wiringpi.pwmWrite(SERVO_PIN, 0) #theretically 50 (1ms) to 100 (2ms) on my servo 40-200 works ok

def set_servo_position(pos):
    """ 
    Turn servo on specified angle in degrees

    Params:
        pos: angle to turn servo, in degrees
    """
    
    move = int(40 + math.floor(pos * (200 - 40) / 180))
    print("pos: {}".format(pos))
    print("move: {}".format(move))
wp.pwmWrite(PWM_R, 0)

#enable pins motor1 -- Lmotor
wp.pinMode(INPUT_1_LEFT_MOTOR, OUTPUT_MODE)
wp.pinMode(INPUT_2_LEFT_MOTOR, OUTPUT_MODE)

#enable pins motor2 -- Rmotor
wp.pinMode(INPUT_1_RIGHT_MOTOR, OUTPUT_MODE)
wp.pinMode(INPUT_2_RIGHT_MOTOR, OUTPUT_MODE)

wp.pinMode(GIFT_PIN, INPUT_MODE)
wp.pinMode(TREE_PIN, INPUT_MODE)

wp.pinMode(12, PWM_MODE)
wp.pinMode(13, PWM_MODE)
wp.pwmSetMode(0)
wp.pwmSetClock(400)
wp.pwmSetRange(1024)
wp.pwmWrite(12,0)
wp.pwmWrite(13,0) 

class easy_encoders():

    #encoder pin numbers on pi (broadcom numbering scheme)
    RW_A = 20 #pin = 38
    RW_B = 26 #pin = 37
    LW_A = 19 #pin = 35
    LW_B = 16 #pin =36

    #encoder counts
    rw_count = 0
예제 #44
0
# Servo Control
import time
import wiringpi
 
# use 'GPIO naming'
wiringpi.wiringPiSetupGpio()
 
# set #18 to be a PWM output
wiringpi.pinMode(16, wiringpi.GPIO.PWM_OUTPUT)
 
# set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
 
# divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)
 
delay_period = 0.01
 
while True:
        for pulse in range(50, 250, 1):
                wiringpi.pwmWrite(16, pulse)
                time.sleep(delay_period)
        for pulse in range(250, 50, -1):
                wiringpi.pwmWrite(16, pulse)
                time.sleep(delay_period)
예제 #45
0
파일: arrow.py 프로젝트: macole/note
import wiringpi as pi, time, math
from lis3dh import lis3dh

sleep_time = 0.01

servo_pin = 18

pi.wiringPiSetupGpio()
pi.pinMode( servo_pin, 2 )
pi.pwmSetMode(0)
pi.pwmSetRange(1024)
pi.pwmSetClock(375)

SPI_CS = 0

lis3dh = lis3dh( pi, SPI_CS )

angle_deg = 0.0

while True:
	x= lis3dh.read( pi, "x" )
	y= lis3dh.read( pi, "y" )
	z= lis3dh.read( pi, "z" )

	angle_reg = math.atan2( y, z )
	angle_deg_new = math.degrees( angle_reg )

	angle_deg = angle_deg * 0.9 + angle_deg_new * 0.1

	print ("x:", x, "  y:", y, "  z:", z, " angle:", angle_deg)