-1

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:

volatile bool start = false;

void start(){
  start = true;
}
void stop(){
  start = false;
}

void setup(){
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), start, RISING)
  pinMode(3, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(3), stop, RISING)
}

void loop() {
  if (start) {
    //Do my stuff here...   
    }
 } 

Any help on how could I accomplish this from a C++ app that takes an argument, (start or stop, 1 or 0)? Or maybe with Python?

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 between the two boards (one cable for each pair of pins or should we also need a ground?). What type of impulse would be more appropriate to send from the raspberry PI? I am also aware that the Arduino works on 5V and the raspberry pi on 3.3V. Should we connect a resistance in series to avoid any over current?

Thank your for any advice or bibliography you may provide, Alexis

Alexis
  • 394
  • 4
  • 14
  • I'm voting to close this question as off-topic because it's about hardware wiring, not programming. – gre_gor May 07 '18 at 16:41
  • Well you are setting the pinMode to INPUT_PULLUP so the input is HIGH when not activated. Instead use a resistor (10K) from input to GND and remove the _PULLUP in your pinMode declaration – XerXeX May 07 '18 at 20:16

1 Answers1

0

With respect to your concern about the voltage issues: I would address this first because that has to be established before anything else will work.

Indeed, the voltage on the Raspberry Pi is 3.3 volts and typically Arduinos are 5.0 Volt logic. There are voltage level converters available that will convert 3.3. to 5.0 and back. You can get these from common sources such as Adafruit or Sparkfun. Specifically the name is

**4-channel I2C-safe Bi-directional Logic Level Converter - BSS138 $4.00 **

Here's an example of a 5V arduino (lilypad) talking to Rasp.PI You can wire the communication between the two devices using this simple device. (Shown is the Sparkfun version).

Alternately and possibly simpler would be to purchase an Arduino that can be run at 3.3 Volts. These are available from China on eBay and have a switch that allows the arduino i/o to be either 5V or 3.3V.

It is possible to use resistors to manage the level conversion. You may want to consider this solution if you have the skills to design it.

Arduinerd
  • 53
  • 3