Go Down

Topic: Serial monitor disconnect after potential power surge (Read 484 times) previous topic - next topic

jeremyg

Hello everyone,

I'm currently attempting to complete a university project that measures the analog output from a sensor.

However, the laptop connected to the Arduino is, I think, experiencing power surges from other machines in the laboratory. I'm kind of stuck with a particular spot in the lab, so it's not quite as simple as moving to another power point. I also don't know exactly which bit of equipment is causing the error. This is similar to here: http://forum.arduino.cc/index.php?topic=238351.0 and here: http://forum.arduino.cc/index.php?topic=238351.msg1730079#msg1730079. However, the particular solutions discussed don't appear to have worked for me.

For example, I have found that using a watch dog in the code does not work. Additionally, pressing the reset button on the Arduino when it fails also has no response.

Finally, using Serial.flush() after each transmission also has no effect.

Currently, when the Serial monitor stops working (the TX light on the Arduino switches off and the Serial Monitor no longer captures data), I have to unplug the USB, plug it back into a different USB port on the laptop, and then upload the code back to the Arduino. Is there any way to do this programmatically?

Thanks!


PaulS

Quote
Is there any way to do this programmatically?
You want to write a program to physically unplug the Arduino?

Add code to the Arduino sketch to blink an LED, using the blink without delay technique. Does the Arduino stop working? Or, is it the PC that goes flaky?
The art of getting good answers lies in asking good questions.

jeremyg

I've implemented the Blink Without Delay functionality.

I'll post on here once the power surge happens again and disrupts the serial communication.

Robin2

However, the laptop connected to the Arduino is, I think, experiencing power surges from other machines in the laboratory. I'm kind of stuck with a particular spot in the lab, so it's not quite as simple as moving to another power point.
The nice thing about laptops is that they have batteries and can work when disconnected from the mains power point.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

jeremyg

Indeed, laptops have batteries. However, this is often collecting data for weeks at a time and measuring drift. So running it off the laptop battery isn't feasible in this instance.

Update: it still hasn't shut off, yet.

Robin2

So running it off the laptop battery isn't feasible in this instance.
Then, if the application is important, run a clean mains power supply for the laptops to connect to.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

jeremyg

I was able to replicate the issue this morning (finally!).

The laptop charger and a Nikon transformer are both plugged into the wall sockets, but at different power points (spaced about 2 m apart).When the Nikon transformer is switched off, the serial connection is disrupted. This drops the connection and the Arduino hangs. This does not disrupt the rest of the code from operating (blink without delay continues to operate), it just disrupts the serial connection (no further data is received).

Transformer details:

Nikon Transformer
Model: XN (JAPAN)
Prim. 220V/240V 50/60Hz 30W
Sec. 3-6V 3.3A
Fuse 0.5A/250V

Has anyone had any experience with this? Previously, Robin has said:
Then, if the application is important, run a clean mains power supply for the laptops to connect to.

...R
and my initial thought it to purchase an uninterrupted power supply. This is pretty expensive and outside my budget. Are there any other options for cleaning a mains power supply?

Alternatively, can this be completed with software? Currently, pressing the red reset button on the Arduino does not reinitialize the serial connection (blink without delay continues to operate, though!). Currently, I have to disconnect the Arduino USB cable, reconnect it to a different USB port, and re-upload the code to the Arduino.

I was thinking of unmounting/re-mounting the USB connection if no signal is received for, say, 30 seconds. However, I've never attempted this before. Can anyone offer some guidance or point to an example or tutorial?

Thanks!

Robin2

I don't think you have said what sort of Arduino you are using.

And it is not clear from your description whether the Arduino resets? Maybe you could get it to flash an LED in an identifiable sequence in setup() so that you easily tell if it resets even when there is no communication with the PC.

Does the PC program that is communicating with the PC recognize that the communication has stopped? If so maybe it can restart it.

What operating system are you using on the PC? If you are using Windows maybe the COM port changes?

Would it help to power the PC and the transformer from the same (or adjacent) outlets?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

jeremyg

what sort of Arduino you are using.
I am using an Arduino Uno.

And it is not clear from your description whether the Arduino resets? Maybe you could get it to flash an LED in an identifiable sequence in setup() so that you easily tell if it resets even when there is no communication with the PC.
I implemented a unique sequence of flashes with the LED in setup and can confirm that the watchdog timer does not get triggered. The code appears to be looping successfully, but the Arduino is not sending information via serial (the TX light stops flashing and turns off). The setup sequence is only triggered when I manually press the red reset button on the Arduino, however, this does not restore serial communication. When I attempt to disconnect and reconnect the serial monitor, I get an error message: "Error while setting serial port parameters: 9,600 N 8 1".

Does the PC program that is communicating with the PC recognize that the communication has stopped? If so maybe it can restart it.
I could get the Python code to recognise that a signal is no longer being received, but I'm not sure where to go from there. Currently, I have to physically disconnect and reconnect the USB cable to a different USB port before I can re-upload the sketch. If I simply re-upload the sketch (without disconnecting/reconnecting, or even disconnecting and reconnecting but to the same USB port), I get an error: "avrdude: ser_open(): can't open device "\\.\COM9": Access is denied."

What operating system are you using on the PC? If you are using Windows maybe the COM port changes?
I am using Windows XP SP3. In Windows' Device Manager, the Arduino Uno remains connected even after it hangs (and does not change port). It just stops sending messages to the Serial Monitor.

Would it help to power the PC and the transformer from the same (or adjacent) outlets?
Previously, they were connected to adjacent outlets (about 2 m apart). However, when connected to the same outlet, the Arduino no longer hangs. Crazy! Any ideas about why this is happening? I'm also worried about other devices in the lab which may drive power surges through the room and therefore, a software solution is still desirable.


Robin2

but the Arduino is not sending information via serial (the TX light stops flashing and turns off).
Is the Arduino program expecting data from the PC?

I am no longer familiar with Windows - I have been using Linux for years.

You mention the watchdog timer and the makes me think you have a complex Arduino program. If so write a very simple Arduino program without any watchdog and with the minimum of code to test the connection.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up