Raspberry Pi + LAMP stack talking to arduino UNO or Leonardo

Goal
I want to build the next UI for my robot in a website so that I don't have to translate it for other devices - anything with a browser should work. It will also mean that the pi can use a cron() to update itself and upload new sketches to the arduino.

Status
I can upload sketches to the arduino UNO with inotool. I can't with Leonardo because I get out_of_sync or programmer_not_responding.
I can open a serial connection.
I have a pi running a LAMP stack with a website.
When I click a button on the website I can send data to the arduino.
When I click a button on the website I want to see a log of messages sent back from the arduino.

Challenge
Every time I open a serial connection the UNO resets.
Every time I try to open a serial connection the Leo gives an out_of_sync error.

Question
How do I maintain a connection so that I the arduino doesn't reset every time AND still be able to upload sketches without hitting the reset button?

Thank you!

How do I maintain a connection so that I the arduino doesn't reset every time AND still be able to upload sketches without hitting the reset button?

How can I have my cake and eat it, too? The answer is that you can't.

Well not with THAT attitude.

I’m thinking some kind of daemon running on the pi that acts as a go-between, keeping the connection open and queueing messages in both directions. I’ve never written a daemon in linux before so I’m not sure where to start. Kill the daemon when appropriate to perform an upgrade, then restart to continue normal operations.

I'm thinking some kind of daemon running on the pi that acts as a go-between, keeping the connection open and queueing messages in both directions.

That doesn't change the fact that the Arduino is hardwired to reset when the serial port opens and closes. All that it changes is how often those events occurred. I assumed that you had already considered that approach and rejected it for some undisclosed reason.

I've never written a daemon in linux before so I'm not sure where to start.

A daemon is just an application that has no user interface. By convention, the last letter in the name is d, as in httpd, snmpd, etc.

Kill the daemon when appropriate to perform an upgrade, then restart to continue normal operations.

Yep.

Well... thanks for bumping the thread.

To avoid resetting the Arduino, your web app would need to keep the serial connection open in normal use. It would be possible for your webapp to provide a web service that could be called to command it to disconnect from the Arduino (i.e. close the serial port) which would free the serial port so that your can cron task can reprogram it (the act of reprogramming it would also cause the Arduino to reset), and another command to reopen the serial connection afterwards (you would expect the Arduino to reset again at this point).

You cron task would then just need to call the web service API to disconnect it from the Arduino, launch the batch file to upload the new sketch, then call the web service API to reconnect it to the Arduino.

If it was up to me, I'd also specify some fallback/recovery behaviour so that the system could recover automatically if any error caused the web app to be left disconnected.

Yes, those are all good points and should be part of the spec. Thank you for catching my oversight!

How about communicating with the Arduino via SPI or I2C, and reserving the serial port just for reprogramming?

I need to do the same: I want to avoid reseting the arduino UNO every time I open the serial but I want to be able to reset it. Possibe solution in this thread:

http://forum.arduino.cc/index.php/topic,26682.0.html

it is not exactly " opening" the serial what makes it reset, the serial to USB driver sends a signals and you can control it.

try with:

stty -f /dev/tty.usbserial.* -hupcl

You can disable that reset by cutting the "RESET EN" jumper on the Uno.

The jumper is a small trace between the two pads in the center of the board, but the silkscreen on that board in the picture is missing the 'S' in RESET.

However, you must press the reset button to reprogram it via USB. You can reconnect the pads with a bit of solder if you want that usb reset feature.

Otherwise it appears you are trying to overcome the usb reset feature, but not when programming it. The way around that is cut the trace and use the ICSP connector to program it.

SurferTim:
You can disable that reset by cutting the "RESET EN" jumper on the Uno.

You can also do it without damaging the hardware by putting a capacitor between reset and ground.