Hello!
I am working on a project and ideally I would like to start and stop the loop of an Arduino with a Raspberru PI. The idea is to send a signal from the Raspberry PI GPIO pins to the Arduino pins and trigger and ISR as follows:
I chose to set two different pins on purpose. I am aware that we could have set only one pin and make it work as a trigger with a function "start = !start" however this way I will have a pin than will always start (or continue) the arduino and another to stop (or make sure the arduino is stopped).
One of my main problems is that I do not know how to set the connections (one cable for each pair of pins or we should also need a ground?).
I am also aware that the Arduino works on 5V and the raspberry pi on 3.3V. Should we connect a resistance in series or some voltage divider to avoid any over current?
I have searched the internet but responses are always about serial connection. I only need an impulse since I think ISR does not work over serial.
Thank your for any advice or bibliography you may provide,
Alexis
alexisgaziello:
One of my main problems is that I do not know how to set the connections (one cable for each pair of pins or we should also need a ground?).
I am also aware that the Arduino works on 5V and the raspberry pi on 3.3V. Should we connect a resistance in series or some voltage divider to avoid any over current?
Hi,
If you are using two different supplies ("chargers", USB, ...), you have to tie grounds together.
As the signal goes from arduino (keep an eye!, not all of them work at 5.0 V), you may do with a resistor divider, but I'd recommend to use a level shifter instead.
Hello vffgaston,
Thanks for the help on the ground. It is clear know. Since I am using the same power I guess it will not be necessary.
However the signal is sent FROM the raspberry pi TO the arduino... And thats one of the problems. Raspberry pi HIGH is 3.3V and arduino HIGH is 5V (more or less, actually is between 3 and 5 but we cannot be sure that the raspberry PI will send a 3.3 V exactly).
I guess my question should be posted on a raspberry forum...
Alexis
You need the Arduino and Raspberry Pi to have a common ground whether at the common power supply or a wire.
Since the signal source is the RPi at 3.3V you don't strictly need a level shifter since the Arduino will read 3.3V as a logic high. It is good practice to use a series resistor (about 1000 Ohms) between Arudino and RPi GPIO pins to limit current. This protects the RPi in case the Arduino pin is accidentally configured as an output.
MrMark:
It is good practice to use a series resistor (about 1000 Ohms) between Arudino and RPi GPIO pins to limit current. This protects the RPi in case the Arduino pin is accidentally configured as an output.
Or when the Arduino is powered off.
3v3 as an input is fine
Using an interrupt is useless unless the code can actually break on different places and the start and stop signals are very fast. Other, just poll using digitalRead().
Using an interrupt can be faster if its a tight loop you want to control, digitalRead() can take 5us or so,
reading a single boolean variable might only take 0.125us
MrMark:
Since the signal source is the RPi at 3.3V you don't strictly need a level shifter since the Arduino will read 3.3V as a logic high. It is good practice to use a series resistor (about 1000 Ohms) between Arudino and RPi GPIO pins to limit current. This protects the RPi in case the Arduino pin is accidentally configured as an output.
What do you think of using SparkFun Logic Level Converter - Bi-Directional "BOB-12009". 5V to 3.3V
That way even if the raspberry pi for some reason sends a lower signal we will be able to read it correctly.
If I use that level converter would I still need the resistance?
septillion:
Using an interrupt is useless unless the code can actually break on different places and the start and stop signals are very fast. Other, just poll using digitalRead().
Please, can you explain a little more this sentence? I did not understand it.
MarkT:
Using an interrupt can be faster if its a tight loop you want to control, digitalRead() can take 5us or so,
reading a single boolean variable might only take 0.125us
My loop code will take 800-1000ms to execute so I would have to send an input for at least a second in order to read the input right? In the other hand ISR reads it whenever the input arrives does it?
Thanks to everybody for the help. I am new in electronics, sorry for my little knowledge.
Alexis
alexisgaziello:
However the signal is sent FROM the raspberry pi TO the arduino... And thats one of the problems. Raspberry pi HIGH is 3.3V and arduino HIGH is 5V (more or less, actually is between 3 and 5 but we cannot be sure that the raspberry PI will send a 3.3 V exactly).
Yes, you're right. Although may be the arduino sees 3.3 V as logical "1", I wouldn't risk: use a level shifter; they are unexpensive.
Yes, I agree (the only concern is the doubt you may have if something else goes wrong ...).
Alexis: you can do it this way; just make sure it works before continuing (just if something else goes wrong ...). Make sure the arduino pin is programmed as input.
alexisgaziello:
What do you think of using SparkFun Logic Level Converter - Bi-Directional "BOB-12009". 5V to 3.3V
That way even if the raspberry pi for some reason sends a lower signal we will be able to read it correctly.
If I use that level converter would I still need the resistance?
That's a fine solution. The series resistor would still add a level of protection should both sides be accidentally configured as output, but it isn't strictly necessary.
Seems like an old thread but i'm about to do the same thing.
I'm using an Arduino for controlling some components, and i will have an RPI that's connected to internet asking some REST-API:s about info and from this send 1/0 (true/false, whatever you wanna call it). Something like "hey arduino, you should do your thing now".
I was in the same thinking as above (using pins), but then i found this article:
I like the solution of using USB ports - no need for resistors or level shifters. The code on the RPI is python, another lib will do no harm. Anyone tried this solution?
Pros/cons?
Question: Arduino can be powered bu both DC-input (and on pins..?) and the USB. Will it run on the USB power from the RPI or should i connect the Arduino to DC-input?
I have (or I guess, am currently) doing this in one of my projects.
Arduino connected via USB port to RPi.
Although I have LAMP (Apache, MySQL & PHP) installed.. and am hosting a local web site/page in PHP that does the communication via serial port... so not using Python
So a little different.. but still connected via USB and communication in both directions