Rpi PWM – Electronic Wings
https://www.electronicwings.com/raspberry-pi/raspberry-pi-pwm-generation-using-python-and-c
Raspberry Pi PWM and Servo Motor Tutorial Roland Pelayo June 6, 2018 5,295 Views
https://www.teachmemicro.com/raspberry-pi-pwm-servo-tutorial/#
Using PWM with RPi.GPIO and Python on the Raspberry Pi – 38,288 views
PWM0 = GPIO 12, GPIO 18
PWM1 = GPIO 13, GPIO 19
For the next part of series on Raspberry Pi, I will show how to produce a PWM signal from a pin. Moreover, I will show you how to control single and multiple servo motors in this Raspberry Pi PWM tutorial.
—
Using PWM in RPi.GPIO – Authors: Anonymous Ben Croston
https://sourceforge.net/p/raspberry-gpio-python/wiki/PWM/
To create a PWM instance:
p = GPIO.PWM(channel, frequency)
To start PWM:
p.start(dc) # where dc is the duty cycle (0.0 <= dc <= 100.0)
To change the frequency:
p.ChangeFrequency(freq) # where freq is the new frequency in Hz
To change the duty cycle:
p.ChangeDutyCycle(dc) # where 0.0 <= dc <= 100.0
To stop PWM:
p.stop()
Note that PWM will also stop if the instance variable ‘p’ goes out of scope.
An example to blink an LED once every two seconds:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 0.5)
p.start(1)
input(‘Press return to stop:’) # use raw_input for Python 2
p.stop()
GPIO.cleanup()
An example to brighten/dim an LED:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50) # channel=12 frequency=50Hz
p.start(0)
try:
while 1:
for dc in range(0, 101, 5):
p.ChangeDutyCycle(dc)
time.sleep(0.1)
for dc in range(100, -1, -5):
p.ChangeDutyCycle(dc)
time.sleep(0.1)
except KeyboardInterrupt:
pass
p.stop()
GPIO.cleanup()
.END
Categories: Raspberry Pi, Uncategorized