Arduino Forum

Using Arduino => General Electronics => Topic started by: DeceptX on May 31, 2013, 08:54 pm

Title: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: DeceptX on May 31, 2013, 08:54 pm
I'm trying to connect my Arduino Uno to my Raspberry Pi using the Rx/Tx pins instead of USB. I understand there is a difference in voltage, where the Pi uses 3.3V and the Uno uses 5V.

Is it possible to use optocouplers to do the connection? I have two 4N35 here. I'm a proffessional programmer but I have very limited knowledge of electronics. I was thinking if it's possible to connect the Uno's Tx to the 4N35 and then to its ground. Then connect the Pi's Rx to the 4N35 and then to its ground. Is this possible? Do I need to add a resistor?
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: Grumpy_Mike on May 31, 2013, 11:46 pm
This is how to do it. No need for opto isolators.
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: sonnyyu on Jun 01, 2013, 01:23 am
Plan B;-

Arduino TX to Pi RX  use 3 silicon diodes in series (5-3*0.6=3.2V) voltage drop or one 1.8 V Zener diode, either will drop the voltage to Pi levels. Pi TX to Arduino RX just connected, 3.3 volt won't hurt the Arduino and its close enough for the Arduino to receive it.

Use USB or powered USB hub is more common since this time not only Arduino is powered by Pi but also supported  up to 127 Arduinos same time.

Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: sonnyyu on Jun 01, 2013, 01:31 am
Plan C;-

Correct answer for OP, it is possible to use optocouplers to do the connection.

(http://s24.postimg.org/r98kja0gl/opto.jpg)

Opto-isolator Breakout sparkfun $4.95 (http://www.sparkfun.com/products/9118)

Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: DeceptX on Jun 01, 2013, 08:41 am
Thank you so much guys!
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: Matous on Jun 06, 2013, 10:55 am
Grumpy_mike, would you please advise me what transistor would be suitable for this application? I need it to be fast enough to handle serial communication, but I'm not sure how to find it myself...
And if when using your circuit the Arduino RX pin is high for some reason, could it damage the transistor or even the Pi? Thanks!
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: twinsfly on Jun 06, 2013, 03:50 pm
yeah,Thank you so much guys! (http://to.ly/lJNz)
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: Erni on Jun 06, 2013, 04:18 pm
Quote
Arduino RX just connected, 3.3 volt won't hurt the Arduino and its close enough for the Arduino to receive it.


No, but the 5V on the Arduino RX pin could/will hurt the RPI
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: sonnyyu on Jun 06, 2013, 04:24 pm

Quote
Arduino RX just connected, 3.3 volt won't hurt the Arduino and its close enough for the Arduino to receive it.


No, but the 5V on the Arduino RX pin could/will hurt the RPI


the 5V on the Arduino TX pin could/will hurt the RPI, but we use 3 silicon diodes in series (5-3*0.6=3.2V) voltage drop or one 1.8 V Zener diode.
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: Grumpy_Mike on Jun 06, 2013, 05:33 pm
Quote
but we use 3 silicon diodes in series (5-3*0.6=3.2V) voltage drop or one 1.8 V Zener diode.

The problem with series diodes is you don't get any sinking current for a logic zero so you noise margin is shot.


Grumpy_mike, would you please advise me what transistor would be suitable for this application? I need it to be fast enough to handle serial communication, but I'm not sure how to find it myself...

You would struggle to find a transistor that will not handle that speed, in electronic terms it is very slow. So any general purpose NPN transistor, the cheapest you can lay your hands on.

Quote
And if when using your circuit the Arduino RX pin is high for some reason, could it damage the transistor or even the Pi?

A rather bizarre set of circumstances there, not only has the RX ( normally set as an input ) got to be set as an output but it has to be set high as well. However, the output impedance of the aruino's output will limit the current to some extent and over current of the output is all that could happen.
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: sonnyyu on Jun 06, 2013, 06:38 pm
Plan D;-

Use 8-channel Bi-directional Logic Level Converter IC

(http://s16.postimg.org/snuazfmc5/TXB0108.gif)

1.2 V to 3.6 V on A Port and 1.65 to 5.5 V on B Port

http://www.adafruit.com/datasheets/txb0108.pdf (http://www.adafruit.com/datasheets/txb0108.pdf)

$8.00, Adafruit  (http://www.adafruit.com/products/395)

$3 overkilled.
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: sonnyyu on Jun 12, 2013, 05:27 pm
Plan E;-

Mosfet Logic Level Converter

(http://s18.postimg.org/9q375uec9/fet.jpg)

Logic Level Converter, Sparkfun, $1.95 (https://www.sparkfun.com/products/8745)
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: Grumpy_Mike on Jun 12, 2013, 06:58 pm
@sonnyyu
You don't know when to give up do you.

Seriously look at your suggestions and rate how practical and appropriate each one is. Only the last one comes close and if you look at it closely you will see it is the same solution I proposed in reply #1 only using FETs and not transistors.
The trick in giving help is for it to be practical and what the poster needs, not necessarily what he asked for. please try and restrain your natural exuberance and give a little thought into you posts. Apply occam's razor once in a while.
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: gowfster on Jun 18, 2013, 05:42 am
In the optocoupled approach, can you connect to the emitter side of the optocoupler with a pull down resistor and connect collector to the voltage rail, to avoid the extra transistors that are there to un-invert the signal?  It seems that if you don't enable the pull up on the pin, it would work?  Reason I ask is that I have a boatload of isolators (good deal in bulk  XD). And may have to tie. Pi to a mega
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: gowfster on Jun 18, 2013, 05:48 am
Grumpy,
In defense of sonny, he pointed out that for $2 you can buy a pre packaged converter from spark fun and not have to buy any other parts, and given it does 4 channels, it could be cheaper than picking up the parts to build one yourself. 
Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: Grumpy_Mike on Jun 18, 2013, 06:25 am

Grumpy,
In defense of sonny, he pointed out that for $2 you can buy a pre packaged converter from spark fun and not have to buy any other parts, and given it does 4 channels, it could be cheaper than picking up the parts to build one yourself. 

Four resistors an a transistor will cost you $0.10.

Title: Re: Connect Arduino to Raspberry Pi with Tx/Rx
Post by: sonnyyu on Jun 18, 2013, 07:13 am

In the optocoupled approach, can you connect to the emitter side of the optocoupler with a pull down resistor and connect collector to the voltage rail, to avoid the extra transistors that are there to un-invert the signal?  It seems that if you don't enable the pull up on the pin, it would work?  Reason I ask is that I have a boatload of isolators (good deal in bulk  XD). And may have to tie. Pi to a mega


Yes, you can. Here is the answer;-

Current Transfer Ratio/Design Guidelines for Transistor Output Optocouplers

Design Guideline Optocouplers (http://www.ecnmag.com/articles/2010/12/design-guidelines-transistor-output-optocouplers)

BTW for just tie Pi to a mega, If I were you just use usb cable via
Quote
Use USB or powered USB hub is more common since this time not only Arduino is powered by Pi but also supported  up to 127 Arduinos same time.
This is the way I did anyway but I did it with few Arduinos same time.