/* ArDAQ, Arduino Data Acquisition (DAQ) 1-6 channels (analog voltage input on pins A0-A5) ascii serial transmission for Arduino UNO / ATmega328P This source code is public domain. Enjoy! This sketch does not scale the data, but it could easily be modified to do so or the data can be scaled in post processing (gnuplot/c/calc/excel/etc). Serial output format: \r\n ArDAQ\r\n sample_type\tascii\r\n bits_per_sample\t10\r\n channels\t\r\n begin_scan_rate_cal\r\n ...interleaved ascii samples... \r\n end_scan_rate_cal\r\n scan_rate\t\r\n begin_daq\r\n ...channel name header... ...interleaved ascii samples... The data can be copied out of the Arduino Serial Monitor on any platform. On Linux, 'screen -L /dev/ttyACM0 115200' is particularly useful. Performance at 115200 baud: 6-channel 10-bit ascii 471 scans/second 1-channel 10-bit ascii 2353 scans/second */ /* configuration */ #define serial_baud_rate 115200 #define start_channel 0 #define end_channel 5 #define ascii_delimiter '\t' void scan_and_transmit() { int sample[end_channel-start_channel+1]; for (byte channel=start_channel; channel<=end_channel; channel++) sample[channel] = analogRead(channel+14); for (byte channel=start_channel; channel<=end_channel; channel++) { Serial.print(sample[channel]); if (channel != end_channel) Serial.print(ascii_delimiter); } Serial.print("\r\n"); } void calculate_scan_rate() { unsigned long start_time; unsigned long end_time; unsigned long elapsed_time = 0; unsigned short scans = 0; float scan_rate; Serial.print("begin_scan_rate_cal\r\n"); start_time = millis(); while (elapsed_time < 1000) { scan_and_transmit(); scans++; end_time = millis(); elapsed_time = end_time - start_time; } scan_rate = scans / (elapsed_time / 1000.0); Serial.print("\r\n"); Serial.print("end_scan_rate_cal\r\n"); Serial.print("scan_rate"); Serial.print(ascii_delimiter); Serial.print(scan_rate); Serial.print("\r\n"); } void setup() { Serial.begin(serial_baud_rate); //setup serial port int sample; for (byte channel=start_channel; channel<=end_channel; channel++) sample = analogRead(channel+14); //setup pins, A0=14, A5=19 Serial.print("\r\n"); Serial.print("ArDAQ\r\n"); Serial.print("sample_type"); Serial.print(ascii_delimiter); Serial.print("ascii\r\n"); Serial.print("bits_per_sample"); Serial.print(ascii_delimiter); Serial.print("10\r\n"); Serial.print("channels"); Serial.print(ascii_delimiter); Serial.print(end_channel-start_channel+1); Serial.print("\r\n"); calculate_scan_rate(); Serial.print("begin_daq\r\n"); for (byte channel=start_channel; channel<=end_channel; channel++) { Serial.print("A"); Serial.print(channel); if (channel != end_channel) Serial.print(ascii_delimiter); } Serial.print("\r\n"); } void loop() { scan_and_transmit(); }