Arduino Nano Every does not recieve characters from C# program unless Arduino Serial Monitor is Opened then Closed

I am making a program with c# to interface my an Arduino Nano Every. Most of everything is working, but I have a problem with the Arduino receiving any characters after it receives power again. The beginning of the stored program works fine, but the Arduino does not seem to receive any characters. I CAN however get the Arduino to work properly AFTER I run Serial Monitor in the Arduino IDE. Does anyone else have this issue? How can I resolve this?

I have no experience with the Nano Every. If it's anything like the normal Nano (or Uno), you can try to set DtrEnable and / or RtsEnable to false in your C# code.

Check the properties in SerialPort Class (System.IO.Ports) | Microsoft Learn.

I did not think about those. I had them both set to false. I tried setting DtrEnable to true, and it does something to make it work. Unfortunately, it screws up my communication and program verification I coded, so I have to figure out how to handle the information the Arduino is receiving and sending.

Edit: I looked into using DtrEnable, but it seems I can't. I am very new to this, so apologies for my lack of understanding how some of these things work.

I guess I would need to know what Serial Monitor is doing when it opens a port to the Arduino versus my windows form app.

Again, not sure if it applies to the Nano Every.

DtrEnable and /or RtsEnable will reset a 328P/2560 based Arduino if set to true when opening the serial port. That could explain the unwanted data if the Every works the same way.
There was recently a thread where it was mentioned that the Nano Every reacts on a software reset. Opening and closing the port at 1200 baud would do that.

I however do not know if the reset / non-reset fits in your application. Note that I might be completely on the wrong track with this.

Instead of your C# application, you can use terminal program that allows you to influence DTR and/or CTS (if that's the way to go). It's easier than recompiling your C# every time; I actually have checkboxes on my C# form to control them. I use RealTerm for that.

Do you mind sharing your code for both the Arduino and the C# application? Preferably stripped down versions that show the problem. Also a clear description of the communication protocol that you're using?

Well I would consider the code to be the issue then. Write it to handle communication errors without breaking.

I would if I knew what to take into account. My program looks for a specific character to be written back from the Arduino (to make sure the proper .ino is stored), but it keeps coming back as something else. I know the Arduino throws back '⸮' when it is reset (don't know if that is for all Arduinos), but I have that taken into account. I am seeing all the characters from the Arduino, and they are only the character I am expecting and '⸮'. There is something happening that I can not see, so I am not sure how to handle it in my code.

The opening and closing port at 1200 baudrate does not work for me. I am trying to take the unwanted data into account, but it is not showing up when I read the next character (I only need to read single characters from the Arduino for my purpose in C#). I do have a reset command set in the Arduino, but it requires the Arduino to be able to receive characters in the first place.

My code is at GitHub - Praetir/Arduino-Computer-Data-Display: Project that takes inspiration from the outdated and non-functioning Arduino CPU Monitor project that can be found at https://www.hackster.io/zakrzu/arduino-pc-monitor-66c07a.

I will have a separate branch with a stripped down version within the next 20 min.

I put up a new branch with the stripped down code.

Well the first step would be to ignore invalid input. Does the "garbage" characters occur before or after the '⸮' character?

While the MCU is held in reset I would expect to see a lot of nonsense, since the USB to serial converter RX signal, is a high impedance input connected to another high impedance input (the default pin state is input).

Do you happen to have access to an oscilloscope/logic analyzer?

It looks like you reset the Arduino every 3 seconds by sending the '@' command? There shouldn't be a need to do that. How long does the reset cycle of the Nano Every take?

It might be advisable to let the Arduino tell your C# application that it's ready. E.g. after a reset (when opening the port), you can let it send a message "Arduino OK" in setup(). Your C# application will have to happily wait till that exact text is received before sending data.

I would start with some extremely simple Arduino code to learn the Arduino's behaviour. Use a terminal program as mentioned before (it doesn't have to be RealTerm, there are plenty others) instead of Serial monitor and just send "Arduino OK" in setup.

Actually, I do, and I just made a PCB to make it easier to probe USB pins while devices are communicating. I also have the C# program set up to console print any characters received, but it does not show any garbage before or after my '?' or expected character '&'.

image

As I was writing this reply, I finally realized that '⸮' changes to '?' when DtrEnable is true. I wish I saw this earlier because that ended up wasting your, my, and sterretje's time.

Sorry about that. And also thank both of your for your time.

The reset is done on purpose as I was having issue with the Arduino getting stuck when my program was just starting. There is some refining to do. The Arduino responds and the resetting/communication/program verification ends before a second cycle ever occurs. I don't know the exact time the Arduino takes to reset, but it's under a second (which I used Thread.Sleep() to allow). There are definitely a lot of behaviors I still need to learn, and I really appreciate the advice.