Page 1 of 1

Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Wed May 18, 2016 9:37 am
by ryuujin
Hi

I asked a while ago on how to connect an arduino and a raspberry pi together, so that a button press on the Arduino would result in a file playback on the RPi.
The answers I got on this matter was that the Uno and the RPi could not directly be connected together because the HIGH signal on a RPi is just 3.3V and the HIGH on the Arduino is 5V.
So that would not work, and I've tried finding voltage levelers in Norway but I could not find any that would suit my purpose, so I am left ordering from China.

Thing is, I really need this to work before I receive this parcel. I tried connecting ARduino to RPi on USB and it worked to some extent, the problem is they are going to be a little farther away so I think wireing would be better.

Now here is my idea:
Could I wire the Uno and the RPi together on 5V supply(connect the Arduino to a regulated 5V supply through the UNO's 5v port. They would then also share ground on this 5V power supply.

THEN, how about I also add a relay which I have lying around (One channel 5V relay for Arduino) to the loop in this manner:
Vcc - To 5V regulated along with Uno and RPi
Gnd - Obviously to GND
Signal - to random Arduino digital pin.

And,
C(common) to Arduino 3.3V port
NO to RPi GPIO pin?

Would this then work the way I want it to?

If I code the RPi something like this?

Code: Select all

import pygame.mixer
from time import sleep
import RPi.GPIO as GPIO
from sys import exit

GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)


pygame.mixer.init(48000, -16, 1, 1024)

snd = pygame.mixer.Sound("game.wav")


soundChannelA = pygame.mixer.Channel(1)

while True:
   try:
      if (GPIO.input(4) == True):
         soundChannelA.play(sndA)

The reason I can't just use the RPi as my main console is that there are numerous other things connected to the Arduino, like a LCD display etc. etc. etc.

What do you think? Is it possible?

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Wed May 18, 2016 9:54 am
by cacti
Since your trigger is only in one direction (from the Arduino to the RPi) I would use a simple transistor to act as a switch (with level conversion). You could also use a resitor devider or a 3.3v zenner with resistor. Just search for "transistor level comversion" on Google.

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Wed May 18, 2016 10:08 am
by ryuujin
Yeah I know there are several ways to do this I guess, but the thing is - I have no idea where I would get a hold of those things here in Norway...
There are e-shops of course, but then I'd have to wait for the products to arrive and they are often extremely expensive because of a "minimum order of 10USD" thing. Seems steep to have to buy stuff I don't need for 10USD just to be able to buy a 1USD transistor.

Would this work without anything else?

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Wed May 18, 2016 1:24 pm
by ryuujin
Noone knows?!

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Mon May 23, 2016 10:08 pm
by anddr
Yes, it is possible to use a relay.
I would just have used a voltage divider, you can find a potentiometer in alot of scrap electronics ( volume knobs etc.)

Greetings from Norway

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Mon May 23, 2016 10:29 pm
by asandford
You can power the Uno from the Pi's 3v3 pin (it will halve the Uno clock speed though) to the 3.3v socket on the the Uno (make sure you have no other power to the uno; including usb).

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Tue May 24, 2016 1:14 am
by pksato
Why make simple things more complex?
To connect a 5V arduino output to raspberry pi input, use a voltage divider. Two resistors, cost only few cents.
And, is bidirectional.
To connect raspberry pi to 5V arduino, use direct connection.
Arduino read high if input voltage are great than 3V.

Voltage divide works fine to few MHz, depending of current flow.
Adding a small capacitor, the frequency range can be extended to GHz.
Some time ago a make these simulations, ground connected 15pF capacitor represent the internal capacitance of logic input.
R1, R2 divider works fine at 10MHz, but R3, R4 is not good, but still usable if some delay on rising is not a problem.
Image

Putting a 22pF capacitor in parallel with R3, can improve rise time, and now have a very god signal.
Image

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Tue May 24, 2016 4:24 pm
by Burngate
You're thinking of using a relay, so you're not wanting high frequency signalling.
So two resistors as a potential divider is the best solution - cheap, low power, small, reliable.

The two resistors could be 2k2 and 3k3, or they could be both 1k; it would still work, as long as the high state is above about 2v and below 3v3 it's safe.

It also protects your Pi from coding errors, which a relay would not - the way you suggest wiring your relay, with 3v3 to C and the GPIO to NO, if by chance you closed the relay and set the GPIO to output low, you would destroy the GPIO. With resistors, high on the arduino port and low out on the Pi would not hurt anything

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Fri Jun 17, 2016 12:55 am
by Slackware
You could also run an opto isolator chip. 3.3 v on pi side, and 5 volt on arduino.

Do they not have electronic stores over there becasue of those stupid ban lead silver solder only laws?

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Fri Jun 17, 2016 9:11 am
by ViaBitz
Like others have said, it is possible to read an arduino output using a 2 resistor voltage divider, (see https://en.m.wikipedia.org/wiki/Voltage_divider ), you can use something like Z1:2K and Z2:3.3K to do the job, Vin would be the Arduino output and Vout the RPi gpio pin.

For the pcb I made ( viewtopic.php?f=93&t=141429&p=936171#p936171 ), I use this to connect to the RPi Rx and use a logic level n channel MOSFET like a 2n7000 / 2n7002. Using a MOSFET to level translate protects you if the arduino input unintentionally becomes an output, if this happens and you've wired them direct, then you've just put 5v into your RPi gpio and that's not a good idea.

Not sure about Norway, but in the UK, can find these resistors and mosfets on eBay in packs of 100 delivered for £1 from China and it's also possible to find tiny level translator boards allowing 2 or 4 I/O's delivered for less than £1.

Re: Arduino + Raspberry Pi connection through 3.3 and relay?

Posted: Fri Jun 17, 2016 11:40 am
by Romonga
Slackware wrote:You could also run an opto isolator chip. 3.3 v on pi side, and 5 volt on arduino.
Can you provide a sketch as to how this would be wired?