Higgins909
Posts: 5
Joined: Sun May 26, 2013 9:32 pm

PWM by Pi or Arduino?

Sun Sep 20, 2015 7:36 am

Can a Pi work with a arduino board to give PWM signals?
How much PWM work can a Pi do by itself? I have a project on mind and it may take many servos/electronic speed controls.
I once heard that the cpu didn't have enough power to work it well, but have seen a video of a guy having about 6-8 servos hooked up as well as a camera that watched for faces.

Then I wondered if the Pi itself can't support many channels, what about attaching a arduino board?

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: PWM by Pi or Arduino?

Sun Sep 20, 2015 8:28 am

The Pi can do PWM by itself, and using some creative techniques it's accurate and repeatable.

Google for "pigpio" for a great example.

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: PWM by Pi or Arduino?

Sun Sep 20, 2015 10:54 am

One could better do that thru the Adafruit Servo HAT. This nice print works with I2C, so you can stack a lot of them. It takes care of it's own timing by an onboard chip, so the RPi is not bothered with that. Each board drives up to 16 servo's and when stacked, you can drive up to 996 servo's. Also, every board can have it's own PSU to feed the servo's.

See this Github repository of mine in which you will find a program that is written around this board. Especially the gawServoHandler.py is an include that takes care of positioning the servo's.

Another program in there (gawServoCalibrate.py) can help you to accurately position your servo's, see the accompanying gawServoCalibrate.md.

This program (rasp_routes_py.py) has been written for model railroad purposes, to be able to set routes three a series of turnouts by pressing one button at the start, and one at the end of a route.

HTH,
Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
MEgg
Posts: 5
Joined: Sun Sep 20, 2015 11:35 am

Re: PWM by Pi or Arduino?

Sun Sep 20, 2015 12:04 pm

Higgins909 wrote:Can a Pi work with a arduino board to give PWM signals?
How much PWM work can a Pi do by itself? I have a project on mind and it may take many servos/electronic speed controls.
I once heard that the cpu didn't have enough power to work it well, but have seen a video of a guy having about 6-8 servos hooked up as well as a camera that watched for faces.

Then I wondered if the Pi itself can't support many channels, what about attaching a arduino board?
I am using a Raspberry Pi B+
plus
Dagu Spider controller ( take a look here
http://cdn.instructables.com/FOP/HB95/H ... MEDIUM.jpg
and here:
http://wiki.jmoon.co/boards/spider-controller/ )
together with this motor controller:
http://www.robotshop.com/media/files/pd ... s011mc.pdf
to control the motors of the Dagu 5 robot ( http://www.dagurobot.com/goods.php?id=48 ).
The Spider controller with an Arduino 2560 and the Raspberry are connected via
serial with a level converter ( https://www.sparkfun.com/products/12009 ) in between,
because Arduino has 5V and Raspberry Pi B+ has 3V3.
Since I am only beginning, currently I can only control a motor from my keyboard
( forward, backward, speed, stop, check the current the motors are consuming, e.g. stall current).

I am looking for the fritzing items ( http://fritzing.org/learning/get-started ) for all this to display how the parts are linked together and to ask questions.

Higgins909
Posts: 5
Joined: Sun May 26, 2013 9:32 pm

Re: PWM by Pi or Arduino?

Mon Sep 21, 2015 12:33 am

I started to question what is compatible with python?
pigpio says its got a C library, but has a python module?
The video I watched mentioned python and arduino, but having issues finding python in arduino.
adafruit seems to be python compatible?
spider controller?

Right now I'm also wondering if I can ever program python to take a live input from ssh or even do any of this over ssh?
or do I need a gui? I planed for it to be a remote use and use ssh and somehow have a python script that would take live input from my keyboard till I ctrl + c out. Like arrow keys on keyboard 1-9 to give different forward speeds, every left or right arrow would change steering servo by 2 deg or something, all without typing commands.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: PWM by Pi or Arduino?

Mon Sep 21, 2015 1:20 am

Higgins909 wrote:I started to question what is compatible with python?
pigpio says its got a C library, but has a python module?
The video I watched mentioned python and arduino, but having issues finding python in arduino.
adafruit seems to be python compatible?
spider controller?

Right now I'm also wondering if I can ever program python to take a live input from ssh or even do any of this over ssh?
or do I need a gui? I planed for it to be a remote use and use ssh and somehow have a python script that would take live input from my keyboard till I ctrl + c out. Like arrow keys on keyboard 1-9 to give different forward speeds, every left or right arrow would change steering servo by 2 deg or something, all without typing commands.
Yes, you can do it all with Python. You can control servos directly from the Pi's GPIO pins. You can control motors using radio control model ESC modules, again controlled by a Pi GPIO. No extra hardware is needed.

You can run your control program from the command line over an ssh session. Or you could install a webserver in the Pi and control everything with a web GUI.

I suggest you start with a simple project, such as one servo controlled by pigpio (or servoblaster).

Have fun!

User avatar
GerardWassink
Posts: 103
Joined: Sun Aug 02, 2015 5:57 pm
Location: Ulrum (Gr), Netherlands
Contact: Website

Re: PWM by Pi or Arduino?

Mon Sep 21, 2015 6:02 am

Have you even looked at my Github project?

Because all you're asking is in there, ssh control, all-python, the works. I have not had the need for controlling with arrow keys, so mine is 'command-line' like in accepting commands, but I'm sure someone has figured out how to do that.

Gerard
---------ooooO----- \\\\\|/// -----Oooo--------
Hacker on ELF-II, ZX80/1, Commodore 64, 8080, x86,
IBM 370 family mainframes
Machine code! Assembly! C good second.
Running Pi's with Hercules and S/370 OS's

-------------oooO-----------Oooo-------------

User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Re: PWM by Pi or Arduino?

Mon Sep 21, 2015 6:39 am

I use RPIO http://pythonhosted.org/RPIO/ which provides python hardware PWM with 1us minimum resolution and 300Hz maximum carrier frequency on any GPIO pin. No need for adafruit servo blaster / Arduino - all driven by the RPi hardware itself.
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

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

Re: PWM by Pi or Arduino?

Mon Sep 21, 2015 8:46 am

As said several times there is no need for external hardware.

My pigpio providing pulses for 24 servos.

http://abyz.co.uk/videos/servo_demo.webm

From Python

Code: Select all

#!/usr/bin/env python

import time

import pigpio

# servo_demo.py
# 2015-09-21
# Public Domain

pi = pigpio.pi() # Connect to local Pi.

# Code assumes a Pi with a 40 pin expansion header or a compute module.

for g in range(2, 27):
   pi.set_servo_pulsewidth(g, 500 + (g-2)*77)

time.sleep(5)

for g in range(2, 27):
   pi.set_servo_pulsewidth(g, 0)

pi.stop() # Disconnect from Pi.
or the command line

Code: Select all

paul ~ $ for ((g=2;g<27;g++)); do pigs s $g $((500 + (g-2)*77)); done
paul ~ $ for ((g=2;g<27;g++)); do pigs s $g 0; done

User avatar
MEgg
Posts: 5
Joined: Sun Sep 20, 2015 11:35 am

Re: PWM by Pi or Arduino?

Sun Sep 27, 2015 1:52 pm

Higgins909 wrote:I started to question what is compatible with python?
pigpio says its got a C library, but has a python module?
The video I watched mentioned python and arduino, but having issues finding python in arduino.
adafruit seems to be python compatible?
spider controller?

Right now I'm also wondering if I can ever program python to take a live input from ssh or even do any of this over ssh?
or do I need a gui? I planed for it to be a remote use and use ssh and somehow have a python script that would take live input from my keyboard till I ctrl + c out. Like arrow keys on keyboard 1-9 to give different forward speeds, every left or right arrow would change steering servo by 2 deg or something, all without typing commands.
I am also just beginning with all that.
I am using
minicom -b 115200 -o -D /dev/ttyAMA0
via ssh on my Raspberry for the serial connection to the Arduino Spider board .
The Spider controller is just an Arduino Mega 2560.
The Arduino is connected to the motor controller.

Therefore I have defined a set of keyboard controls to control my robot remotely via WLAN.
E.g. up = increase speed
down = decrease speed
s = full stop
r = back
v = forward (I am speaking German, therefore (v)orwärts = forward, (r)ückwärts = back ;-) )
w = actual PWM value , amperes drawn by motors, encoder counts
h = half speed
f = full speed

My plan is to pack Raspberry B+, Spider controller (which will do servo control also) and motor controller onto the robot
and then the only connection to the robot will be PC <----WLAN(UMTS?)--->Raspberrry.

With some tiny modifications I also managed to program the Spider controller on my Raspberry with arduino 1.0.1 .
The instructions here:
http://razzpisampler.oreilly.com/ch10.html
say that one has to disable serial communication but that was not necessary in my case.
I have minicom running and arduino 1.0.1 at the same time.

Sounds complicated but it is very easy:
PC/N900 as Handy <---WLAN + ssh ----> Raspberry B+ <----serial/USB for programming with arduino---> Spider Motor controller <-----> 4CH Motor controller <---> Dagu 5 Rover

Return to “Beginners”