Go Down

Topic: Serial Com data bit Slip. or not communicate properly. (Read 494 times) previous topic - next topic

EJLED

Hi, I am sending 0-23999 to PC using following code.

 
void setup()
{

  Serial.begin(250000);
}

void loop() {
  for (int i=0;i<=23999;i++)
  {

 Serial.println(i);
 
 }

 
  delay(10000); // wait for 10 second
}

 code work well. but i am facing issue is that.

 When i open serial monitor of arduino all data comes line by line and everything worked well. but when i access com port using python or in visual studio the data after 5000 is not in order some of bits overlapped or missing.

i observed that the data comes in serial monitor of arduino during Tx LED of arduino ON and whole data transferd and Tx LED blinking during complete transmission of data, where in case of python and VB even if Tx data LED turned off . the data is still coming on the window of python / VB. how this happen why data Transfer and Tx LEDs both not synchronize in case of python and VB.

Why this happens i am not able to understand.

anyone faced same problem?

baud rate is set 250000 both sides. (Arduino and PC).

TIA

el_supremo

Try it at a much slower rate and see if there are any problems. E.g. try 57600 at both ends.
VB (and python?) is an interpreted language which can be quite a bit slower than compiled code. It may have trouble keeping up with such a high baud rate.

Pete
Don't send me technical questions via Private Message.

Robin2

This code will overload the Arduino's serial output buffer. The Arduino is many times faster than serial data moves - even at 250,000 baud
 
Code: [Select]
for (int i=0;i<=23999;i++)
  {

 Serial.println(i);
 
 }


Try adding a short delay() after each Serial.println().

I don't think there would be a problem at 250,000 baud. I normally use 500,000.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

sterretje

but when i access com port using python or in visual studio the data after 5000 is not in order some of bits overlapped or missing.
You're probably overflowing the serial input buffer of the PC. In VB, you can modify it with the ReadBufferSize property. No idea about python.

i observed that the data comes in serial monitor of arduino during Tx LED of arduino ON and whole data transferd and Tx LED blinking during complete transmission of data, where in case of python and VB even if Tx data LED turned off . the data is still coming on the window of python / VB. how this happen why data Transfer and Tx LEDs both not synchronize in case of python and VB.
The data at the PC side is buffered. Once the Arduino has finished transmitting, the TX led will no longer flash. However, your PC application can't read/display the data fast enough; once the Arduino has finished sending, there is still data in the PC's buffer that is read and processed by your application.

This code will overload the Arduino's serial output buffer. The Arduino is many times faster than serial data moves - even at 250,000 baud
I know you know this ;) One will not loose bits or bytes due to that; the Arduino side will just stall till there is space in the output buffer to send the next byte.




If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Robin2

I know you know this ;) One will not loose bits or bytes due to that; the Arduino side will just stall till there is space in the output buffer to send the next byte.
Indeed. But overloading the buffer continuously is poor programming.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up