Slow communications.  VB6 to Arduino

I am sending a large amount of data from a VB6 program to an Arduino thru the USB. The com is much slower then I expected. I have isolated the problem but don't know how to solve it.

I have written a small test program in VB6 that outputs five characters to the com port and repeats four times. When I look at the data received on the Arduino board with a scope I see the first five characters followed by about a 4 millisecond delay, then five more characters and another 4 ms delay, five more characters and another 4 ms delay then the last five characters. It's that 4 ms delay that is causing all my problems.

When I run the same test program but output to com 1 (the hard com port on my computer) and look at the transmit pin with a scope I see all 20 characters come without any delay.

I am using basic default com setting with a speed of 115200. I am using the latest virtual com port driver from the FTDI web site.

Can anyone give me any suggestions on how to resolve this??

post the arduino code.

I'm sure it's not an Arduino code problem. I am looking with my scope at the serial data that is coming out of the USB chip and going into pin 1. That's where I am seeing this 4 ms delay. It's got to be a USB thing. Either with the USB chip on the Arduino board or the virtual com port driver on the desktop computer.

Is the Arduino connected directly to the computer or through a hub?

Have you tried other USB ports on the computer?

How is the port initialized? Is any flow control enabled?

Thanks Coding Badly, those are all good questions.
It's connected directly to the computer, no hub. I just tried a different USB port on the computer and it makes no difference. Flow control is turned off. I still have the 4 ms delay.

If it's not too much trouble, try sending data in exactly 64 byte blocks.

These may help...

http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=76081&view=next

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1170939903/0

It looks like from my VB6 program I only get one opportunity to send data to the virtual com port once every 4 ms. It's apparently a windows/USB thing and there is nothing I can do to change that. I have rewritten my VB6 program to send larger blocks of data and that has helped.

Now that I am sending larger blocks of data I have another problem. The RX butter on the Arduino is only 128 bytes. Is there a way to increase it? I would like to be able to set it to 256 bytes.

It looks like from my VB6 program I only get one opportunity to send data to the virtual com port once every 4 ms. It's apparently a windows/USB thing and there is nothing I can do to change that. I have rewritten my VB6 program to send larger blocks of data and that has helped.

Now that I am sending larger blocks of data I have another problem. The RX butter on the Arduino is only 128 bytes. Is there a way to increase it? I would like to be able to set it to 256 bytes.

Did you try sending exactly 64 bytes?

The RX buffer on the Arduino is only 128 bytes. Is there a way to increase it?

I suspect there is but it's beyond my experience. Hopefully, someone else can provide some guidance.

Look in "Arduino/hardware/cores/arduino/HardwareSerial.cpp".

#define RX_BUFFER_SIZE 128
(line 34)

But beware, ATMega chips have very limited RAM, 1024 bytes.

The FT232 chip has a 128 byte transmit buffer so sending blocks of 64 bytes will keep both the FT232 buffer and the Arduino receive buffer from overflowing.

Thanks guys, I have been able to increase the RX butter by changing the RX_Butter_SIZE in HardwareSerial.cpp but I found that if in go over 256 then the Serial.available() command does not report out correctly.

I was able to fix that by changing line 168 in HardwareSerial.cpp from “uint8_t HardwareSerial::available(void)” to “uint16_t HardwareSerial::available(void)” .
And also changing line 50 in HardwareSerial.h from “uint8_t available(void);” to “uint16_t available(void);” .

I can't believe that I figured that out on my own. I am now running a 1024 byte buffer with no problems at all. I have also bumped the com speed up to 230400 and it is still working with no data errors. I didn't know little Arduino could run that fast.

Note: The actual RX buffer size is one less then what is in RX_BUFFER_SIZE.
Example: If you want a true 128 byte buffer use RX_BUFFER_SIZE 129.

Now that's cool!

How much memory (RAM) is left for your programs other needs ?

I don't know. I never figured out how to tell. The ATmega328 has 2K of RAM and I am using half of it for the buffer. Fortunately my program does not use much.