Arduino + Raspberry Pi connection through 3.3 and relay?

Hi

I asked someone 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? When say D10 pin receives a LOW signal, the Relay will flip, sending power from 3.3V on the Arduino to the RPi's GPIO4 pin?

Or will this for some reason end up frying one or both of my microcontrollers?

If I code the RPi something like this?

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, several buttons that work as a keypad, another relay etc. etc. etc.

What do you think? Is it possible?

(deleted)

Absolutely not necessary.

The "level shifter" is a diode and pull-up resistor. The resistor pulls the Pi GPIO up to 3.3 V, the diode (1N914 or whatever) cathode goes to the Arduino and anode to the Pi. As always, they must have a common ground connection but the supplies need not be in common.

spycatcher2k:
You could just use resistors (voltage divider)

No, not resistors.

Resistor and diode.

Thing is. guys. Where I live there are no radio shops around or whatnot where I can actually buy resistors or volgate dividers etc etc.

I order most things online which takes about 7 days to get there from within Norway and most of the time there is a 10USD minimum on orders.

So basically, I am wondering if this would work without frying either one or both of my components so that I don't have to deal with transistors, resistors, diodes etc etc.

I think you might be able to do what you say with a relay, provided that you have a relay module that has at least a driver and a protection diode, as the AVR will not be able to drive a relay on its own and will get fried.

Try posting a diagram of what you are trying to do.

Well, a relay could work - sort of - given that you take into account such things as contact bounce and a pull-up on the GPIO pin.

Why dont you attach the button to a pi gpio?

mart256:
Why don't you attach the button to a pi gpio?

That might be a trifle too simple!

Presumably there is some other requirement as yet unrevealed.

spycatcher2k:
You could just use resistors (voltage divider)

that would work but violates basic hobbyist tenet of using most complicated most expensive solution possible. paul is headed in the right direction adding a diode which is even more expensive and un-necessary. actually in most cases one resistor is a simpler way to interface 5v out to 3v devices or running arduino off 3v but still too easy and economical.

using ddr register effectively allows avr outputs to function as open collector so no hardware changes at all but this definitely spoils the fun so forget i even mentioned it.

ps. turns out rpi inputs are really 5v tolerant but thats a whole other story.

Have you considered using the USB on the RPi to connect to the Arduino? I've used that before.

edit: You will find the Arduino serial port as /dev/ttyACM0. That is how my Mega 2560 shows up. I've used C and Python on the RPi.

john1993:
... adding a diode which is even more expensive and unnecessary. actually in most cases one resistor is a simpler way to interface 5v out to 3v devices

And indeed that will work with a high value resistor - 10k or more. In this particular situation, it is perhaps not a problem but the reason for using a diode is that it minimises the high-to-low transition time and permits the use of a low value resistor which then minimises the low-to-high transition time. While it may not matter here, it often does. There is always a reason.

john1993:
using ddr register effectively allows avr outputs to function as open collector so no hardware changes at all but this definitely spoils the fun so forget I even mentioned it.

No, we will forget it not because it "spoils the fun", but because it is wrong!

Using an open-collector function requires - what do you know? A pull-up resistor! As I keep saying. Unless the Pi has an internal pull-up which may be readily enabled. Nobody has so far mentioned whether or not it does.


ryuujin87:
Thing is. guys. Where I live there are no radio shops around or whatnot where I can actually buy resistors or voltage dividers etc etc.

I order most things online which takes about 7 days to get there from within Norway and most of the time there is a US$10 minimum on orders.

OK, all fine and good but when you come back to review this - get serious!

You have a tactical/ organisational problem here. You have some of the parts necessary to work in electronics, but are missing critical components. However you solve the immediate concern, go to eBay and order - from China - some resistor assortments focussing on values in the range 47 to 100k Ohms with a few outliers, and some capacitors in the range 10 nF to 470 µF.

OK, it will take three weeks, but this should cost you little more than that US$10 minimum local order and you will then be set to actually do things. And a pack each of 1N914 (1N4004) and 1N4007 or equivalent diodes. And some various LEDs. And ...

Paul__B:
No, we will forget it not because it "spoils the fun", but because it is wrong!

Using an open-collector function requires - what do you know? A pull-up resistor! As I keep saying. Unless the Pi has an internal pull-up which may be readily enabled. Nobody has so far mentioned whether or not it does.

of course pi has internal pu and enabled by default. hard to imagine any modern device (or antique for that matter) that does not. and even if in some alternate universe it didnt theres those pi 5v tolerant inputs.

im surprised no special purpose level converter board suggestions either which would be in true tradition of hobbyist overkill. one can be had for less than $10 from sparkfun.

ps. had to laugh a few months back when a fellow at local ham club was showing off his tft with 5 of these boards. actually seemed proud of the fact that he spent over 25 bucks to interface a $4 display. couldnt get them to work and eventually ended up just connecting direct. ah well...