Prevent Serial Monitor from Resetting the Arduino

I just got a Raspberry Pi 3 and have been setting it up send serial signals to an Arduino mega. I'm starting with a simple blink sketch from a python script on the RPI. Everything works great until the python script closes the serial port and finishes. I'm trying to leave a pin on the Arduino HIGH but when the port the pin goes back to LOW.

I guess this is no surprise because the same thing happens when you open the serial monitor from the Arduino IDE. It's as if the sketch is restarted with the serial monitor.

Is there a way to prevent the serial port from restarting the sketch? Other work arounds?

Thanks
Rich

On the board there are RESET ENABLE pads. Cut the wire between to disable reset. Problem is how to re-enable it. You have to solder wire back. Better should be a microswithch or jumper at this place. Other and "nonivasive" way is to put large capacitor about 1uF between RESET and GND pin to span over reset pulse.

Does a Mega reset if you open the connection to Serial1, Serial2 or Serial3 ?

The Mega does NOT reset when you use Serial1, Serial2 or Serial3. But you can't access them with the regular Arduino USB connection.

One solution to the OP's problem is to use an FTDI cable (USB-ttl cable) to connect the PC to the Arduino's Rx and Tx and GND pins (and no connection to the Reset pin). Then the Arduino won't reset and this will work as well with Serial (on and Uno or Mega) as with the other Serial ports on a Mega.

...R

On my solar cell tester using a Nano, I put a 0.47uF cap from GND to reset pin, then I can take it outside, get some readings then bring it back in and hook up to computer and open serial monitor without a reset. Have to remove cap to load another sketch, of course.

I took Robin2's suggestion and I hooked up an FTDI cable to the Arduino Mega Serial1 to the Raspberry Pi. Note that I left the reset wire disconnected. And as predicted the board does not reset when the python script finishes.

Thanks for your help everyone!

Ride on!
Rich