def __init__(self): """Initialise movement.""" PWM.setup() #get rid of debug output PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) #pins #i2c pins can be enabled high at boot - see http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=35321 self._l_enable_pin = 4 self._l_forward_pin = 3 self._l_backward_pin = 2 self._r_enable_pin = 17 self._r_forward_pin = 27 self._r_backward_pin = 22 #constants self.LEFT = 1 self.RIGHT = 2 #setup the pins RPIO.setup(self._l_forward_pin, RPIO.OUT) RPIO.setup(self._r_forward_pin, RPIO.OUT) RPIO.setup(self._l_backward_pin, RPIO.OUT) RPIO.setup(self._r_backward_pin, RPIO.OUT) #pwm setup self._dma_l = 0 self._dma_r = 1 PWM.init_channel(self._dma_l) PWM.init_channel(self._dma_r) #this is silly, but otherwise pwm will complain if we try and clear a channel that hasn't been already used PWM.add_channel_pulse(self._dma_l,self._l_enable_pin,0,0) PWM.add_channel_pulse(self._dma_r,self._r_enable_pin,0,0)
def __init__(self, pin, location, rotation, name): #--------------------------------------------------------------------------- # The GPIO BCM numbered pin providing PWM signal for this ESC #--------------------------------------------------------------------------- self.bcm_pin = pin #--------------------------------------------------------------------------- # The location on the quad, and the direction of the motor controlled by this ESC #--------------------------------------------------------------------------- self.motor_location = location self.motor_rotation = rotation #--------------------------------------------------------------------------- # The PWM pulse width range required by this ESC in microseconds #--------------------------------------------------------------------------- self.min_pulse_width = 1000 self.max_pulse_width = 2000 #--------------------------------------------------------------------------- # The PWM pulse range required by this ESC #--------------------------------------------------------------------------- self.current_pulse_width = self.min_pulse_width self.name = name #--------------------------------------------------------------------------- # Initialize the RPIO DMA PWM #--------------------------------------------------------------------------- if not PWM.is_setup(): PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) PWM.setup(1) # 1us increment PWM.init_channel(RPIO_DMA_CHANNEL, 3000) # 3ms carrier period PWM.add_channel_pulse(RPIO_DMA_CHANNEL, self.bcm_pin, 0, self.current_pulse_width)
def init(frequency=FREQUENCY, multi_channel=MULTI_CHANNEL): # frequency: frequency in herts # multi_channel: true or false if multi_channel: CHANNEL_A = 0 CHANNEL_B = 1 CHANNEL_C = 2 CHANNEL_D = 3 else: CHANNEL_A = 0 CHANNEL_B = 0 CHANNEL_C = 0 CHANNEL_D = 0 pwm = {"A": [PIN.CEL_A_1, PIN.CEL_A_2, CHANNEL_A, frequency], "B": [PIN.CEL_B_1, PIN.CEL_B_2, CHANNEL_B, frequency], "C": [PIN.CEL_C_1, PIN.CEL_C_2, CHANNEL_C, frequency], "D": [PIN.CEL_D_1, PIN.CEL_D_2, CHANNEL_D, frequency]} PWM.setup() testing = 0 testing = testing + init_pwm(pwm['A'][2], pwm['A'][3]) testing = testing + init_pwm(pwm['B'][2], pwm['B'][3]) testing = testing + init_pwm(pwm['C'][2], pwm['C'][3]) testing = testing + init_pwm(pwm['D'][2], pwm['D'][3]) if not((testing == 4)): print("ERROR: Something went wrong while Initializing one or more PWMs") return pwm
def initGPIO(self): if self.cnf.offline: self.logger.info("TEST: import PWM") self.logger.info("TEST: import MFRC522") self.logger.info("TEST: initializing PWM") return # We're careful as to not import the # RPIO itself; as it magically claims # pin 22; thus conflicting with MFRC522. # import RPIO.PWM as PWM PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) PWM.setup(pulseInc) PWM.init_channel(relayChannel, subcycle_time_us=int(1e6 / frequency)) PWM.init_channel(ledChannel, subcycle_time_us=int( 1e6 / 1)) # Cycle time in microSeconds == 1 second # Flash top LED while we get our bearings. # self.setTopLED(20) # Note: The current MFC522 library claims pin22/GPIO25 # as the reset pin -- set by the constant NRSTPD near # the start of the file. # import MFRC522 MIFAREReader = MFRC522.MFRC522()
def setup(): PWM.setup() PWM.init_channel(DMA_LEFT,10000) PWM.init_channel(DMA_RIGHT,10000) PWM.add_channel_pulse(DMA_LEFT, LEFT_FORWARD, 0, 0) PWM.add_channel_pulse(DMA_LEFT, LEFT_BACKWARD, 0, 0) PWM.add_channel_pulse(DMA_RIGHT, RIGHT_FORWARD, 0, 0) PWM.add_channel_pulse(DMA_RIGHT, RIGHT_BACKWARD, 0, 0)
def init_pwm(self): '''Initialize PWM configuration. We are using RPIO.PWM to implement software PWM via DMA, using the PCM implementation. We initalize three DMA channels, one for each color.''' LOG.debug('initializting PWM configuration') PWM.setup(delay_hw=PWM.DELAY_VIA_PCM) PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) for ch in [0, 1, 2]: PWM.init_channel(ch)
def __init__(self, DO_DIRECTION_PIN, DO_RESET_PIN, DI_FAULT_PIN, ARGS): self.REG = { # AMIS-30543 Registers 'WR': 0x00, 'CR0': 0x01, 'CR1': 0x02, 'CR2': 0x03, 'CR3': 0x09, 'SR0': 0x04, 'SR1': 0x05, 'SR2': 0x06, 'SR3': 0x07, 'SR4': 0x0A } self.CMD = { # AMIS-30543 Command constants 'READ': 0x00, 'WRITE': 0x80 } self.dirctrl = ARGS[0] self.pwmf = ARGS[1] self.pwmj = ARGS[2] self.sm = ARGS[3] self.mult = ARGS[4] self.dist = ARGS[5] self.step = ARGS[6] self.VAL = { 'WR': 0b00000000, # no watchdog 'CR0': 0b00010111 | self.sm, # & 2.7 A current limit 'CR1': 0b00000000 | self.dirctrl | self.pwmf | self.pwmj, # & step on rising edge & fast slopes 'CR2': 0b00000000, # motor off & no sleep & SLA gain @ 0.5 & SLA no transparent 'CR3': 0b00000000 #, # no extended step mode #'dist': self.dist, #'step': self.step } # InitGPIO PWM.setup(5, 0) # 5 us pulse_incr, 0 delay_hw PWM.init_channel(0, 3000) # DMA channel 0, 3000 us subcycle time self.DO_RESET = gpiozero.DigitalOutputDevice(DO_RESET_PIN) self.DO_DIRECTION = gpiozero.DigitalOutputDevice(DO_DIRECTION_PIN) self.DI_NO_FAULT = gpiozero.DigitalInputDevice(DI_FAULT_PIN) self.spi = SpiDev() self.spi.open(0, 0) self.spi.max_speed_hz = 1000000 self.RegisterSet()
def __init__(self, gpioPin): # RPIO PWM initalization if PWM.is_setup() == 0: PWM.setup(pulse_incr_us=self.pulseIncrementUs) self.gpioPin = gpioPin self.dutyCycle = self.initialpulsewidth self.pwmChannel = self.getFreePwmChannel() PWM.init_channel(self.pwmChannel, subcycle_time_us=self.subCycleTime)
def initMotor(self): RPIO.setup(self.MODE_Pin,RPIO.OUT,initial=RPIO.HIGH); #select PWM Mode; PWM.setup(); #initialize channel 0 and 1 for motor A and B PWM.init_channel(self.A_CHANNEL); PWM.init_channel(self.B_CHANNEL); RPIO.setup(self.APHASE_Pin,RPIO.OUT,initial=RPIO.LOW); #default A to fwd direction PWM.add_channel_pulse(self.A_CHANNEL,self.AENBL_Pin,0,0);#default A to channel 0 and speed 0 RPIO.setup(self.BPHASE_Pin,RPIO.OUT,initial=RPIO.LOW); #default B to fwd direction PWM.add_channel_pulse(self.B_CHANNEL,self.BENBL_Pin,0,0);#default B to channel 1 and speed 0
def __init__(self, redPin, greenPin, bluePin): if not PWM.is_setup(): PWM.setup(10,1) self.pins = [redPin, greenPin, bluePin] a=2 while PWM.is_channel_initialized(a): a=a+1 self.channels = [a, a+1, a+2] for channel_num in self.channels: PWM.init_channel(channel_num, subcycle_time_us=10000)
def initialize(self): # Setup PWM if backlight is defined if self.__backlight: PWM.setup() PWM.init_channel(0) self.enableBacklight() # Setup rs, enable and rw pins GPIO.setup(self.__rs, GPIO.OUT) GPIO.setup(self.__enable, GPIO.OUT) if self.__rw: GPIO.setup(self.__rw, GPIO.OUT)
def __init__(self, pins): """Pin configuration. [pins] : List of the the pins to use for R,G and B (GPIO.BCM numbering). """ pins = [int(pin) for pin in pins.split(",")] if not len(pins) == 3: raise ValueError("Configuration must contain three pins (pins=" + str(pins) + ")") self._pins = pins # PWM setup PWM.setup(pulse_incr_us=PWM_RES) PWM.init_channel(PWM_DMA, subcycle_time_us=PWM_PRD) PWM.init_channel(PWM_DMA1, subcycle_time_us=PWM_PRD1)
def __init__(self, gpio=18, period=20000, ch_count=6): self.gpio = gpio self.period = period self.channel_count = ch_count self.control_ppm = PWM.Servo() PWM.setup() # add channels and set init value as 150 for ch in range(1, self.channel_count): PWM.init_channel(ch, self.period) PWM.add_channel_pulse(ch, self.gpio, self.default_channel_width, self.default_channel_value) self.default_channel_value.insert(ch, self.default_channel_value)
def set_brightness(self, percent): # Make our percentage logarithmic from 0 to 100 for a more natural brightness curve percent = (float(percent)/10)**2 # Divide the 20ms period into 4 pulses so we get 200Hz # pulse width in 10us increments. pulse_width = int((100-percent) * 5) if (not PWM.is_setup()): PWM.setup() PWM.init_channel(0) PWM.add_channel_pulse(0, self.lcd_backlight, start=0, width=pulse_width) PWM.add_channel_pulse(0, self.lcd_backlight, start=499, width=pulse_width) PWM.add_channel_pulse(0, self.lcd_backlight, start=999, width=pulse_width) PWM.add_channel_pulse(0, self.lcd_backlight, start=1499, width=pulse_width)
def __init__(self, channel=PWM_CHANNEL, pin=PWM_PIN, subcycle=PWM_SUBCYCLE, unit=PWM_UNIT): self._channel = channel self._pin = pin self._subcycle = subcycle self._range = int(subcycle / unit) if not PWM.is_setup(): PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) PWM.setup() # work around bug in RPIO.PWM, https://www.raspberrypi.org/forums/viewtopic.php?p=509549 signal.signal(signal.SIGCHLD, signal.SIG_IGN) if not PWM.is_channel_initialized(self._channel): PWM.init_channel(self._channel, self._subcycle)
def pwm_example2(): from RPIO import PWM # Setup PWM and DMA channel 0 PWM.setup() PWM.init_channel(0) # Add some pulses to the subcycle PWM.add_channel_pulse(0, 17, 0, 50) PWM.add_channel_pulse(0, 17, 100, 50) # Stop PWM for specific GPIO on channel 0 PWM.clear_channel_gpio(0, 17) # Shutdown all PWM and DMA activity PWM.cleanup()
def __init__(self): PWM.cleanup() PWM.setup(1) PWM.init_channel(1, 5000) PWM.init_channel(2, 5000) PWM.init_channel(3, 5000) self.r = 0 self.g = 0 self.b = 0 self.dimFactor = 1. self.fadeTimer = None self.fadeCallback = None self.fadeStartTime = datetime.now() self.fadeSeconds = None
def main(): # Set up Frequency in Hertz FREQUENCY = 1000 SUBCYCLE_US = ((1 / FREQUENCY) * 1000000) CHANNEL = 0 # Set duty_cycle 0 -> 100 DUTY_CYCLE = 50 # Set Pin PINO = PIN.CEL_A_1 # Setup PWM and DMA channel 0 PWM.setup() PWM.init_channel(channel=CHANNEL, subcycle_time_us=SUBCYCLE_US) # Test initialization if not (PWM.is_channel_initialized(CHANNEL)): print("ERROR: Channel could not be initialized!") return -1 # Test Frequency if not (PWM.get_channel_subcycle_time_us(CHANNEL) == SUBCYCLE_US): print("ERROR: Frequency could not be setted!") return -1 # Add pwm Pulse PWM.add_channel_pulse(dma_channel=CHANNEL, gpio=PINO, start=0, width=((SUBCYCLE_US / 10) * (DUTY_CYCLE / 100))) # fake while print("Press any key to stop") input() # Stop PWM for specific GPIO on channel 0 PWM.clear_channel_gpio(0, PINO) # Shutdown all PWM and DMA activity PWM.cleanup() return 0
def start(self): if not PWM.is_setup(): PWM.setup() if not PWM.is_channel_initialized(0): PWM.init_channel(0) #same as look_forward() without clearing first PWM.add_channel_pulse(0, self.pPanL, 0, self.pan_centerL) PWM.add_channel_pulse(0, self.pTiltL, 0, self.tilt_centerL) PWM.add_channel_pulse(0, self.pPanR, 0, self.pan_centerR) PWM.add_channel_pulse(0, self.pTiltR, 0, self.tilt_centerR) RPIO.setup(self.pPanicBtn, RPIO.IN) RPIO.add_interrupt_callback(self.pPanicBtn, edge='falling', pull_up_down=RPIO.PUD_UP, callback=self.cb_panic, debounce_timeout_ms=200) RPIO.wait_for_interrupts(threaded=True)
def __init__(self): PWM.setup() PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) PWM.init_channel(0) self.num = { 0: (1, 1, 1, 1, 1, 1, 0), 1: (0, 1, 1, 0, 0, 0, 0), 2: (1, 1, 0, 1, 1, 0, 1), 3: (1, 1, 1, 1, 0, 0, 1), 4: (0, 1, 1, 0, 0, 1, 1), 5: (1, 0, 1, 1, 0, 1, 1), 6: (1, 0, 1, 1, 1, 1, 1), 7: (1, 1, 1, 0, 0, 0, 0), 8: (1, 1, 1, 1, 1, 1, 1), 9: (1, 1, 1, 1, 0, 1, 1) } self.pulse = {0: 4, 1: 999} PWM.add_channel_pulse(0, 20, 0, 999) PWM.add_channel_pulse(0, 21, 1000, 999)
def pwm_setup(): pwm.set_loglevel(pwm.LOG_LEVEL_ERRORS) pwm.setup(5) pwm.init_channel(0, 5000)
import RPIO.PWM as PWM PWM.setup(30) PWM.init_channel(1, 3000) PWM.clear_channel_gpio(1, 18) PWM.clear_channel(1) PWM.cleanup()
from RPIO import PWM PWM.setup() PWM.init_channel(0) PWM.add_channel_pulse(0, 12, 0, 50) PWM.add_channel_pulse(0, 12, 100, 50) PWM.clear_channel_gpio(0, 12) input('waiting...') PWM.cleanup()
import gaugette.rotary_encoder import gaugette.switch import gaugette.rgbled import telnetlib import sys import time import math import re import RPIO.PWM as PWM PWM.setup(pulse_incr_us=10, delay_hw=0) PWM.init_channel(0) # gebruik DMA channel 0 art_host = "192.168.1.5" art_zone = "1" art_source = "3" A_PIN = 7 #7 B_PIN = 9 #5 SW_PIN = 8 #3 VP_PIN = 0 #11 VM_PIN = 3 #13 NX_PIN = 2 #15 PV_PIN = 12 #16 LI_PIN = 9 #WPi 13 #Pin 21 LR_PIN = 25 #WPi 6 #Pin 22 LG_PIN = 11 #WPi 14 #Pin 23 LB_PIN = 8 #WPi 10 #Pin 24
from RPIO import PWM import time PWM.setup(pulse_incr_us=5) PWM.init_channel(0, subcycle_time_us=20000) PWM.add_channel_pulse(0, 7, 0, 300) while (True): eingabe = raw_input('Wert eingeben') PWM.add_channel_pulse(0, 7, 0, int(eingabe)) #time.sleep(2) #PWM.add_channel_pulse(0,7,0,300) #time.sleep(2) #PWM.clear_channel(0) #time.sleep(2) #PWM.add_channel_pulse(0,7,0,285) #time.sleep(2) #for i in range(300,350,1): # PWM.add_channel_pulse(0,7,0,i) # time.sleep(1) #PWM.clear_channel_gpio(0,7) #PWM.cleanup() #motor = PWM.Servo() #print PWM.get_pulse_incr_us() #motor.set_servo(7,1500) #time.sleep(2) #while(True): # eingabe = raw_input('Wert eingebe:') # if(eingabe=='v'): # for i in range(1500,2000,10): # print i # motor.set_servo(7,i)
def setup(): webiopi.debug("Script with macros - Setup") # Setup PWM and DMA channel 0 PWM.setup() PWM.init_channel(0)
import hardware.encoder as encoder import hardware.esc as esc import hardware.motor as motor import hardware.imu as imu import thread import re import RPIO.PWM as PWM #setup: PWM.cleanup() PWM.setup(pulse_incr_us=10, delay_hw=0) component_measure = encoder.encoders(24,23) #pins A and B component = encoder.encoder(22) #pin C component_measure.update() mymotor = esc.motor('m1', 5, simulation=False) mymotor.start() mymotor.setW(0) #x = imu.IMU_device(0x19,0x6b,0x1e) #remember to connect the imu, #addresses are fixed mot1 = motor.motor() driver1 = mot1.driver() driver1.add_motor(21,20)#put the right pins for each of the motors driver1.add_motor(26,16) driver2 = mot1.driver()
def __init__(self, leds): if not PWM.is_setup(): PWM.setup(10,1) self.leds = leds
def __init__(self): if not PWM.is_setup(): PWM.setup() #put this in def __init__():
""" import RPIO.PWM as PWM import time GPIO_R = 17 GPIO_G = 18 GPIO_B = 27 GPIO_BUZ = 22 CHANNEL = 0 PERIOD_CH0 = 4000 # 4ms = 250Hz PERIOD_CH1 = 4000 # 4ms = 250Hz PWM.set_loglevel(PWM.LOG_LEVEL_DEBUG) PWM.setup(10, 0) PWM.init_channel(0, PERIOD_CH0) #PWM.init_channel(1, PERIOD_CH1) PWM.print_channel(0) #PWM.print_channel(1) list_R = [255, 255, 255, 0, 0, 0, 255] list_G = [0, 128, 255, 255, 0, 0, 0] list_B = [0, 0, 0, 0, 255, 130, 255] r = 0 g = 0 b = 0 k = PERIOD_CH0 - 10.0 #PWM.add_channel_pulse(1, GPIO_BUZ, 0, 390)
subcycle_time = [3000, 4000, 5000, 6000] #[3000, 5000, 100000, 150000] #min=3000microsec. da moltiplicare per granularity (default: 10 microsecondi) #(in millisec. sono: 20ms, 200ms, 5sec, 10sec) #pulse_start = [200, 20, 50, 100] #_start=200*100 microsec=20 msec. #pulse_width = [100, 500, 1000, 5000] #_width=100*100 microsec=10 msec. pulse_start = [0, 20, 60, 100] #_start=x*10 microsec pulse_width = [50, 50, 50, 50] #_width=x*10 microsec #incr_impulso = [10, 10, 10, 10] canale_dma = [0, 1, 2, 3] #ce ne sono 15 (0-14) gpio_port = [18, 23, 24, 25] #porte GPIO (lato pin pari) #frequency = [500, 50, 2, 1] #in Hz #set della granularity (è il default durante l'inizializzazione tic di incremento in microsecondi) PWM.setup(granularity, 0) #default: pulse_incr_us=10, delay_hw=0 for i in canale_dma: PWM.init_channel(i, subcycle_time[i]) #canale DMA con tempo subcycle # PWM.setup(granularity, 0) #default: pulse_incr_us=10, delay_hw=0 #aggiungo un impulso nel canale DMA all'interno di ogni subcycle per ogni GPIO #POSSO ANCHE NON AGGIUNGERE NIENTE :-), VOLENDO. # PWM.add_channel_pulse(i, gpio_port[i], pulse_start[i], pulse_width[i]) PWM.add_channel_pulse(0, gpio_port[0], pulse_start[0], pulse_width[0]) PWM.add_channel_pulse(1, gpio_port[1], pulse_start[1], pulse_width[1]) PWM.add_channel_pulse(2, gpio_port[2], pulse_start[2], pulse_width[2]) PWM.add_channel_pulse(3, gpio_port[3], pulse_start[3], pulse_width[3]) #setup per output su GPIO for j in gpio_port:
def io_init(): PWM.setup() PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)
def __init__(self): PWM.setup(3) PWM.init_channel(5, 3000) PWM.init_channel(6, 3000) PWM.init_channel(7, 3000) self.mapping = {17, 27, 22}
def trying(event): if event.type == pygame.JOYBUTTONDOWN: if event.button == PS3_BUTTON_SELECT: #do something print elif event.button == PS3_BUTTON_START: #do something print elif event.button == PS3_BUTTON_TRI: #shut down the motors and and shut down the system (power off.) stop() p.stop() os.system('sudo poweroff') elif event.button == PS3_BUTTON_X: #run clockwise function counter_clockwise() print 'back' elif event.button == PS3_BUTTON_SQUARE: #stop motor 1 print 'stop' stop() elif event.button == PS3_BUTTON_UP: #reboot the system os.system('sudo reboot') if event.type == pygame.JOYAXISMOTION: if event.axis == PS3_AXIS_LEFT_VERTICAL: #This is used to control the forwards and backwards movement. #if event.value>=.24: # print 'stop' # stop() if event.value>=threshold: clockwise() speed=int(event.value*100) p.ChangeDutyCycle(speed) if event.value>=-.24: if event.value<0: stop() elif event.value<=-threshold: counter_clockwise() speed=-1*(int(event.value*100)) p.ChangeDutyCycle(speed) elif event.axis == PS3_AXIS_RIGHT_HORIZONTAL: #This is used to control the left and right movement. if event.value>=threshold: clockwise1() speed=int(event.value*500) if PWM.is_setup() == 1: #set up the pwm to be set out. PWM.add_channel_pulse(0,22,0,speed) else: PWM.setup() PWM.init_channel(0) PWM.add_channel_pulse(0,22,0,speed) if event.value>=-.24: if event.value<0: stop1() elif event.value<=-threshold: counter_clockwise1() speed=-1*(int(event.value*500)) if PWM.is_setup() == 1: #set up pwm PWM.add_channel_pulse(0,22,0,speed) else: PWM.setup() PWM.init_channel(0) PWM.add_channel_pulse(0,22,0,speed)
from RPIO import PWM import time DMA_CH = 0 GPin = 21 SSTime = 1000000 PWM.setup(1000, 0) PWM.init_channel(DMA_CH, SSTime) PWM.add_channel_pulse(DMA_CH, GPin, 0, 200) PWM.add_channel_pulse(DMA_CH, GPin, 250, 50) PWM.add_channel_pulse(DMA_CH, GPin, 350, 25) PWM.add_channel_pulse(DMA_CH, GPin, 450, 50) time.sleep(5) PWM.clear_channel_gpio(DMA_CH, GPin) PWM.cleanup()
#------------------------------------------------------------------------------ # RGB LED Test App. #------------------------------------------------------------------------------ import io import time import math import RPIO.PWM as PWM print('Starting RGB LED Test') #PWM.set_loglevel(PWM.LOG_LEVEL_DEBUG) PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) PWM.setup(pulse_incr_us=10) PWM.init_channel(0, subcycle_time_us=10000) PWM.print_channel(0) BLUE_LED = 2 RED_LED = 3 GREEN_LED = 4 PWM.add_channel_pulse(0, BLUE_LED, 0, 1000) PWM.add_channel_pulse(0, RED_LED, 0, 1000) PWM.add_channel_pulse(0, GREEN_LED, 0, 1000) startTime = time.time() speed = 4.0 brightness = 100 r = 0.0 g = 0.0 b = 0.0
# MOTOR 1 GPIO.output(MD1 ,1) # IN1 GPIO.output(MD2 ,1) # IN2 # MOTOR 2 GPIO.output(ME1 ,1) # IN3 GPIO.output(ME2 ,1) # IN4 #////////////MAIN\\\\\\\\\ #---INICIALIZAÇÃO stdscr = curses.initscr() #Inicia Curses curses.noecho() #Desabilita Verbose Terminal - Curses curses.cbreak() #Habilita terminal para apenas um caractere - Curses stdscr.keypad(1) #Habilita Uso do Teclado Numérico - Curses stdscr.refresh() #Atualiza Tela - Curses PWM.setup() #Inicia PWM - RPIO/PWM PWM.init_channel(0) #Inicia Canal PWM para Servo Câmera - RPIO/PWM #---LOOP PRINCIPAL tecla = '' while tecla != ord('q'): tecla = stdscr.getch() if tecla == curses.KEY_UP: eixox=1 acelerar(1,eixox) elif tecla == curses.KEY_DOWN: eixox=0 acelerar(1,eixox) elif tecla == curses.KEY_LEFT: dire=1 rota(8,dire)
import RPIO from RPIO import PWM import time # Top and bottom LEDs # - Flash alternating. # PWM.setup(1000) # Pulse increment in micro Seconds = 1 milli Second PWM.init_channel(0, subcycle_time_us=1000000) # Cycle time in microSeconds == 1 second # All values from here are in mSeconds. # PWM.add_channel_pulse(0, 23, start=500, width=499) PWM.add_channel_pulse(0, 24, start=0, width=499) time.sleep(5) # Needed to clear down the GPIO back to input (cleanup() does not do that). # PWM.clear_channel_gpio(0,23) PWM.clear_channel_gpio(0,24) # Shutdown all PWM and DMA activity PWM.cleanup()
""" Until someone builds a good RPIO library for Node, I will be using """ import zerorpc from RPIO import PWM if not PWM.is_setup(): PWM.setup(pulse_incr_us=1) PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS) PWM.init_channel(1,3000) class RPIOHelper(object): def addChannelPulse(self, gpio, rate): PWM.add_channel_pulse(1, gpio, 0, int(rate)) s = zerorpc.Server(RPIOHelper()) s.bind("tcp://0.0.0.0:4242") s.run()
import time import RPi.GPIO as GPIO import RPIO.PWM as PWM #setting headder pins #Chnl = 13 PWM.setup(1) PWM.init_channel(1, 3000) #PWMPinW = 18 PWM.add_channel_pulse(1, 18, 0, 1000) PWM.add_channel_pulse(1, 23, 0, 1500) while True: time.sleep(1)
GPIO.setup(24, GPIO.OUT) #1 bank 3 GPIO.output(24, GPIO.LOW) GPIO.setup(26, GPIO.OUT) #1 bank 3 GPIO.output(26, GPIO.LOW) GPIO.setup(32, GPIO.OUT) #1 bank 3 GPIO.output(32, GPIO.LOW) GPIO.setup(36, GPIO.OUT) #1 bank 3 GPIO.output(36, GPIO.LOW) GPIO.setup(38, GPIO.OUT) #1 bank 3 GPIO.output(38, GPIO.LOW) GPIO.setup(40, GPIO.OUT) #1 bank 3 GPIO.output(40, GPIO.LOW) """ PWM.setup() PWM.init_channel(0) """ class FuncThread(threading.Thread): def __init__(self, target, *args): self._target = target self._args = args threading.Thread.__init__(self) def run(self): self._target(*self._args)
subcycle_time = [3000, 5000, 100000, 150000] #moltiplicare per granularity (default: 10 microsecondi) #(in millisec. sono: 20ms, 200ms, 5sec, 10sec) #pulse_start = [200, 20, 50, 100] #_start=200*100 microsec=20 msec. #pulse_width = [100, 500, 1000, 5000] #_width=100*100 microsec=10 msec. pulse_start = [0, 0, 0, 0] #_start=0*10 microsec=0 msec. pulse_width = [0, 0, 0, 0] #_width=0*10 microsec=0 msec. #incr_impulso = [10, 10, 10, 10] canale_dma = [0, 1, 2, 3] #ce ne sono 15 (0-14) gpio_port = [18, 23, 24, 25] #porte GPIO (lato pin pari) #frequency = [500, 50, 2, 1] #in Hz #set della granularity (è il default durante l'inizializzazione tic di incremento in microsecondi) PWM.setup(granularity, 0) #default: pulse_incr_us=10, delay_hw=0 for i in canale_dma: PWM.init_channel(i, subcycle_time[i]) #canale DMA con tempo subcycle # PWM.setup(granularity, 0) #default: pulse_incr_us=10, delay_hw=0 #aggiungo un impulso nel canale DMA all'interno di ogni subcycle per ogni GPIO #POSSO ANCHE NON AGGIUNGERE NIENTE :-), VOLENDO. PWM.add_channel_pulse(i, gpio_port[i], pulse_start[i], pulse_width[i]) #setup per output su GPIO for i in gpio_port: RPIO.setup(i, RPIO.OUT) for i in canale_dma: PWM.print_channel(i) if PWM.is_channel_initialized(i): print ("canale ", i, " inizializzato")
def pwm_setup(): pwm.set_loglevel(pwm.LOG_LEVEL_ERRORS) pwm.setup(INCREMENT_US) pwm.init_channel(DMA_CHANNEL, 5000)