Go Down

Topic: Connect Arduino to Raspberry Pi with Tx/Rx (Read 22992 times) previous topic - next topic

DeceptX

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?

Grumpy_Mike

This is how to do it. No need for opto isolators.

sonnyyu

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.


sonnyyu

Plan C;-

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



Opto-isolator Breakout sparkfun $4.95



Matous

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!

twinsfly


Erni

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

sonnyyu


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.

Grumpy_Mike

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.

sonnyyu

Plan D;-

Use 8-channel Bi-directional Logic Level Converter IC



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

$8.00, Adafruit

$3 overkilled.

sonnyyu


Grumpy_Mike

@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.

gowfster

#13
Jun 18, 2013, 05:42 am Last Edit: Jun 18, 2013, 05:51 am by gowfster Reason: 1
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

gowfster

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. 

Go Up