Go Down

Topic: Try this super fast analog pin logger (Read 64460 times) previous topic - next topic

fat16lib

Quote
Can you help me configure it to sample A0 at 40,000 samples per second ?


First you need an SD card that has very low write latency.

I found this card works very well http://www.amazon.com/SanDisk-Class-Flash-Memory-SDSDB-004G-AFFP/dp/B007JRB0RY.

Change only these values.
Code: [Select]
//------------------------------------------------------------------------------
// Analog pin number list for a sample.  Pins may be in any order and pin
// numbers may be repeated.
const uint8_t PIN_LIST[] = {0};
//------------------------------------------------------------------------------
// Sample rate in samples per second.
const float SAMPLE_RATE = 40000;  // Must be 0.25 or greater.

Here is serial output for recording about five minutes of data.  The proper SDHC card is extremely important.
Quote

Sample pins: 0
ADC bits: 10
ADC clock kHz: 1000
Sample Rate: 40000.00
Sample interval usec: 25.0000
Creating new file
Erasing all data
Logging - type any character to stop
Truncating file
File renamed: ANALOG01.BIN
Max block write usec: 1112
Record time sec: 304.766
Sample count: 12190600
Samples/sec: 39999.87
Overruns: 0
Done


Quote

What does 8-bit mode mean for the 2000 hZ clock rate ?

8-bit mode only records the high 8-bits of each ADC  reading .  At 2000 kHz ADC clock rate the ADC only provides about 7.5 significant bits. see the ADC_ENOB.PNG file.  This reduces the amount of date written so it is easier for SD cards to handle the data rate.

I didn't include 8-bit mode in the max data rate table.  Here is a version with 8-bit mode.

Code: [Select]


ADC clock kHz 8-bit only
125 250 500 1000 2000
pins
1 7692 14286 25000 40000 57143
2 3810 6667 11111 16667 22222
3 2572 4790 8421 13559 19512
4 1942 3636 6452 10526 15385
5 1559 2930 5229 8602 12698
6 1303 2454 4396 7273 10811
7 1119 2111 3791 6299 9412
8 980 1852 3333 5556 8333
9 872 1649 2974 4969 7477
10 786 1487 2685 4494 6780
11 715 1354 2446 4103 6202
12 656 1242 2247 3774 5714
13 606 1148 2078 3493 5298
14 563 1067 1932 3252 4938
15 525 996 1806 3042 4624
16 493 935 1695 2857 4348

Here is serial monitor output for a short recording with an 18 microsecond sample interval.
Quote

Sample pins: 0
ADC bits: 8
ADC clock kHz: 2000
Sample Rate: 55555.55
Sample interval usec: 18.0000
Creating new file
Erasing all data
Logging - type any character to stop
Truncating file
File renamed: ANALOG02.BIN
Max block write usec: 1304
Record time sec: 28.103
Sample count: 1561189
Samples/sec: 55552.39
Overruns: 0



BrownSuedeShoes

I am relatively new to arduino, but I am trying to get this code working on my Yun. I am trying to run your code as is, but I am getting a number of errors. Can you help clear up what I am doing wrong?

Code: [Select]
Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Yún"

AnalogBinLogger:143: error: 'SdFat' does not name a type
AnalogBinLogger:145: error: 'SdBaseFile' does not name a type
AnalogBinLogger.ino: In function 'void error_P(const char*)':
AnalogBinLogger:251: error: 'sd' was not declared in this scope
AnalogBinLogger.ino: In function 'void binaryToCsv()':
AnalogBinLogger:416: error: 'SdFile' was not declared in this scope
AnalogBinLogger:416: error: expected `;' before 'csvFile'
AnalogBinLogger:418: error: 'BufferedWriter' was not declared in this scope
AnalogBinLogger:418: error: expected `;' before 'bw'
AnalogBinLogger:420: error: 'binFile' was not declared in this scope
AnalogBinLogger:424: error: 'binFile' was not declared in this scope
AnalogBinLogger:430: error: 'csvFile' was not declared in this scope
AnalogBinLogger:430: error: 'O_WRITE' was not declared in this scope
AnalogBinLogger:430: error: 'O_CREAT' was not declared in this scope
AnalogBinLogger:430: error: 'O_TRUNC' was not declared in this scope
AnalogBinLogger:438: error: 'bw' was not declared in this scope
AnalogBinLogger:438: error: 'csvFile' was not declared in this scope
AnalogBinLogger.ino: In function 'void checkOverrun()':
AnalogBinLogger:497: error: 'binFile' was not declared in this scope
AnalogBinLogger:501: error: 'binFile' was not declared in this scope
AnalogBinLogger:504: error: 'binFile' was not declared in this scope
AnalogBinLogger.ino: In function 'void dumpData()':
AnalogBinLogger:538: error: 'binFile' was not declared in this scope
AnalogBinLogger:542: error: 'binFile' was not declared in this scope
AnalogBinLogger.ino: In function 'void logData()':
AnalogBinLogger:584: error: 'sd' was not declared in this scope
AnalogBinLogger:596: error: 'sd' was not declared in this scope
AnalogBinLogger:604: error: 'binFile' was not declared in this scope
AnalogBinLogger:605: error: 'sd' was not declared in this scope
AnalogBinLogger:614: error: 'sd' was not declared in this scope
AnalogBinLogger.ino: In function 'void setup()':
AnalogBinLogger:752: error: 'FreeRam' was not declared in this scope
AnalogBinLogger:755: error: 'sd' was not declared in this scope
AnalogBinLogger:755: error: 'SPI_FULL_SPEED' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

raschemmel

Read Reply#5 & 6 on this post. Explains about where BIN2CSV program should be located. (can't be in same directory as library)
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Turtle9er

Hi,

I was wondering if this sketch can be used on a Teensy 3.1. did a quick test, however a few errors came up with respect to Too Little Ram and QUEUE_DIM, which is due to ram error not letting those be defined. If it is a easy fix to get this working on a teensy, that would be awesome. Thanks.

fat16lib

Quote
I was wondering if this sketch can be used on a Teensy 3.1 .... If it is a easy fix to get this working on a teensy, that would be awesome. Thanks.


The logger is closely associated with AVR so it would require a lot of mods. 

I have no interest in porting this program to ARM since an RTOS based solution would be better on ARM.

raschemmel

Attached is a sample of the toneAC library toneAC DEMO playing a whistle followed by the classic "Shave and a haircut, two bits."
melody from many many years back (probably 1800s western america era).
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

kitkadbury

#21
Jun 25, 2014, 04:46 am Last Edit: Jun 25, 2014, 04:30 pm by kitkadbury Reason: 1
A newbie in arduino here. I'm trying to do datalogging and print the ADC values onto a CSV file. I've configured A2 as the sample pin. On the serial monitor, the values are consistent, however on the excel file, there are gibberish characters and inconsistent jump in the values. Could someone help me please?  

raschemmel

#22
Jun 25, 2014, 04:50 am Last Edit: Jun 25, 2014, 04:52 am by raschemmel Reason: 1
No.
We can't see your code.
Also we don't know how you are "  trying to print the values into a CSV file".
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

G_46

Hi All,
thanks a lot to Fat16lib to share this with us. I am using the AnalogBinLogger20140326beta version on a Arduino Mega 2560 + Arduino Wireless SD Shield + Panasonic Micro SD HC I (class 10). Please note that I am new to Arduino and to C code too  :smiley-red:.
My aim is to log 4 analog pin at 200 Hz and the system must run straight after the the user will switch on the board (it is a DAQ mounted on a race car), without computer connected (so no serial monitor and no keyboard to give input to the program). Logging periods of my application are between 4 and 6 minutes

So I will really appreciate if you can help with the followings

1. I wish to modify the code in a way that the time is recorded too. [this is very important for applications that need to post process the data in the time or frequency domain. This will also give an idea the user if the logging frequency is stable or not, again this is very important if you FFT the logged data]

2. I wish to modify the code in a way that the data logging will start when the user will switch on the board and will finish when the user will switch the board off. I know that can cause some issue as the board is switched off while the record is going on, but adding a button to start stop is really the last of the option I would like to use. Perhaps the transition from .BIN to .CVS could be done later in the post processing?

I will really appreciate any help with these two question.

Thanks in advance

G

raschemmel

#24
Jun 27, 2014, 03:38 pm Last Edit: Jun 27, 2014, 04:37 pm by raschemmel Reason: 1
Read the previous posts . The "transistion " as you call it is called "file conversion" from bin to csv. If you don't do it immediately after stopping the recording then you have to use a command window  and command line  commands, which is much more complicated. I don't think you can use this program to log timestamps. It is what it is. It logs analog data. If that's not enough for you then go write your own program.  You don't really need to log timestamps because the ADC clock speed that you set tells you what the sampling time is. Knowing the sampling time means you can create a column in Excel and fill it with the value of the sampling time added to each cell, so if the sampling time was 25uS, the first cell would contain 0. The second cell in that column would contain"25", the 3rd, "50 " and so on. When you plot the data column with respect to the column containing those values,
you are in fact plotting the analog data with respect to time in uS, are you not ?

 Read the instructions. You do not understand how to use this program because you have not read any instructions. This program does not print to CSV.  Get that idea out of your head. Secondly, the program interface is the serial monitor. The command menu is printed to the serial monitor.

Quote
The program has four commands:

c - convert file to CSV
d - dump data to Serial
e - overrun error details
r - record ADC data

All commands can be terminated by entering a character from the serial monitor.





If you are getting jibberish characters it is because your baud rate is wrong. Post a screenshot of your serial monitor screen. Also post an explanation of how you are using the program. so we can verify that you actually know what your doing . Post the explanation in the following format:
STEP-1: [DO THIS]
STEP-2 [DO THIS]
etc. .


etc

You have posted absolutely nothing that indicates you have the slightest clue how to use this program. You can see my posts with the excel plots and I had no problem using it. The fact that you state this:

Quote
I'm trying to do datalogging and print the ADC values onto a CSV file.  


Means you don't understand how this program works. It is a BIN LOGGER .That is even in the name of the sketch.
What does that mean ? It means it is NOT A CSV LOGGER. or it would be named AnalogCSVLogger.   It creates BIN files which must be converted to CSV files. You can do the conversion after you stop recording or you can do it later using the command window. The first method is easer.

In the future, if a program doesn't work, try reading the Readme file (see attaached)
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

G_46


I don't think you can use this program to log timestamps. It is what it is. It logs analog data. If that's not enough for you then go write your own program. 


See Raschemmel, people like you should be banned from the forum. This is not a place to discuss about commercial software where you cannot change anything, this forum is for people sharing knowledge and to interact together to change and improve open source software. Your post is full of complains and shows your disrespectful attitude with people who are newbies.


You don't really need to log timestamps because the ADC clock speed that you set tells you what the sampling time is.  


I had already problems with sampling time from the ADC not being constant, so that s one of the reasons I am asking to log the time, for checking purposes.  If you are not able to suggest a constructive chance to the program to achieve that , then do not answer, we do not need your complains, be respectful!

And remember this is a place where people ask "politely" for help, want to find solutions and discuss different approaches and techniques, there is no space for your negative attitude, shut the f. up!

G

raschemmel

#26
Jun 28, 2014, 10:42 am Last Edit: Jul 12, 2014, 03:12 am by raschemmel Reason: 1
I take it that means you finally read the Readme file ?

" Your  welcome"
If anyone should be banned from the forum it's people who don't read Readme files.
I respect people who take the time to do their homework before crying "help".
Good luck loggong timestamps with the BinLogger.
FYI,
The ADC clock is accurate . If you don't believe that I dare you to post your code so we can see the proof.
BTW,
Open source doesn't mean if the software doesn't do what you want you can ask someone ELSE to change it for you.
It means YOU can can change it.  If you don't like the way it works then write your own code.
Why is it disrespectful to tell you that the reason you are getting gibberish in your Excel file is that you didn't read the Readme file and
you think the program logs ASCI to a CSV file in realtime when actually it logs BIN files (hence the name BinLogger) which must be converted to CSV AFTER the logging is complete.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Matoo

Hi, im a newbie here and im trying to interface the AnalogBinLogger code with a Nokia 5110 LCD and an SD card module. However, i keep getting these errors.

error: createContiguous failed
SD errorCode: 0X19,0X0

I tested the SD card using the CardInfo code and it works fine..
Can somebody help me please?
Thanks in advance!

tharekmohtar

#28
Aug 19, 2014, 09:55 pm Last Edit: Aug 20, 2014, 02:12 pm by tharekmohtar Reason: 1
Hello guys,

I already try the code and it works like a charm. I was trying to modify it because I want to start and end the acquisition of data remotely. I bought a cheap RF transmitter and receiver (https://www.sparkfun.com/products/10532 and https://www.sparkfun.com/products/retired/8946)  and downloaded the virtualwire library (http://www.airspayce.com/mikem/arduino/VirtualWire/). To start the acquisition I modified the code like this:

Code: [Select]
void setup(void) {
 if (ERROR_LED_PIN >= 0) {
   pinMode(ERROR_LED_PIN, OUTPUT);
 }
 Serial.begin(9600);
 
 vw_setup(2000);             // Bits per sec
 vw_set_rx_pin(8) ;
 vw_rx_start();              // Start the receiver
 
 // Read the first sample pin to init the ADC.
 analogRead(PIN_LIST[0]);
 
 Serial.print(F("FreeRam: "));
 Serial.println(FreeRam());

 // initialize file system.
 if (!sd.begin(SD_CS_PIN, SPI_FULL_SPEED)) {
   sd.initErrorPrint();
   fatalBlink();
 }
}
//------------------------------------------------------------------------------
void loop(void) {
 Serial.println();
 Serial.println(F("type:"));
 Serial.println(F("c - convert file to CSV"));
 Serial.println(F("d - dump data to Serial"));  
 Serial.println(F("e - overrun error details"));
 Serial.println(F("r - record ADC data"));

 while(!vw_get_message(message, &msgLength)) {}
 if (ERROR_LED_PIN >= 0) {
   digitalWrite(ERROR_LED_PIN, LOW);
 }
 
 if (message[0] == 'c')
 {
   binaryToCsv();
 }
 else if (message[0] == 'd')
 {
   dumpData();
 }
 else if (message[0] == 'e')
 {
   checkOverrun();
 }
 else if (message[0] == 'r')
 {
   logData();
 }
 else
 {
   Serial.println(F("Invalid entry"));
 }
}


So when i send the letter r from my other arduino  the one with the sd card starts recording. The problem is when I try to stop it. To do so I modified the logdata function:

Code: [Select]
   if (vw_get_message(message, &msgLength)) {
     // stop ISR calls
     adcStop();
     if (isrBuf != 0 && isrBuf->count >= PIN_COUNT) {
       // Truncate to last complete sample.
       isrBuf->count = PIN_COUNT*(isrBuf->count/PIN_COUNT);
       // put buffer in full queue
       fullQueue[fullHead] = isrBuf;
       fullHead = queueNext(fullHead);
       isrBuf = 0;
     }
     if (fullHead == fullTail) break;
   }


But the former does not work. I read in the virtualwire documentation that it uses timer1 and I think that is why my code is not working but I don't know how to fix it.

Any advice?

Thanks in advance to you all

raschemmel

#29
Aug 20, 2014, 12:03 am Last Edit: Aug 20, 2014, 12:05 am by raschemmel Reason: 1
There is only one way to stop the recording. Put the cursor in the serial monitor entry window and hit any key.
The serial monitor menu prints a promot to that effect when it starts the recording . The menu is only viewable on the serial monitor.
After stopping the recording, if you do not endter the letter command to convert the file to CSV then you will have to convert it from binary later using the dos command window using the command line commands for converting it. It is MUCH more convenient to do the conversion immediately after stopping the recording.

READ THE README FILE . EVERYTHING IS IN THERE.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Go Up