0

I would like to have all serial output from Arduino (nano) dumped to the terminal in Linux, without blocking the serial port for uploading new sketch version (for quick debugging loop), when using Arduino-Makefile:

[Errno 16] could not open port /dev/ttyUSB0: [Errno 16] Device or resource busy: '/dev/ttyUSB0'

Is there something made for that already? I did read about 10 related questions here and elsewhere (using screen, socat and others) but none of them deals with the question how to not block the port.

I might eventually code something in Python, which will disconnect when signalled and reconnect again after a few seconds (I use custom Makefile for the upload) and I imagine Arduino's IDE serial monitor does something similar.

Other pointers on how to solve the issue are appreciated!

1

(using screen, socat and others) but none of them deals with the question how to not block the port.

Other pointers on how to solve the issue are appreciated!

I say:

Virtually all hardware problems can be solved with software. But, sometimes, the $50000 software problem can be solved with the $2 hardware solution.

This is one of those cases. Buy a CP2102 6-pin serial UART USB adapter for < $2 on Ebay, or for < $10 on Amazon, to provide a second serial interface to the same Arduino (both connected to the same hardware UART built in to the Arduino's ATmega328 mcu). Let the main USB serial interface handle code uploads to the Arduino. Let this 2nd, external UART handle READ-ONLY from the Arduino!

Plug it in:

Arduino     CP2102 USB 6-pin UART
-------     ---------------------
Tx          Rx
GND         GND

Done. Do NOT plug in the CP2102 Tx to anything.

Now, use screen, or my crude datalogging Python serial terminal I wrote here (eRCaGuy_PyTerm), or a 2nd instance of the Arduino IDE with the Serial Monitor, or any other serial terminal for that matter, to read from the CP2102 while the Arduino's built-in USB adapter does code uploading.

Two serial interfaces to the same pins on the Arduino: one does Tx/Rx to/from the Arduino, while the other does only Rx to read from the Arduino.

I use a 2nd UART like this all the time as a trick to allow me to read the data from the Arduino into one Serial Monitor in one instance of the Arduino IDE so I can see the numbers, and I use the external CP2101 USB adapter to read the same exact data from the Arduino into the Serial Plotter of another instance of the Arduino IDE so I can see the live, plotted graphs!

It's amazing how well this works. Quick hack. Easy solution.


Note: to you use my eRCaGuy_PyTerm Python serial terminal, first set all your serial parameters inside the user_config.py file, then run python3 serial_terminal.py to run the program. It is a 2-way serial terminal, with datalogging. It works quite well. I really should improve its readme and post some examples someday.

| improve this answer | |
  • 1
    Cool!! In fact I have a few of those adapters around, it will be a $0 solution :) – eudoxos Oct 10 at 10:52
0

You can write your own python script that prints received serial output. By using try/except in a loop you can "pause" your serial monitor while uploading is in progress.

I did the same a while ago using pyserial on linux. I'd like to share it, but at the moment I have no access to my other machine. I can post it later if you want.

| improve this answer | |
  • Please post it, that would be awesome! I did not try yet but reconnecting while upload is in progress will make it fail; can you handle that or is there simply a fixed time to wait after failure? – eudoxos May 12 at 15:42
  • @eudoxos k, I'll look for the code. You can't access the port with two processes at the same time, but you can catch the exception – Sim Son May 12 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.