Arduino serial port closed

I'm using an Arduino Uno R3 for my project and running into an issue where the serial port randomly closes and does not reconnect.

This is the error I receive: "Arduino serial port closed"

These are the environment details:

  • Node Red is running on a Windows machine
  • I use node-red-node-arduino to connect to and monitor the Arduino
  • Arduino is located in a different room than the machine which runs Node Red
  • Arduino is connected to the computer via USB to ethernet adapter
  • 6 analogue pins and 11 digital pins are in use

Despite the error message, the arduino node displays as "connected" and the port is still detectable, but the Arduino no longer responds and Node Red can no longer receive input. Currently, the only way to fix this is to restart Node Red which is not a viable solution for my use case. Is there a way I can programmatically reconnect the Arduino when the disconnect happens, or avoid it entirely?

There is currently no way to do this. (apart from restart or redeploy the flow).
But ideally we need to try to work out why it is dropping the link. Does it timeout due to inactivity for example ?

@dceejay - Thanks for the response! Unfortunately, there doesn't appear to be a clear cause for closing the port. Sometimes it closes when you leave the system to idle (within 5-20 hours), but most often it disconnects while the Arduino is actively receiving input. One thing to note is that due to the nature of the project, the Arduino may receive inputs to multiple pins at the same time. Could this be the reason?

I have the same problem using a raspberry pi to control arduino uno...

On a project I am working on, I have experienced this as well. I have resolved it, as best I can measure. I am using a Raspberry Pi 3 and a Sparkfun Redboard (Uno), connected by USB cable between the two. The Arduino is communicating serial commands with the Pi. When I prototyped this system, it was in a pretty noisy environment (near a running engine) and I was having a lot of serial port disconnects; they would occur every couple of minutes. I suspected noise might be the issue, and realized the cable I was using was about 6 ft long, and was just hanging out in space between the Pi and Uno. When a cable is in a noisy environment, it acts like an antenna with EMC and will pick up a lot of noise. The first thing I tried was to simply coil up the long cable so there was much less exposed between the two connections. My Pi and Uno were inches apart, so this was easy to do.
This resolved all of my serial port disconnects. I have since gone further with the project and have implemented a short cable between my Pi and Uno (6 inch) and it will run with no issue as well. In my testing, I have had a connection for weeks on end, with no drops.
If you are having issues with serial port connections dropping, consider shortening the cables. If this is not possible, limit the "antenna" effect as much as possible with proper shielding or reducing the number of connections in the system (i.e. a single long USB cable might be better than USB > ethernet adapter > USB). I didn't try ferrite chokes on the USB cable, but this may work as well.
I don't think the issue I faced had anything to do with Node-RED.

2 Likes

I already use only Arduino Uno and then a Raspberry Pi 4 with an Arduino Uno. I prototyped this system at home with some sensors, buttons and leds. I'm using the small USB cable but I still have serial port closed.

Thought I provide a quick update on the workaround. I never quite figured out how to avoid or remediate the "serial port closure" issue, so I decided to eliminate the serial connection entirely. Instead, I replaced the arduino with a raspberry pi, connected all the sensors to its GPIO pins, and set up a secondary Node Red instance on the pi. As inputs are registered on the raspberry pi, the local (rpi) node red instance send http requests to the central node red instance. Not sure if it's the most elegant solution, but the system is finally stable.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.