Pages: [1]   Go Down
Author Topic: fast USB communication or data storage  (Read 1062 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everybody! now, I'm trying to use Arduino as a DAQ for a university project; my acquisition rate should be at least 1KHz. To acquire data, I use analogRead, which works fine; problems arise when I try to send them to the pc: Serial.write() doesn't seem to be fast enough, since it takes 1, 2, sometimes even 3 ms to do the sending. I've tried to come out with some alternative; for example, I see there is a Wire library; could that be solution to my problems? how could I use it? another idea would be, since on-line processing is not required, temporarily store the data; problem is Arduino's built-in memory isn't big enough; so maybe Icould write everything on an SD. would that be fast enough?
Logged

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

Quote
Serial.write() doesn't seem to be fast enough, since it takes 1, 2, sometimes even 3 ms to do the sending.
At what baud rate?

Quote
I see there is a Wire library; could that be solution to my problems?
The Wire library is for I2C communication between two devices that support I2C. Does your PC?

Quote
problem is Arduino's built-in memory isn't big enough
There are external EEPROM chips that you could use.

Quote
so maybe Icould write everything on an SD. would that be fast enough?
Depends on the code. Buffering the data and writing it in large chunks, each time you open the file is faster than opening the file, writing a value, and closing the file.
Logged

South Africa
Offline Offline
Newbie
*
Karma: 1
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have also wondered about the limits of serial communication since I'm using an Uno as DAC for a PC oscilloscope.  My strategy is to gather a block of readings and then send it to the PC in one go.  Using this method enables me to sample at quite high rates, but there is obviously gap when the data gets transmitted.  I poll for data from the PC, with a resulting delay of 33 - 37 ms from sending a request byte to receiving 1775 bytes of data (excluding ADC sampling of course).  I decided to do a test with some variation in data size and BAUD rates using the following code base:
Code:
const word sz = 1;  // < change according to test
byte buf[sz];
void setup(){
  Serial.begin(230400); // < change according to test
}

void loop(){
  for (int i=0; i < sz; i++){
    buf[i] = '-'; }
 
  unsigned long t = micros();
  Serial.write(buf, sz);
  t = micros() - t;
  Serial.println();
  Serial.print("Time = ");
  Serial.print(t);
  Serial.println("us");
  delay(500);
}

Attached please find some results.  Interestingly enough when sending up to 16 bytes of data the time spent in transmission seems to be independent of baud rate (actually it seems as if transmission time increases with increasing baud rate).  The time to transmitting 256+ bytes of data varies on baud rate with the shortest transmission time given by the highest baud rate as expected.  I guess this is related to buffering and polling of all the components along the serial data path and hence may be very system specific. My test system:
  • Debian Wheezy (Linux kernel 3.2.0-2)
  • Arduino 1.01 + Uno Rev. 3 board, standard USB connection between board & PC
  • Baud rates up to 115200 verified using Arduino serial monitor, higher baud rates monitored using a simple Lazarus program using the synaser.pas library

* SerialTest.csv (0.36 KB - downloaded 7 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34210
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You waste time sending strings.
Logged

South Africa
Offline Offline
Newbie
*
Karma: 1
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You waste time sending strings.
True, although the timing is only measured around the Serial.write(buf, sz) call thus exclude the time taken to transmit the report strings.
« Last Edit: July 15, 2012, 01:55:22 pm by Christo » Logged

California
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Without resorting to assembly code or other tricks, I get close to 3000 samples per second for two channels in my LXARDOSCOPE project, available from Sourceforge. The samples from the ADC are transferred through the serial or USB port. The attached screenshot shows a 419.6 Hz sine wave and a 1468.6Hz square wave at a sampling rate of 2938 per second.


* lxardoscope_T.png (23.01 KB, 790x490 - viewed 40 times.)
Logged

Pages: [1]   Go Up
Jump to: