neteng
Posts: 24
Joined: Wed May 11, 2016 3:56 am

Raspberry Pi with Arduino

Wed May 11, 2016 4:43 am

Hi all,

I have a robotic arm project. The arm has 6 motors, of which the 6th is the gripper motor. Since the Pi only has one pwm pin, I want to use an Arduino board to generate the respective pwm signals needed for the motors. I want my algorithm(inverse Kinematics and forward kinematics) to be computed by the Pi....Send the relevant signals to the Arduino for it to generate the 6 pwm signals.

Is this possible???........Help.....

Note that the encoder output from each motors will be read by the Pi.......

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Raspberry Pi with Arduino

Wed May 11, 2016 8:27 am

neteng wrote:Hi all,

I have a robotic arm project. The arm has 6 motors, of which the 6th is the gripper motor. Since the Pi only has one pwm pin, I want to use an Arduino board to generate the respective pwm signals needed for the motors. I want my algorithm(inverse Kinematics and forward kinematics) to be computed by the Pi....Send the relevant signals to the Arduino for it to generate the 6 pwm signals.

Is this possible???........Help.....

Note that the encoder output from each motors will be read by the Pi.......
First pick the method that the Pi will use to communicate with the Arduino (USB or Serial are probably the better options).
Pick the format for your output data.
Determine Transmission failure criteria.
Write your arduino sketch to generate PWM signals based on the signals the Pi will output.
Doug.
Building Management Systems Engineer.

User avatar
B.Goode
Posts: 8917
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Raspberry Pi with Arduino

Wed May 11, 2016 8:57 am

Your choice of an Arduino to interface directly with the servos may be correct, but note that while it is true to say that the RPi has only one hardware-controlled pwm pin you should be aware that any/all of the gpio pins on the RPi can be used to generate pwm signals under software control. A library such as pigpio http://abyz.co.uk/rpi/pigpio/index.html allows you to do this on the RPi very easily.

Note that the servos will need an independent power supply.

If you still want to separate the two functions you might like to consider firmata https://github.com/firmata/protocol as a means of communicating between the RPi and Ardunio. (There are other similar libraries available, this happens to be the one I have experimented with.)

neteng
Posts: 24
Joined: Wed May 11, 2016 3:56 am

Re: Raspberry Pi with Arduino

Thu May 12, 2016 12:36 am

B.Goode wrote:Your choice of an Arduino to interface directly with the servos may be correct, but note that while it is true to say that the RPi has only one hardware-controlled pwm pin you should be aware that any/all of the gpio pins on the RPi can be used to generate pwm signals under software control. A library such as pigpio http://abyz.co.uk/rpi/pigpio/index.html allows you to do this on the RPi very easily.

Note that the servos will need an independent power supply.

If you still want to separate the two functions you might like to consider firmata https://github.com/firmata/protocol as a means of communicating between the RPi and Ardunio. (There are other similar libraries available, this happens to be the one I have experimented with.)
Thanks bro......I need 12 pins for my encoders......5 from my limit switches.......So the pins on the Pi will ultimately be scarce.....Thus I have decided to do the scheme as such....And also we are cautious of our Pi....So we employ the Arduino ......

mthomason
Posts: 113
Joined: Sun Apr 24, 2016 12:28 pm

Re: Raspberry Pi with Arduino

Thu May 12, 2016 1:37 am

Another option could be to use something like this:
https://www.adafruit.com/product/815
Which not only gives you 12 PWM pins that you can drive over I2C, but also allows you to plug the servos into it directly for PWM, Power, and Ground (you'll still need a power supply to plug into it to provide power to the servos, but it'll make routing the cables easier)

They've actually done a tutorial for hooking it up to a Pi, too:
https://learn.adafruit.com/adafruit-16- ... spberry-pi
Although personally I'd leave out the Pi Cobbler and just wire it directly onto the Pi's I2C (or create an I2C bus on a breadboard if using more than one I2C device)

User avatar
kolban
Posts: 143
Joined: Fri Dec 04, 2015 1:45 am
Location: Texas, USA

Re: Raspberry Pi with Arduino

Thu May 12, 2016 3:24 am

I second @mthomason's idea ... but for me (being very price sensitive - read as poor), I went with the sub $4.00 version available on eBay see... http://www.ebay.com/itm/PCA9685-16-Chan ... 1402794566

The "primary" component is the PCA9685 IC. If you search eBay for this part, you'll find a bunch of different vendors. There are also driver libraries for most Pi languages.
FREE book on Raspberry Pi usage and programming

https://leanpub.com/pi

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: Raspberry Pi with Arduino

Thu May 12, 2016 8:24 am

you may use an Arduino Due or Mega to generate the pwm signals, both have lots of hardware pwm pins (min. 12, pins 2...13)

You can interface them via UART or USB (Due directly, Mega on UART with level shifter!), or you may use i2c to communicate (works just for the Due).
pwm on Arduino is 8bit (0-255).

Just transmit 2-3 bytes for each pwm port:
a) pin number (2...13)
b) pwm value (0...255)
c) perhaps a direction signal (maybe also coded in the pin number (2...13 forward, -2...-13 reverse) )

then a H bridge (e.g., L293 or L298) can provide the power for motor control

Here is how I did the communication (tested by a Pi 2 and mostly a Arduino Due - scroll some posts up and down!):

UART Pi to Arduino http://www.mindstormsforum.de/viewtopic ... 907#p67815
I2C Pi to Arduino: http://www.mindstormsforum.de/viewtopic ... 909#p67909

I strongly recommend the Due, a China clone costs just 14-20 EUR (Ebay)


HTH!
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

neteng
Posts: 24
Joined: Wed May 11, 2016 3:56 am

Re: Raspberry Pi with Arduino

Sat Jul 23, 2016 5:26 am

The optical encoder for our motors have a 5VDC Vcc and a 2 channels output.......I want the ouputs to be fed to the Raspberry Pi's GPIO. However, the Pi's GPIO are 3.3V TTL......Is it still possible to still integrate the encoder as such???......By providing a sort of intermediate level converter between the Pi and the encoder???

Return to “Beginners”