Pages: [1]   Go Down
Author Topic: Max usb speed in Arduino Uno?  (Read 4695 times)
0 Members and 1 Guest are viewing this topic.
Finland
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way to send from Arduino Uno to the host pc via usb-cable faster than baudrate 115200? The serial monitor baudrate list ends at 115200 (version 0021),
but when experimenting with own programs up to 921600 bd seems to "almost" succeed.
(win XP, reading COM13 with hyperterminal of XP).
I am producing megabytes or even gigabytes of sensor data in Arduino and would like to send them continuously to pc for analysis. One way would be to use an microSD-card in Arduino and gather data there, but it would be better, if serial transfer to host via usb would succeed .
I did experiment with this program:
Quote
long starttime, endtime, elapsedtime;
int lines = 500;
long baudrate = 921600; // 115200;

String s = "0123...   1         2         3         4    ...49";
int linelength = s.length() + 2; // incl carriage return + line feed

void setup(){
  Serial.begin(baudrate);
}

void loop(){
  starttime = micros();
  
  for (int ind = 0;ind < lines;ind ++){
    Serial.println(s);
    delay(10); // remove or vary this, or use delayMicroseconds(100)
  } 
 
  endtime = micros();
  elapsedtime = endtime - starttime;
  
  Serial.print("baudrate=");
  Serial.println(baudrate, DEC);
  Serial.print(lines, DEC);
  Serial.print(" lines with ");
  Serial.print(linelength, DEC);
  Serial.print(" characters each, elapsed time in microseconds = ");
  Serial.println(elapsedtime, DEC);
  Serial.print("actual throughput chars/sec = ");
  float charspersec = lines * linelength / (float(elapsedtime) * 0.000001);
  Serial.println(charspersec, 3);
  while(true){
  }
}

When using delay(10), the data arrives well at baudrate 921600 , but  with shorter delays there seems to be something like buffering problems. Or might be the receiving program is too slow (?).
Any ideas to get data to host fast?
« Last Edit: December 29, 2010, 07:56:09 am by optimistx » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should probably begin by looking at the source code for the Serial.begin() function to see what happens when a baud rate is specified.

Specific timing is set up, based on the specified baud rate. Look at what happens when the specified baud rate is not in the list.

You'll notice, if you try to modify the list, that at some point, the resolution of the timer becomes greater than the minimum time required. This limits the speed of serial data transmission.
Logged

Finland
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks PaulS. If Arduino cannot send bits(?) bytes(?) serially at right moments in time at high baudrates, then this feature limits any serial communication, including serial microSD cards, other Arduinos etc ? If so, I have a bigger problem than expected. USB 2.0 (http://en.wikipedia.org/wiki/Universal_Serial_Bus) can transfer
480 megabits per second (57 megabytes/s) , but  Arduino cannot utilize that (?), only  about 10 kilobytes/s. Sigh.

Other cheap, quick and dirty  methods to consider for high speed data transfer to host?
« Last Edit: December 30, 2010, 03:18:25 am by optimistx » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Other cheap, quick and dirty  methods to consider for high speed data transfer to host?

http://www.pjrc.com/teensy/

$18
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16468
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Other cheap, quick and dirty  methods to consider for high speed data transfer to host?

1 Cheap, 2 high-speed, 3 easy to use. You get to pick only any two attributes but Arduino doesn't do #2, if 57Mbytes is your criteria. Arduino is clocked with a 16Mhz crystal, what does that tell you?

Lefty
« Last Edit: December 30, 2010, 03:41:44 am by retrolefty » Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 63
Posts: 6049
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
, then this feature limits any serial communication,
eh, not really.  Anyone who is using an emulated serial port for significant amount of data transfer is probably not going about their solution correctly.

Very rarely does anyone make a complaint about how fast they can transfer data from the Arduino to the PC.  For most cases the Arduino's implementation is fine.  

So in YOUR corner case, it limits "any" serial communication.  However, in the majority of projects using the Arduino the serial connection is, by far, the lowest thing on the list of bottlenecks.

Maybe you need to consider an alternative implementation.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Finland
Offline Offline
Jr. Member
**
Karma: 0
Posts: 96
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks to everyone for the opinions and ideas.
My problem seems to have been the following:
The host can receive at baud rates 115 200, 230 400, 460 800, 921 600,
but my 16 Mhz Arduino can send at baudrates 1 000 000, or 500 000. (or less)
When trying to send at 1 000 000 bd the transmission "almost succeeded", which was astonishing and missleading my thoughts. The difference 921 600 vs 1000 000 was so high that I could not believe that the host really was using 921 600 baud rate.
When the difference in baudrates was differing almost 8 % then during 9 bits the sampling moments would differ too much to get even one byte correctly.
I think that when the baud rates at the sender and the receiver are the same,  the transmission should succeed even at 2 megabaud rate well. (datasheet of 328).
I probably try Bluetooth next by acquiring a bluetooth usb stick to the host and a bluetooth circuit to Arduino to send. 800 kbytes/second should be possible in theory, which solves the transmission speed problem well.

Teensy is also an interesting idea, 800 kbytes/s with usb cable. How is that possible, different software or different hardware or both?
« Last Edit: January 05, 2011, 02:53:08 pm by optimistx » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Teensy is also an interesting idea, 800 kbytes/s with usb cable. How is that possible, different software or different hardware or both?
Both.  It uses an Atmel chip with an integrated USB controller.  The processor is able to communicate directly with the host computer via USB.
Logged

Pages: [1]   Go Up
Jump to: