adi33
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.

evilkitty
Posts: 370
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 - https://github.com/WiringPi/WiringPi-Python

Code: Select all

#!/usr/bin/python
import wiringpi as piwiring # the name seems backwards IMO
import time

pin=18
piwiring.wiringPiSetupGpio()
try:
     #hardware pwm
     piwiring.pinMode(pin, 2)
     piwiring.pwmWrite(pin, 512) # 50%
     time.sleep(3)
     piwiring.pwmWrite(pin, 0) # 0%

     #software pwm
     piwiring.pinMode(pin, 1)
     piwiring.softPwmCreate(pin,0,100)
     piwiring.softPwmWrite(pin, 50) # 50%
     time.sleep(3)
     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() # https://www.wyliodrin.com/wiki/_media/ciscoupb/j8header.png

piwire.pinMode(pin, X) # 0=Input; 1=Output; 2=PWM
piwire.pullUpDnControl(pin, X) # 0=None; 1=Pull Down; 2=Pull Up
piwire.digitalRead(pin)
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
piwire.softPwmWrite(pin,50)
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: http://imgur.com/a/6xIUI | Thermostat: http://imgur.com/a/4LVnT

User avatar
joan
Posts: 14354
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.

See http://abyz.co.uk/rpi/pigpio/python.html#hardware_PWM

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
jefferson_palheta
Posts: 10
Joined: Thu Apr 27, 2017 8:22 pm
Contact: Twitter

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”