This Python3 script was created to generate a square wave pattern from the GPIO of the Raspberry Pi. This signal was used to inject a signal into an electronics project, but could be used as the basis for any PWM needs.
The script is configured to output the signal
on pin 12 (GPIO18).
Other pins which may be used
are pin 32 (GPIO12)
and pin 33 (GPIO13).
Standard pin numbers (GPIO.BOARD
) are used, Broadcom
numbering (GPIO.BCM
) may be used if desired by editing the
appropriate line.
Configuration:
pwmPin
: Board Pin (changeGPIO.BOARD
toGPIO.BCM
to use Broadcom numbering)dutyCycle
: Duty cycle in percentfreq
: Pulse frequency in Hz