Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTR gets disabled when uploading on Windows #2417

Open
3 tasks done
RandyParedis opened this issue Apr 16, 2024 · 0 comments
Open
3 tasks done

DTR gets disabled when uploading on Windows #2417

RandyParedis opened this issue Apr 16, 2024 · 0 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@RandyParedis
Copy link

Describe the problem

Hi there,

My apologies if this is a duplicate issue, but I have been unable to find anything that solved my problem.

I have an official Arduino Nano Every that I connect to my computer via USB (on COM3). The sketch I have assumes there is an external process that communicates with the Arduino over USB (Baudrate is 115200, Parity none and 8 data bits). However, I noticed that Serial.available() will always yield 0.

So, I did some digging and I realized that the code only started to work after I opened and closed the Serial monitor. When looking into the device state (by running mode COM3 /state on Windows), I was able to discern that I can only receive an input when DTR is ON. When I use the Upload button (or "Upload using Programmer") in the IDE, DTR is always OFF afterwards. Opening and closing the Serial monitor appears to have the same effect as calling mode COM3 BAUD=115200 PARITY=n DATA=8 DTR=on.

The external process I use for communicationis an executable someone else has written, so I do not have access to that source code. But the issue persists when using set /p x="999" <nul >\\.\COM3 to force an input. It is not an option for any hardware modifications on my end.

To reproduce

  1. Connect an Arduino Nano Every over USB. My Arduino is connected on the COM3 port, but I will use COMx in the steps below.
  2. Use the IDE to create a sketch with following code:
void setup() {
  Serial.begin(115200);
  Serial.setTimeout(10);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  if(Serial.available() > 0) {
    String signal = Serial.readString();
    signal.trim();

    // Startup command
    if(signal == "999") {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(100);
      return;
    }

    digitalWrite(LED_BUILTIN, LOW);
  }
}
  1. Upload the sketch using the Upload button, or "Upload Using Programmer".
  2. Send a signal to the Arduino. I use the command prompt: set /p x="999" <nul >\\.\COMx. Nothing happens.
  3. Open DTR on the device by calling mode COMx BAUD=115200 PARITY=n DATA=8 DTR=on from the command prompt.
  4. If we now execute (4) again, the led turns on! We can turn it off by calling set /p x="0" <nul >\\.\COMx
  5. If we repeat steps (3) and (4) again, nothing happens once more as DTR has been disabled again.

Expected behavior

I would expect that either DTR is opened automatically, or that it would be reset to the previous state after upload. Alternatively, having a setting that allows a user to select which DTR state is preferred on the port can be the best of both worlds.

Arduino IDE version

2.3.3-nightly-20240416

Operating system

Windows

Operating system version

10 and 11

Additional context

I was able to find the following thread that helped me identify the issue:
https://forum.arduino.cc/t/sketch-only-works-after-serial-monitor-is-activated-solved/880297

However, constantly needing to updating the DTR circuit line before the Serial connection starts to work is incredibly obnoxious and feels counter-intuitive. My biggest issue is that I have to do this after every upload, which makes debugging code (the Arduino Nano Every does not support the IDE's debugger) quite a hassle.

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@RandyParedis RandyParedis added the type: imperfection Perceived defect in any part of project label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

1 participant