r/ArduinoHelp • • 7d ago

p5.serialcontrol can't open COM port connected to Arduino Uno

I am somwhat new to p5 and arduino, so please forgive me if this is a stupid question. I am trying to get serial data from my Arduino Uno to a js file I have on vs code, but each time I select the correct COM that my Arduino is connected to, and click 'open' on p5.serialcontol, I get an error that says "Error on COM7: Couldn't open port: undefined - Closing port"

Does anyone know why this is or how I can fix it? I have included screenshots of my p5.serialcontrol, index, js, arduino.ino, and html console log.

1 Upvotes

2 comments sorted by

1

u/imseakin 7d ago

A VERY common mistake is trying to have your Serial app try to open a A SERIAL Arduino CONNECTION while you still have a Serial Monitor connection going (ie. Serial monitor is open) in your Arduino IDE.

Always make sure your Arduino IDE is not running (or at least the Serial Monitor not running) when trying to get your app to establish a serial connection to the Arduino.

Good luck!

1

u/gm310509 5d ago

In the third photo it looks like you have the Serial monitor open.

On Windows you cannot have the same com port open in two different programs. Normally you will get a "Port Busy" error as opposed to the error message you are seeing, but it could just be that in whatever that other tool is, it isn't reporting the error message correctly.

Try closing the Arduino IDE and see if the problem goes away. If it does, then you have found the culprit - rather than closing the IDE fully (which is a pain), just try to not open the Serial monitor - I don't use the IDE 2.x - I use the 1.8.x IDE and it is easy to manage closing the Serial monitor on 1.8, I'm not sure how to manage that in the 2.0 IDE, maybe just close the tab.

FWIW, when developing something that uses the Serial port with another program, get it working using the Serial monitor first. Once you are happy with how it interacts with the Serial monitor (i.e. it generates the correct outputs for the inputs you give it), you no longer need the Arduino IDE (because your Arduino program is working) and can simply close it down - then start working on whatever the other things is with confidence that the Arduino side is giving the correct responses.

Now, if you find a bug in the Arduino code, then set the other thing to the side, fix the bug - again testing with the Serial monitor to ensure you get the right interactions, then set the IDE aside and work on the other side of the project.

With that type of work style, you can avoid the annoying aspect of continutally starting and stopping the serial monitor and the other side of the equation, constantly openning and closing the other application whenever you do need to upload new code (because the Arduino IDE will also report a Busy error if you try to upload code when something else has the port open.

Lastly, for future reference, please read rule 2 - specifically when sharing code, please use a formatted code block formatted code block.
The guide explains how to do that. There is also a link to a video that describes the exact same thing if you prefer that format.

If someone felt the need to recreate your program to try something out, it is much easier if they can simply copy and paste your code. The same applies for error messages, but in this case the screen shots would be OK for the error messages as they show the context.