Skip to content

Instantly share code, notes, and snippets.

@electronut
Created November 22, 2014 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electronut/191e3cc6225c40570221 to your computer and use it in GitHub Desktop.
Save electronut/191e3cc6225c40570221 to your computer and use it in GitHub Desktop.
For testing the hardware PWM capabilities of the Raspberry Pi Model A+.
"""
test_HW_PWM.py
For testing the hardware PWM capabilities of the Raspberry Pi Model A+.
Author: Mahesh Venkitachalam
Website: electronut.in
"""
import wiringpi2 as wiringpi
import time
print("starting PWM")
# use BCM GPIO numbers
wiringpi.wiringPiSetupGpio()
# enable PWM0
wiringpi.pinMode(18,2)
# 25% duty cycle
wiringpi.pwmWrite(18, 256)
# enable PWM1
wiringpi.pinMode(13,2)
# 75% duty cycle
wiringpi.pwmWrite(13, 768)
# loop
while True:
try:
time.sleep(0.5)
except:
# clean up
wiringpi.pwmWrite(18, 0)
wiringpi.pwmWrite(13, 0)
print("exiting.")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment