Try this super fast analog pin logger

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).

toneAC DEMO-2.CSV (1.6 MB)

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?

No.
We can't see your code.
Also we don't know how you are " trying to print the values into a CSV file".

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 :blush:.
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

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.

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:

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)

readme.txt (4.26 KB)

raschemmel:
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.

raschemmel:
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

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.

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!

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 (VirtualWire: VirtualWire library for Arduino and other boards). To start the acquisition I modified the code like this:

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:

    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

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.

Thanks for your answer,

I am trying to to start and stop the acquisition using a RF transmitter and receiver. My question had nothing to do with the conversion between bin to csv. I was asking how to solve the conflict between virtualwire and the analogbinlogger since, I think, they both use timer1.

Thanks again

Edit: I suspect using VirtualWire will cause this logger to fail, even if you modify it to use a different timer. VirtualWire takes too long in its interrupt routine.

Timer1 is used to start the ADC conversion. Only timer0 or timer1 can be used to trigger the ADC but timer0 is used for mills() and micros().

Timer2 is free but a mod to the VirtualWire library would be required. This is probably not too difficult since VirtualWire runs on ATtiny85 using timer0 which is 8-bits. I believe timer2 has all the required features.

If you can live with logging at 500 Hz or less, the new SdFat has a logger that does not use timer1, the LowLatencyLogger example.

The new library is here GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library.

Using VirtialWire with any fast logger may cause problems.

Thank you so much for your answer. I need 5kHz so I will try to change the virtualwire library.

Best regards.

Hi fat16lib,

First of all, I really appreciate your work and I just wanted to let you know that it helped me a lot. I downloaded your AnalogIsrLogger20121219 zip.file(I know it is the older version) and currently working on logging the Analog pin.

Detailed Specifications

  1. Arduino Uno
  2. 32GB SanDisk SDHC card
  3. Attempting to log 250Hz, 1V sine wave into SDcard. (using a Digilent Explorer board to generate signal input to arduino)

So far, the only thing that i changed in your code is setting the SD chip select pin from SS to 4.

// SD chip select pin
const uint8_t chipSelect = 4;

I was able to access the menu shown in "Menu" snippet in the attachment and was able to log the data and covert the binary to a text file.

CURRENT ISSUE:
When i try to feed analog data to the Arduino into port A0, i do not get the results i want. The code does not seem to detect any input signal, the interrupt does not seem to be working as well. The result is a constant value that does not change even when i manipulate the frequency or amplitude of the analog signal. Refer to the "Result" snippet at the attached.

Can someone please help me out with this? I do not understand as to why this is happening.

menu.PNG

AnalogIsrLogger20121219 zip(I know it is the older version)

Please download the latest SdFat from GitHub and try the current version of AnalogBinLogger.

The example is here https://github.com/greiman/SdFat/tree/master/SdFat/examples/AnalogBinLogger

I'm doing the same thing, starting & stopping analogbinlogger with a RF transmitter/receiver. I don't use virtualwire. Just connect RF receiver output to one of the digital input pins. Check this pin for HI or LO signal.

tharekmohtar:
Thanks for your answer,

I am trying to to start and stop the acquisition using a RF transmitter and receiver. My question had nothing to do with the conversion between bin to csv. I was asking how to solve the conflict between virtualwire and the analogbinlogger since, I think, they both use timer1.

Thanks again

Hi fat16lib.
I want to record data in kHz from arduino to SDcard. I have 2GB SD card FAT16, and SDcard holder.
I downloaded your AnalogBinLogger20140326beta.zip(1.88MB) file. i tried for two days following your instructions and changing files and folders here and there and fully messed up. i just want a fresh start.
I uninstalled and installed Arduino 1.0.5-r3.

Kindly suggest the procedure steps after unzipping the file(i.e, what files to keep where). i have read your 'read me' file. sorry to say that i got confused. plz tell me where to keep SdFat.h, SdFat.cpp, BufferedWriter.h, BufferedWriter.cpp and remaining files if any.

I read the previous posts but didn't make out. kindly give the steps to follow

Thank you

I have removed the beta version of this program. Please download the newest SdFat from GitHub GitHub - greiman/SdFat: Arduino FAT16/FAT32 exFAT Library.

AnalogBinLogger is now a SdFat example https://github.com/greiman/SdFat/tree/master/SdFat/examples/AnalogBinLogger.

Also see this directory https://github.com/greiman/SdFat/tree/master/AnalogBinLoggerExtras

See the SdFat readme file and the html documentation for installing SdFat.

You must manually install SdFat by copying the SdFat folder from the download package to the Arduino libraries folder in you sketch book.

See the Manual installation section of this guide http://arduino.cc/en/Guide/Libraries

Hi Fat16lib,

I finally got it working, using the 2014beta version!! So i was able to sample a 250Hz wave and reconstruct the signal which is then played in MATLAB. It sounds pretty good, almost perfect! Thought it would be nice to let you know!

Questions

  1. I realized once i set my SAMPLE_RATE to be greater than 8000Hz, I receive an error saying "Sample rate too high". Why is that? Am i bounded by the limitations of the SD card write latency?

  2. Also, in the readme, it says

"If your SD card has a long write latency, it may be necessary to use slower sample rates."

How would you measure the optimal sample rate to use? I would think, a higher sample rate would always be better.But then again i'm a newbie!

Reminder:
Detailed Specifications

  1. Arduino Uno
  2. 32GB SanDisk SDHC card
  3. Attempting to log 250Hz, 1V sine wave into SDcard. (using a Digilent Explorer board to generate signal input to arduino)

Sorry for these questions, I'm new, but i'm willing to learn!! Let me know if you want any data/testing from me. I would gladly obliged :slight_smile:

I realized once i set my SAMPLE_RATE to be greater than 8000Hz, I receive an error saying "Sample rate too high". Why is that? Am i bounded by the limitations of the SD card write latency?

Many of your questions are covered in the folder I asked you to look at https://github.com/greiman/SdFat-beta/tree/master/AnalogBinLoggerExtras.

The maximum possible sample rate depends on how many pins you are logging and the ADC clock frequency. See RateTable.txt in in the the above folder. Also see the readme.txt and AdcErrorStudy.txt.

If your SD card has latency problems, you will get data overrun errors. A Mega will eliminate SD latency problems since it has more RAM.

If you log only one pin, you may be able to log at 40,000 Hz.

Try the following:

//------------------------------------------------------------------------------
// 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 a short run I did on an Uno at 40,000 Hz logging Analog pin zero.

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: ANALOG04.BIN
Max block write usec: 1116
Record time sec: 77.307
Sample count: 3092251
Samples/sec: 39999.62
Overruns: 0

You can log slightly faster if you select 8-bit mode.

// Set RECORD_EIGHT_BITS non-zero to record only the high 8-bits of the ADC.
#define RECORD_EIGHT_BITS 1

Here is a run with 18 μs between samples, about 55,555 Hz.

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: ANALOG07.BIN
Max block write usec: 1304
Record time sec: 142.443
Sample count: 7913444
Samples/sec: 55555.16
Overruns: 0
Done