Page 1 of 1

WiringPi PWM in Python

Posted: Sun Oct 21, 2012 4:14 pm
by davef21370
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 ;)

Re: WiringPi PWM in Python

Posted: Sun Oct 21, 2012 8:06 pm
by eyebee
Take a look at joan's comments in this thread:
http://www.raspberrypi.org/phpBB3/viewt ... 37&t=20587

Re: WiringPi PWM in Python

Posted: Mon Oct 22, 2012 9:01 am
by Grumpy Mike
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.

Re: WiringPi PWM in Python

Posted: Mon Oct 22, 2012 12:06 pm
by simplesi
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

Re: WiringPi PWM in Python

Posted: Mon Oct 22, 2012 8:19 pm
by 6677
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

Re: WiringPi PWM in Python

Posted: Tue Oct 23, 2012 4:34 pm
by davef21370
6677, thanks very much, that's what I wanted to know.

And thanks everybody else for your input.

:)

Re: WiringPi PWM in Python

Posted: Wed Oct 24, 2012 8:27 am
by texy
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

Re: WiringPi PWM in Python

Posted: Wed Oct 24, 2012 9:12 am
by simplesi
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

Re: WiringPi PWM in Python

Posted: Wed Oct 24, 2012 3:35 pm
by Grumpy Mike
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.

Re: WiringPi PWM in Python

Posted: Wed Oct 24, 2012 4:44 pm
by simplesi
I posted it back up the thread :)
http://www.raspberrypi.org/phpBB3/viewt ... wm+scratch
Simon

Re: WiringPi PWM in Python

Posted: Wed Oct 24, 2012 8:55 pm
by aboudou
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

Re: WiringPi PWM in Python

Posted: Thu Oct 25, 2012 3:05 pm
by 6677
For 2 motors he probably wouldn't need the hugest amount of accuracy ever.