Why doesn’t serial communication work in C# with Arduino? — Exploring RS232

microwavestine
3 min readFeb 6, 2024

While going through a tutorial on making serial communication between Arduino (connected to Windows PC by USB) and C# program, I realized the example code given to the class wouldn’t work without this line:

sp.DtrEnable = true

Several stack overflow and Arduino forums also suggest this as the solution, but I did not fully understand why this was required and wanted to get to the bottom of it.

I first looked through Arduino UNO R4 Wifi Cheatsheet and it suggests that with HID.h library, we can enable DTR by doing Serial.dtr() on Arduino side instead of C#. After testing I confirmed that it is possible to enable DTR and do serial communication this way as well.

But why is enabling DTR required at all? It turns out, Arduino uses RS232 interface for Serial communication, and uses RS232’s DTR signal to control the way program uploads and starts interacting.

ChatGPT explains succinctly:

When it comes to Arduino programming, the DTR (Data Terminal Ready) signal is often associated with the automatic reset functionality on the Arduino board, especially when programming the board via a USB-to-Serial interface.

Here's how it typically works:

1. **Automatic Reset:** When you upload a new program (sketch) to an Arduino board using the Arduino IDE, the IDE communicates with the board over a USB-to-Serial connection. In order to initiate the bootloader on the Arduino, the board is often reset just before the upload process begins. This is done to ensure that the bootloader is ready to receive the new program.

2. **DTR Signal:** The DTR signal is commonly used to trigger the automatic reset. When you initiate the upload process in the Arduino IDE, it briefly lowers the DTR signal. This change in the DTR signal state is detected by the Arduino board, causing it to reset.

3. **Bootloader Activation:** After the reset, the bootloader on the Arduino is active, and it listens for incoming program data on the serial port. The Arduino IDE then starts sending the compiled program to the board.

4. **Communication with the IDE:** Once the bootloader has received the new program, the board resets again to run the newly uploaded code. The DTR signal is then restored to its normal state.

The DTR signal is essentially used as a way to trigger the automatic reset on the Arduino board, facilitating the uploading of new programs without the need for a manual reset button.

In the context of communicating with DOS (Disk Operating System), the process described above is crucial for programming Arduino boards using the Arduino IDE, which runs on the host computer. It's a mechanism that simplifies the programming process by automating the reset sequence on the Arduino board. Without DTR functionality, users might need to manually press the reset button on the Arduino board at the right time during the upload process, which can be inconvenient. Enabling DTR in this context streamlines the programming workflow.

PuTTY and built-in Arduino Serial Monitor appears to enable DTR by default, but for C#, DTR is disabled by default. Therefore DTR has to be manually enabled for communication to work (unless it’s manually enabled by Arduino code).

For more information on RTS, DTS:

--

--