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