Serial Communication Works until i send a value from Serial monitor

Hi all,

This is my first time in the forum, i'm totally new and i may be bad asking the right questions.

I made a very small program in Access VBA 2010 that will send a value X:


Open "COM3:9600,8,N,1" For Binary Access Read Write As #1 Put #1, , 7 & vbCrLf Close #1


This code is correctly sending the "7" to Arduino:

******CODE:******

String sReceived = "";

void setup() { Serial.begin(9600); pinMode(7, OUTPUT);

}

void loop() { if ((Serial.available())) { sReceived = Serial.readString(); sReceived.trim(); Serial.print(sReceived);

if (sReceived == "7") { digitalWrite(7, HIGH); delay(300); digitalWrite(7, LOW); }

} }


My problem is that my VB code is successfully sending the data (Arduino TX and RX blinks) but it only works after i open Arduino Serial Monitor and send any string.

After sending any string from Monitor the program will run perfectly.

Can you help me with this?

Thanks for your help!!

What sort of Arduino do you have?

Hi, Thanks for response.

Arduino UNO.

OK this problem is typical of boards that use USB HID connections like the Leonardo or the Micro, but the Uno does not work that way.

Opening the serial monitor does reset the Arduino, but I don't know what VB is doing.

VB is sending a number 7 by a binary file very simple code.

Sould i post this in another sectiom, i cannot find a solution.

if (sReceived == "7")

Is not the way to compair strings.

Did you understand the bit about the Arduino being reset when a coms port is opened or closed?

Hi,

"Did you understand the bit about the Arduino being reset when a coms port is opened or closed?"

I have read about this, i even put a 100 uF cap. in the reset ping to the ground but nothing.

About string comparison i'm brand new on this and probably did many mistakes but it does work at least, that part.

Can you please tell me more about your suggestion?

Thanks

I have read about this, i even put a 100 uF cap. in the reset ping to the ground but nothing.

That trick only works for short reset pulses not permanent logic levels.

Once you Arduino board resets it looses anything that was in the serial buffer.

Thanks for your response Mike!

Is there any way with Arduino code to emulate sending a string from monitor . . . i mean this may open the communication that i manually do.

No I think your problem is how you are sending the message from VB. The VB code should open the serial port and send messages. Then not to close the port until the VB code is finished.

The weird part is that TX and RX led blinks on Arduino but it doesn't execute the code until i open the serial monitor and send something.

Should i move this question to the code forum?

The weird part is that TX and RX led blinks on Arduino

The TX and RX LEDs are not controlled by the Arduino but by the USB host on the PC.

payanazo: Should i move this question to the code forum?

No.

Your PC program needs to open the serial port and allow time for the Uno to reset before trying communicate. Then it should keep the serial port open until it is completely finished with the Uno.

In my programs I include something like Serial.println("Arduino is ready"); in setup() and my PC program waits to receive that before doing anything else.

...R

payanazo: Sould i post this in another sectiom, i cannot find a solution.

Yes, it has been moved to here at my request.

Grumpy_Mike: Yes, it has been moved to here at my request.

I thought it was "here" when I posted Reply #12 - but it would not be the first time I was confused :)

...R

It was but I asked on reply #11