Reset Arduino via serial communication with Raspberry Pi

Hello everyone,
I'm closing and re-opening the Serial port in the Raspberry Pi at the end of the Arduino's sketch in order to reset it, however I'm wondering if I can use this method aiming to reset the Arduino while running the void loop() ? If not, is there any solution to achieve that?

Any suggestion can help me please.
Thank you in advance.

Why do you want to reset the Arduino ?

I'm trying to create an emergency stop of a stepper motor in the sketch.

Any time that you open the serial port that is connected to the Arduino on a PC (or Mac or Pi or ...), most Arduinos will reset. Exceptions are those with native USB e.g. Leonardo).

If you are running e.g. the blink sketch and you open the serial monitor, the Arduino will reset.

IF the stepper motor has your finger trapped and pinching hard, just resetting the Arduino will not stop the pressure from the motor because it will remain powered.

1 Like

@chaymoss, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

Software emergency stops are really not a good idea

1 Like

Thank you all for your help.

Any time that you open the serial port that is connected to the Arduino on a PC (or Mac or Pi or ...), most Arduinos will reset. Exceptions are those with native USB e.g. Leonardo).

I'm using Arduino Uno, I'm not getting that actually. I'm using two buttons in a GUI (multithreading) to control the Arduino through the RPI. Closing and re-opening the serial port doesn't stop the stepper from rotating.

Any suggestion?

Are you using a software serial port? You only get the reset if going through the USB/serial connection.

I'm using the module serial in Pi to close and re-open the serial USB port and send/receive data to/from the Arduino

Tell your Pi to set the DTR to high. That will send a USB message to the Arduino to pulse the reset pin.

CitationTell your Pi to set the DTR to high

I don't really know how to do that, but should I leave the void setup() function empty if I want to reset it using serial connection?

Do a search on the web; you have the keywords DTR, Arduino and Serial; add yoour programming language (on the Pi) and operating systemn in the mix :wink: It might not be straight forward on non-windows based systems.

No.

Still can't find anything useful, couldn't I connect a GPIO Pin of RPI to the reset pin of the Arduino and set it high whenever I want to reset it? Can this method damage the RPI?

Now, I can enable/disable the DTR of the RPI, I can actually re-execute the code only when it's fineshed, however I can't stop the stepper from rotating meaning I can't reset the Arduino while it's executing the void loop() function, is there any solution to overcome this problem?

Have you tried both options (true and false) or whatever is required?

Yes I tried both, when setting DTR to high the Arduino will reset.
Can I create a condition in Arduino to check the DTR state? If it's high the stepper will stop, otherwise it will continue rotating

Might be best to modify your setup() code to immediately stop the stepper at that point. Then is later, the Arduino is reset, as soon as the code begins to execute, the stepper will be stopped.

I have an enable pin to enable/disable the stepper using the following line

digitalWrite(EN2, LOW);

I put this line in the setup and when starting the void loop(), it doesn't work.
However I noticed that when reset the Arduino and send an empty strings the stepper will stop but it will start again once I stop sending empty data.
Any suggestion?

Most stepper controllers set the enable low to ENABLE the controller.