Posts: 1
Joined: Fri Jun 10, 2016 6:30 pm

Hardware pwm pins on raspberry pi mobel B+

Fri Jun 10, 2016 6:34 pm

i have a confusion about how many hardware pwm pins are on rpi. I haven't got proper answer. pls help.

Posts: 464
Joined: Tue Apr 15, 2014 11:39 pm

Re: Hardware pwm pins on raspberry pi mobel B+

Fri Jun 10, 2016 11:59 pm

there is only 1 hardware pwm pin, if you use need analog audio you can't use it as a hardware pwm
RPi.GPIO does not offer hardware pwm support, you will need to use a alternate library if you are using python
i picked use wiringpi -

Code: Select all

import wiringpi as piwiring # the name seems backwards IMO
import time

     #hardware pwm
     piwiring.pinMode(pin, 2)
     piwiring.pwmWrite(pin, 512) # 50%
     piwiring.pwmWrite(pin, 0) # 0%

     #software pwm
     piwiring.pinMode(pin, 1)
     piwiring.softPwmWrite(pin, 50) # 50%
     piwiring.softPwmWrite(pin, 0) # 0%
except KeyboardInterrupt:
     piwiring.pinMode(pin, 0)
this library also offers software pwm, i found it to be more consistent than RPi.GPIO implementation

Here are my scratch notes for this library

Code: Select all

import wiringpi as piwire

piwire.wiringPiSetupGpio() #

piwire.pinMode(pin, X) # 0=Input; 1=Output; 2=PWM
piwire.pullUpDnControl(pin, X) # 0=None; 1=Pull Down; 2=Pull Up
piwire.digitalWrite(pin, 0) # 0=Low; 1=High
piwire.pwmWrite(pin, X) # 0=Low; 1024=High; Use with pinMode 2 on GPIO18
piwire.softPwmCreate(pin,0,100) # Use with pinMode 1
I am using PWM for a simple buzzer, i ended up using wiringpi's softpwm feature on GPIO18 cause i use the audio jack
My Pi Server: | Thermostat:

User avatar
Posts: 16078
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Hardware pwm pins on raspberry pi mobel B+

Sat Jun 11, 2016 4:37 am

There are four accessible hardware PWM GPIO on the Pis with the 40 pin expansion header.

However there are only two channels so GPIO12 has the same setting as GPIO18 and GPIO13 has the same setting as GPIO19.


In addition DMA timed PWM (i.e. jitter free) may be used on all the other accessible GPIO if that's what you actually need.

User avatar
Posts: 10
Joined: Thu Apr 27, 2017 8:22 pm

Re: Hardware pwm pins on raspberry pi mobel B+

Mon Jul 10, 2017 4:51 pm

in my case, RP 3 B, pwm just work on this pins
WiringPi _______BCM
GPIO.1_______(BCM 18)
GPIO.23______(BCM 13)
GPIO.24______(BCM 24)
GPIO.26______(BCM 12)

Return to “General discussion”