Skip to content

Instantly share code, notes, and snippets.

@boseji
Created November 4, 2013 00:32
Show Gist options
  • Save boseji/7296435 to your computer and use it in GitHub Desktop.
Save boseji/7296435 to your computer and use it in GitHub Desktop.
Python code for Raspberry Pi to generate square wave at 20% duty cycle at GPIO7 pin 26 of P1 with 1kHz frequency
#!/usr/bin/python
#####
# This program would generate PWM on GPIO7 Pin 26 of P1
# with 20% Duty Cycle at 1kHz
######
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(7,GPIO.OUT)
p=GPIO.PWM(7,1190)
p.start(13.8)
raw_input("Press Enter key to Stop 1kHz PWM @ 20% duty cycle")
GPIO.cleanup()
@Anjen1
Copy link

Anjen1 commented Nov 28, 2013

Hey, just wanted to thank you for providing this program. I wasn't sure how to generate square waves, but between this and the docs it all makes sense now.

regards,

aj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment