Serial messages not received unless Arduino's serial monitor was first opened (Excel VBA to Arduino)

Opening the serial monitor in the IDE reboots the Arduino. I think that the same thing will happen when you open the serial port from any other program, so whenever you send a message via your SerialPortSend subroutine, the Arduino will restart. Was that what you wanted?

One can influence that in a number of applications. Possibly not in VBA (I don't know) and definitely not in Serial Monitor; with Realterm I can influence it as well as with my own Windows applications.

That's why I suggested the 5 second delay.

The thing that is troubling me is that the port is opened and closed for each message. Not sure whether that (and the reboot side effect) was intended.

Ah, missed that; concentrating too much on the problem in the topic title. Good point :+1:

Yes, this is something I want. It allows to free up the COM link after the message is sent, in order to allow other types of communication, for instance the Arduino board sending messages to the VBA program. It is a way to "futureproof" my program.
The side effect is the rebooting of the Arduino board, but it is not a problem in my use case.

I just received components to try to bypass the serial port's limitations. I will keep you posted once I tried them.
Thanks to all of you for your help!

I tried different methods to try and circumvent the message reception problem on the Arduino side:

  1. Disabling programming mode by using a capacitor between the pins GND and RESET on the Arduino board, as suggested here and inspired by previous messages in the current thread : Preventing overwriting of sketch -- What is the best approach? - #11 by in0 and Programming Disable Jumper - #5 by Bskitter
    It could have freed up the com link for serial communication, but it does not work.

  2. Using the pins 0 and 1 as Tx and Rx to create a serial port that is independent on the built-in USB and its limitations. For some reason I can't get this serial port to work with my PC : the COM port is always busy, so I can't send anything on it from the PC.

For now I don't have more time for this project, so I implemented a functional but very unsatisfying solution: I use VBA to issue a Windows command to open the Arduino IDE, then keyboard shortcuts to open the serial monitor. Then I write the message using keyboard emulation in VBA, as a way to send it to the Arduino board directly from the serial monitor. Meaning that Arduino's serial monitor must always be open behind my VBA software.

Once again, thanks to all for your help!
And don't hesitate if you know what's up with the serial connection using pins 0 and 1 (Tx and Rx).

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

@p_hu had a question about receiving serial data, and for some reason it was only working after the serial monitor had been opened. I had this same issue and came across multiple other people who were also experiencing this behavior, or had trouble receiving serial data using a .net application. I noticed that in putty, serial data would receive fine, and in other apps like termite it would not, so I finally found what the solution is and I wanted to post on here in case someone else would find it useful. Here is a simple arduino sketch:

int i=0;

void setup(void){
  Serial.begin(2000000);
}

void loop() {
  i++;
  Serial.print(i);
  delay(500);
}

And the .net application code to make it work:

    Public Sub open(port As String)
        objSerial = New IO.Ports.SerialPort(port)
        objSerial.BaudRate = 2000000
        objSerial.Handshake = IO.Ports.Handshake.None

        objSerial.ReadTimeout = 500
        objSerial.Open()

        objSerial.DtrEnable = True
    End Sub

The thing that was always missing is the objSerial.DtrEnable = True line. Without that line, the application will never read serial data. As it turns out, turning on RTS handshake does work, but only half way, as enabling RTS handshake causes the data to be received only AFTER the serial monitor is opened. By setting DtrEnable to try, it works all the time no matter what.

I know this is late to the party, but I was running into this same problem and after working on it for a while, I found the solution. The issue is that you need to send DtrEnable before you can start receiving data from the port. This isn't the case for most serial devices, but when using the Arduino Micro, and perhaps others that use an emulated port through USB, this seems to be the case. Below is the code with the call to make it work:

    Public Sub open(port As String)
        objSerial = New IO.Ports.SerialPort(port)
        objSerial.BaudRate = 2000000
        objSerial.Handshake = IO.Ports.Handshake.None 

        objSerial.ReadTimeout = 500
        objSerial.Open()

        objSerial.DtrEnable = True '<< need to do this before you can receive data
    End Sub

I found many other topics that were facing a similar problem, and some of them "fixed" the issue by enabling handshake, but as it turns out that only half fixes it as it still requires you to open the serial monitor for it to start working.