0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« on: October 17, 2009, 04:43:05 pm » |
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??
|
|
|
|
|
Logged
|
|
|
|
|
Queens, NY
Offline
Jr. Member
Karma: 0
Posts: 57
Arduino rocks =op
|
 |
« Reply #1 on: October 17, 2009, 07:03:27 pm » |
post the arduino code.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #2 on: October 17, 2009, 07:50:48 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 116
Posts: 10130
|
 |
« Reply #3 on: October 17, 2009, 08:17:59 pm » |
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?
|
|
|
|
« Last Edit: October 17, 2009, 08:20:17 pm by bcook »
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #4 on: October 17, 2009, 08:50:39 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 116
Posts: 10130
|
 |
« Reply #5 on: October 17, 2009, 09:44:03 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #6 on: October 25, 2009, 12:46:55 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #7 on: October 25, 2009, 12:47:38 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 116
Posts: 10130
|
 |
« Reply #8 on: October 25, 2009, 03:55:20 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Gothenburg, Sweden
Offline
Jr. Member
Karma: 0
Posts: 87
Arduino rocks
|
 |
« Reply #9 on: October 25, 2009, 05:17:40 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #10 on: November 01, 2009, 02:48:36 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen / Denmark
Offline
Edison Member
Karma: 5
Posts: 2338
Do it !
|
 |
« Reply #11 on: November 01, 2009, 03:11:10 pm » |
Now that's cool!
How much memory (RAM) is left for your programs other needs ?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 7
Arduino rocks
|
 |
« Reply #12 on: November 01, 2009, 03:24:20 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
|