Пример #1
0
 def __init__(self, xin1, xin2, channels):
     self.xin1 = xin1
     self.xin2 = xin2
     self.channel1 = channels[0]
     self.channel2 = channels[1]
     PWM.init_channel(self.channel1)
     PWM.init_channel(self.channel2)
Пример #2
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)
Пример #3
0
 def __init__(self, xin1, xin2, channels):
     self.xin1 = xin1
     self.xin2 = xin2
     self.channel1 = channels[0]
     self.channel2 = channels[1]
     PWM.init_channel(self.channel1)
     PWM.init_channel(self.channel2)
Пример #4
0
        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)
Пример #5
0
    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()
Пример #6
0
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)
Пример #7
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)
Пример #8
0
    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()
Пример #9
0
    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)
Пример #10
0
    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
Пример #11
0
    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)
Пример #12
0
    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)
Пример #13
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)
Пример #14
0
    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, 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)
Пример #16
0
    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)
Пример #17
0
    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)
Пример #18
0
        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)
Пример #19
0
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()
Пример #20
0
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
Пример #21
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)
Пример #22
0
    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)
Пример #23
0
def setup():
    # Setup PWM and DMA channel 0
    PWM.set_loglevel(1)
    print("Set loglevel\n")
    # PWM.setup()
    PWM.init_channel(0)

    # polarity pins are outputs:
    for pin in pins_pol:
        RPIO.setup(pin, RPIO.OUT, initial=RPIO.LOW)
        # defined as output
        # all output off

    for pin in pins_pwm:
        # Set servo on GPIO17 to 0 us. 20ms is one PWM period.
        servo.set_servo(pin, 0)  #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)
Пример #24
0
def init_pwm(channel, frequency):
    # channel_id = 2
    # channel: pwm['A'][channel_id],  pwm['B']channel_id,  pwm['C']channel_id,  pwm['D']channel_id
    # frequency: Frequency in Hz

    subcycle = (1/frequency)*1000000

    # if not already initialized by other pwms initialize channeç
    if not(PWM.is_channel_initialized(channel)):
        PWM.init_channel(channel, subcycle)

    # 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):
        print("ERROR: Frequency could not be setted!")
        return -1

    return 1
Пример #25
0
    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
Пример #26
0
def translate(value, inMin, inMax, outMin, outMax):
    # Figure out how 'wide' each range is
    inSpan = inMax - inMin
    outSpan = outMax - outMin

    # Convert the input range into a 0-1 range (float)
    valueScaled = float(value - inMin) / float(inSpan)

    # Convert the 0-1 range into a value in the output range.
    return outMin + (valueScaled * outSpan)


# Setup PWM and DMA channel 1
PWM.setup()
PWM.init_channel(1)
PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)

UDP_IP = "192.168.240.1"
UDP_PORT = 5005

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # Internet  # UDP
sock.bind((UDP_IP, UDP_PORT))

PWM.add_channel_pulse(1, 17, 0, 100)
sleep(0.5)
PWM.add_channel_pulse(1, 17, 0, 200)
sleep(0.5)
PWM.add_channel_pulse(1, 17, 0, 150)
sleep(0.5)
PWM.add_channel_pulse(1, 22, 0, 60)
Пример #27
0
from RPIO import PWM
from sys import stdin,stdout

pin=18

PWM.setup()
PWM.init_channel(13)
PWM.add_channel_pulse(13, pin ,0,0)
while True:
	userinput = stdin.readline().rstrip('\n')

	if userinput == 'quit':
		break
	else:
		stdout.write("LightValue: " + userinput)
		PWM.clear_channel_gpio(13, pin)
		PWM.add_channel_pulse(13, pin ,999,int(userinput))


Пример #28
0
import RPIO
from RPIO import PWM as PWM
import time

RPIO.setmode(RPIO.BOARD)

GPIO = 12
CHANNEL = 1

RPIO.setup(GPIO,RPIO.OUT)

# Setup PWM and DMA channel 0
PWM.set_loglevel(PWM.LOG_LEVEL_DEBUG)
PWM.setup()
PWM.init_channel(CHANNEL,20000)
PWM.print_channel(CHANNEL)

RPIO.output(GPIO, False)

def changespeed(current_speed,set_speed,step_size,delay):
  for counter in range (current_speed, set_speed, step_size):
    pwmmotor=int(round(counter*199,-1))
    print(pwmmotor)
    PWM.add_channel_pulse(CHANNEL,GPIO,0,pwmmotor)
    time.sleep(delay)

# Add some pulses to the subcycle
PWM.add_channel_pulse(CHANNEL, GPIO, 0, 0)

changespeed(0,100,1,0.02) # accelerate from 0 to 100% step 1% delay 0.02 S
Пример #29
0
green_gpio	= 24
blue_gpio	= 25
white_gpio	= 22
motion_gpio	= 18

# settings
motion_delay				= 0		# motion delay trigger ( boolean, 0 or 1 )
motion_delay_cycles			= 1200	# cycles, time dependent on sleep functions
num_motion_delay_cycles 	= 0		# number of cycles since last motion detected

# initiate motion input pin
RPIO.setup( motion_gpio, RPIO.IN )

# initiate software PWM
PWM.setup()
PWM.init_channel( 0, 10000 )
PWM.print_channel( 0 )

# start infinite loop
first_cycle = 1
while True:
	
	# first cycle
	#
	#	- fun startup lighting sequence
	#	- then turns all pins on in case some of the config_colors are set to zero
	#
	if first_cycle == 1:
		PWM.add_channel_pulse( 0, red_gpio, 0, 200 )
		time.sleep( 0.6 )
		PWM.clear_channel_gpio( 0, red_gpio )
Пример #30
0
import RPIO
from RPIO import PWM

RPIO.cleanup()

PWM.setup()

servo = PWM.Servo()
RPIO.setup(27, RPIO.OUT)
dcen = 27
RPIO.setup(22, RPIO.OUT)
dcdr = 22



PWM.init_channel(3)


class Control :
	Direction = 0
	Speed = 0


	@staticmethod
	def lefter ():
		Control.Direction= 1700
		Control.setdirection()

	@staticmethod
	def righter ():
		Control.Direction= 700
Пример #31
0
	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)
   elif tecla == curses.KEY_RIGHT:
"""
This example uses lower-level PWM control methods of RPIO.PWM. The default
settings include a subcycle time of 20ms and a pulse-width increment
granularity of 10us.

RPIO Documentation: http://pythonhosted.org/RPIO
"""
import RPIO.PWM as PWM

GPIO = 17
CHANNEL = 0

PWM.set_loglevel(PWM.LOG_LEVEL_DEBUG)

PWM.setup()
PWM.init_channel(CHANNEL)
PWM.print_channel(CHANNEL)

PWM.add_channel_pulse(CHANNEL, GPIO, 0, 50)
PWM.add_channel_pulse(CHANNEL, GPIO, 100, 50)
Пример #33
0
def get_DMA():
	a = find_DMA_available()
	PWM.init_channel(a)
	return a
Пример #34
0
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)
Пример #35
0
def pwm_setup():
    pwm.set_loglevel(pwm.LOG_LEVEL_ERRORS)
    pwm.setup(5)
    pwm.init_channel(0, 5000)
Пример #36
0
#-*- coding:utf-8 -*-
import RPIO
from RPIO import PWM

RPIO.cleanup()

PWM.setup()

servo = PWM.Servo()
RPIO.setup(27, RPIO.OUT)
dcen = 27
RPIO.setup(22, RPIO.OUT)
dcdr = 22

PWM.init_channel(3)


class Control:
    Direction = 0
    Speed = 0

    @staticmethod
    def lefter():
        Control.Direction = 1700
        Control.setdirection()

    @staticmethod
    def righter():
        Control.Direction = 700
        Control.setdirection()
Пример #37
0
from time import sleep

def translate(value, inMin, inMax, outMin, outMax):
    # Figure out how 'wide' each range is
    inSpan = inMax - inMin
    outSpan = outMax - outMin

    # Convert the input range into a 0-1 range (float)
    valueScaled = float(value - inMin) / float(inSpan)

    # Convert the 0-1 range into a value in the output range.
    return outMin + (valueScaled * outSpan)
 
# Setup PWM and DMA channel 1
PWM.setup()
PWM.init_channel(1)
PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)

UDP_IP = "192.168.240.1"
UDP_PORT = 5005
 
sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))

PWM.add_channel_pulse(1, 17, 0,100)
sleep(0.5)
PWM.add_channel_pulse(1, 17, 0,200)
sleep(0.5)
PWM.add_channel_pulse(1, 17, 0,150)
sleep(0.5)
Пример #38
0
import evdev
import RPi.GPIO as GPIO
import RPIO.PWM as PWM

#setting headder pins
GPIO.setmode(GPIO.BCM)
ChnlL = 13
ChnlR = 12
ChnlW = 11
PWM.setup(1)
PWM.init_channel(ChnlL, 3000)
PWM.init_channel(ChnlR, 3000)
PWM.init_channel(ChnlW, 3000)

#Initializing throttle and direction
RThrot = 0
LThrot = 0
sigLimit = 2900

#set direction pins
DirPinL = 23
DirPinR = 24
DirPinW = 25
GPIO.setup(DirPinL, GPIO.OUT)
GPIO.setup(DirPinR, GPIO.OUT)
GPIO.setup(DirPinW, GPIO.OUT)
PWMPinL = 17
PWMPinR = 27
PWMPinW = 18
PWM.add_channel_pulse(ChnlL, PWMPinL, 0, 0)
PWM.add_channel_pulse(ChnlR, PWMPinR, 0, 0)
Пример #39
0
#!/usr/bin/env python
from RPIO import PWM

PWM.setup()
PWM.init_channel(0, 1000000)

PWM.add_channel_pulse(0, 17, 0, 1400)

while True:
  pass

Пример #40
0
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)
while 1:
Пример #41
0
import RPIO.PWM as PWM

GPIO = 2
CHANNEL = 0
GPIO2 = 3
CHANNEL2 = 3

PWM.set_loglevel(PWM.LOG_LEVEL_DEBUG)

PWM.setup()
PWM.init_channel(CHANNEL)
PWM.print_channel(CHANNEL)

PWM.add_channel_pulse(CHANNEL, GPIO, 0, 500)

raw_input('Enter your input:')

PWM.init_channel(CHANNEL2)
PWM.print_channel(CHANNEL2)

PWM.add_channel_pulse(CHANNEL2, GPIO2, 600, 200)

raw_input('Enter your input:')

PWM.clear_channel(CHANNEL)

raw_input('Enter your input:')

PWM.clear_channel(CHANNEL2)

raw_input('Enter your input:')
Пример #42
0
#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:
	RPIO.setup(j, RPIO.OUT)

for k in canale_dma:
Пример #43
0
def get_DMA():
    a = find_DMA_available()
    PWM.init_channel(a)
    return a
Пример #44
0
import sys
import time
from sys import stdin,stdout

print "NewServoStarted"

print "ready"

pin=22

open=47
close=7


PWM.setup()
PWM.init_channel(14)
PWM.set_loglevel(PWM.LOG_LEVEL_ERRORS)


userinput = stdin.readline().rstrip('\n')

x=open
i=close+15

while i in range(close,open):
	i=i+1
	PWM.add_channel_pulse(14, pin , i, i)
	time.sleep(0.17)

PWM.clear_channel_gpio(14,pin)
time.sleep(int(userinput))
Пример #45
0
def initialize():
	PWM.init_channel(1,SUBCYCL)
Пример #46
0
RPIO.setup(SPIMISO, RPIO.IN)
RPIO.setup(SPICLK, RPIO.OUT)
RPIO.setup(SPICS, RPIO.OUT)
RPIO.setup(19, RPIO.OUT)
RPIO.setup(26, RPIO.OUT)
RPIO.setup(16, RPIO.OUT)
RPIO.setup(20, RPIO.OUT)
RPIO.setup(4, RPIO.IN, pull_up_down=RPIO.PUD_UP)

RPIO.add_interrupt_callback(4,
                            PWR_func,
                            edge="falling",
                            debounce_timeout_ms=50)

PWM.setup()
PWM.init_channel(11)
PWM.init_channel(12)
servo = PWM.Servo(dma_channel=8)
servo_pos = 1300
servo.set_servo(20, 1300)

# joystick ADC channels
joy_x_adc = 0
joy_y_adc = 1

while True:
    try:
        # get joystick position from ADC
        joy_x = readadc(joy_x_adc, SPICLK, SPIMOSI, SPIMISO, SPICS)
        joy_y = readadc(joy_y_adc, SPICLK, SPIMOSI, SPIMISO, SPICS)
Пример #47
0
r_backward_pin = 22

#constants
LEFT = 1
RIGHT = 2

#setup the pins
RPIO.setup(l_forward_pin, RPIO.OUT)
RPIO.setup(r_forward_pin, RPIO.OUT)
RPIO.setup(l_backward_pin, RPIO.OUT)
RPIO.setup(r_backward_pin, RPIO.OUT)

#pwm setup
dma_l = 0
dma_r = 1
PWM.init_channel(dma_l)
PWM.init_channel(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(dma_l,l_enable_pin,0,0)
PWM.add_channel_pulse(dma_r,r_enable_pin,0,0)

def stop_all():
    print "stop"
    PWM.clear_channel_gpio(dma_l, l_enable_pin)
    PWM.clear_channel_gpio(dma_r, r_enable_pin)

#direction, how long to drive for, how fast to drive
def drive(wheel,speed):
    if wheel == LEFT:
        print "left",
        dma = dma_l
Пример #48
0
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()
Пример #49
0
import time
import autopilot
from RPIO import PWM

PWM.init_channel(1, 18005)
autopilot.minAll()
time.sleep(5)
autopilot.maxAll()
time.sleep(30)
PWM.cleanup()
Пример #50
0
#------------------------------------------------------------------------------
# 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
Пример #51
0
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
Пример #52
0
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()

Пример #53
0
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()
Пример #54
0
def setup():
    webiopi.debug("Script with macros - Setup")

    # Setup PWM and DMA channel 0
    PWM.setup()
    PWM.init_channel(0)
Пример #55
0
#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")
	else:
		print ("canale ", i, " NON inizializzato")
	if PWM.is_setup():
Пример #56
0
"""
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()