User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

WiringPi PWM in Python

Sun Oct 21, 2012 4:14 pm

Got wiringpi installed with the Python wrap and need to drive 2 motors using pwm.

Searched the relevant forums and Googled everything but seem to be getting conflicting answers.

Will wiringpi for Python handle pwm for 2 motors and if so how (source)?
If not am I better off using C/C++?
If I need to use C which compiler is best?

Any help appreciated, things were so much easier in the Atari days ;)
Apple say... Monkey do !!

eyebee
Posts: 35
Joined: Tue Sep 25, 2012 7:05 pm
Location: Los Angeles, CA

Re: WiringPi PWM in Python

Sun Oct 21, 2012 8:06 pm

Take a look at joan's comments in this thread:
http://www.raspberrypi.org/phpBB3/viewt ... 37&t=20587

User avatar
Grumpy Mike
Posts: 973
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: WiringPi PWM in Python

Mon Oct 22, 2012 9:01 am

Will wiringpi for Python handle pwm for 2 motors and if so how (source)?
The Raspberry Pi only has one PWM output that is wired out to the GPIO pins. The second PWM is wired up to the speaker jack but you will need to remove the output filter and solder a wire direct onto the board to get at it.
If not am I better off using C/C++?
Makes no difference to the problem.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: WiringPi PWM in Python

Mon Oct 22, 2012 12:06 pm

You can always try it like this
http://www.raspberrypi.org/phpBB3/viewt ... wm+scratch

I use Rpi.GPIO and not wiringpi but the same technique should work fine

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

6677
Posts: 383
Joined: Wed Mar 14, 2012 9:23 pm

Re: WiringPi PWM in Python

Mon Oct 22, 2012 8:19 pm

Grumpy Mike wrote:
Will wiringpi for Python handle pwm for 2 motors and if so how (source)?
The Raspberry Pi only has one PWM output that is wired out to the GPIO pins. The second PWM is wired up to the speaker jack but you will need to remove the output filter and solder a wire direct onto the board to get at it.
If not am I better off using C/C++?
Makes no difference to the problem.
Wiring pi bit bangs PWM on all the other GPIO capable pins. We all know that there are performance issues in doing so but generally for the purposes of getting some motor speed control its more than adequete







If not am I better off using C/C++?
It may alleviate some of the performance issues of the above mentioned bit banging but not noticeably so. Chances are if your just doing the tradition IR/ultrasound/laser rangefinder + servo + 2 motors affair then you will be fine although I would dedicate the servo to the hardware PWM pin and leave the bit banging for the motors.
Will wiringpi for Python handle pwm for 2 motors and if so how (source)?
It will. Source in python I cannot share but this is a link about using wiring pi with C/C++ to achieve the exact same thing. http://letsmakerobots.com/node/34774

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: WiringPi PWM in Python

Tue Oct 23, 2012 4:34 pm

6677, thanks very much, that's what I wanted to know.

And thanks everybody else for your input.

:)
Apple say... Monkey do !!

texy
Forum Moderator
Forum Moderator
Posts: 5171
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: WiringPi PWM in Python

Wed Oct 24, 2012 8:27 am

Wiringpi for C may well support PWM on all GPIO pins, but that doesn't mean that wiringpi for python does. The problem is that currently the python version is not pulling Gordon's latest wiringpi code.
Then again, it may 'just work'.
Has this been proven?

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: WiringPi PWM in Python

Wed Oct 24, 2012 9:12 am

The problem is that currently the python version is not pulling Gordon's latest wiringpi code.
This is the issue with using wiringpi in python - Gordon doesn't support it - he's a rough and tough C man :) and no-one has taken it upon themselves to reliably incorporate his work into Python.

Since RPi.GPIO "just works" in Python and then I recommend just writing your own PWM code (I did it- how hard can it be! :) )

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
Grumpy Mike
Posts: 973
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: WiringPi PWM in Python

Wed Oct 24, 2012 3:35 pm

I recommend just writing your own PWM code (I did it- how hard can it be! :) )
Is it using the hardware PWM or is it bit banging?
Care to share Si.

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: WiringPi PWM in Python

Wed Oct 24, 2012 4:44 pm

I posted it back up the thread :)
http://www.raspberrypi.org/phpBB3/viewt ... wm+scratch
Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

User avatar
aboudou
Posts: 98
Joined: Wed Aug 08, 2012 12:38 pm
Location: Cintegabelle, France
Contact: Website

Re: WiringPi PWM in Python

Wed Oct 24, 2012 8:55 pm

Grumpy Mike wrote:
I recommend just writing your own PWM code (I did it- how hard can it be! :) )
Is it using the hardware PWM or is it bit banging?
Care to share Si.
If needed, I wrote a simple PWM Python library (software PWM) which should be enough if you don't need a high level accuracy. It's available here : https://github.com/aboudou/pizypwm
https://goddess-gate.com/ - My main website
http://raspberrypi.goddess-gate.com/ - A website about (and hosted by) my Raspberry Pi
https://twitter.com/boudouarnaud - Follow me on Twitter
http://www.fablab-sud31.fr/ - Fab Lab Sud31-Val d'Ariège

6677
Posts: 383
Joined: Wed Mar 14, 2012 9:23 pm

Re: WiringPi PWM in Python

Thu Oct 25, 2012 3:05 pm

For 2 motors he probably wouldn't need the hugest amount of accuracy ever.

Return to “Python”