PWM output on pin 18 not possible?

1,363 views
Skip to first unread message

Stefan M Larsen

unread,
May 11, 2013, 6:07:50 PM5/11/13
to pi...@googlegroups.com
Hi,

I am trying to control a motor using the Gertboard and Pi4j. I have attached a test program in python using the wiring library. The python program uses GPIO pin 18 as PWM output, but Pi4j reports that
this is not supported:

"This GPIO pin [GPIO 18] does not support the pin mode specified [pwm_output]"

As I understand it, the Pi4j and wiring should use the same pin numbering, since Pi4j is based on wiring...

Have I misunderstood something, or is this a bug?

I am using 1.0_SNAPSHOT

Regards,
Stefan
motor-wp.py

Stefan M Larsen

unread,
May 11, 2013, 6:26:06 PM5/11/13
to pi...@googlegroups.com
BTW, I have tried version 0.0.5 with same result...

/Stefan

Pi4J

unread,
May 12, 2013, 6:27:05 AM5/12/13
to pi...@googlegroups.com
Hi Stefan,

WiringPi (and Pi4J) uses a different pin numbering scheme.  So the Broadcom GPIO #18 is really pin number #1 in wiringPi and thus also in Pi4J.  
This pin numbering abstraction is to help isolate your program from future pin number changes.  The broadcom and header pins numbers can move around but wiringPi and thus Pi4J maintain the pin abstraction so your program does not have to be modified between board revisions.   

This page includes the pin numbering scheme used for wiringPi. 

You can also see here on line 43 that pin #1 in Pi4J is the only one configured to support PWM:

So, just try Pi4J pin number #1 and I think you are good to go.

Thanks, Robert





Sean Curran

unread,
Jan 8, 2014, 10:08:18 PM1/8/14
to pi...@googlegroups.com, pi...@googlegroups.com
Is there a reason that this is the only pin that supports PWM?  Also, are there still plans to add support for new PWM related wiringPi methods?  I saw this mentioned in another thread.

Brian Wyld

unread,
Feb 19, 2015, 3:26:04 AM2/19/15
to pi...@googlegroups.com
Hi,

On the B+, pins 26 and 23 (p4j numbering, BCM pins 12 and 13) should support hardware PWM. Is this supported by p4j? (I can't get it to work using these pins!)

thanks

Brian

Robert Savage

unread,
Feb 20, 2015, 7:46:04 AM2/20/15
to pi...@googlegroups.com
Brian,

The code seems to suggest that PWM is supported on 23, 24, and 26.  I'll have to run some tests to see if its working properly.


public static final Pin GPIO_23 = createDigitalAndPwmPin(23, "GPIO 23"); // requires 2B, A+, B+ or newer model (40 pin header) : supports PWM1 [ALT0]
public static final Pin GPIO_24 = createDigitalAndPwmPin(24, "GPIO 24"); // requires 2B, A+, B+ or newer model (40 pin header) : supports PWM1 [ALT5]
public static final Pin GPIO_25 = createDigitalPin(25, "GPIO 25"); // requires 2B, A+, B+ or newer model (40 pin header)
public static final Pin GPIO_26 = createDigitalAndPwmPin(26, "GPIO 26"); // requires 2B, A+, B+ or newer model (40 pin header) : supports PWM0 [ALT0]

Robert Savage

unread,
Feb 21, 2015, 6:11:49 PM2/21/15
to pi...@googlegroups.com
Bryan,

I tested pins 1, 23, 24, and 26 on my oscilloscope using a RPi B+ model and all did appear to be working as PWM outputs. 
Below is my sample/test code:

package gpio.test;


import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinPwmOutput;
import com.pi4j.io.gpio.RaspiPin;


public class PwmTest {


   
/**
     * @param args the command line arguments
     * @throws java.lang.InterruptedException
     */

   
public static void main(String[] args) throws InterruptedException {
 
       
GpioController gpio = GpioFactory.getInstance();
       
GpioPinPwmOutput pwm = gpio.provisionPwmOutputPin(RaspiPin.GPIO_24);
        pwm
.setPwm(500);
       
       
// keep program running until user aborts (CTRL-C)
       
for (;;) { Thread.sleep(500); }        
   
}
   
}


Thanks, Robert

Reply all
Reply to author
Forward
0 new messages