Wildfire v4 SD card logging


#1

Hello:

I’m trying to configure my wildfire v4 board to log data from multiple analog sensors to an SD card, as well as publish to sparkfun. I have limited coding experience, but is there a simple add on sketch I can copy into the demo sketch that comes pre-programmed on the board?

Thanks!


#2

Sorry for the lag in responding. The source code for the demo is located online here: https://github.com/wickeddevice/wildfirev4demo

You would just need to modify it to integrate writing to SD card, e.g. by inserting some code here. You could get a pretty good handle on what code to put in there by looking at the File => Examples => SD => ReadWrite example code that comes with Arduino. Something like:

#include <SD.h>
 ...
 void setup() {
   ...
     Serial.print("Initializing SD card...");
     if (!SD.begin(16)) {
       Serial.println("initialization failed!");
       return;
     }
     else{
       Serial.println("initialization done.");
     }
     ...
 }

…then change the code that looks like this…

  for(uint8_t ii = 0; ii < 8; ii++){
    if(configuration.ANALOG_ENABLE[ii]){
      uint16_t value = analogRead(ii);
      field[num_channels_enabled++] = value;      
      configuration.PREVIOUS_VALUE[ii] = configuration.CURRENT_VALUE[ii];
      configuration.CURRENT_VALUE[ii] = value;
    }
  }       

… to look something more like this:

  File myFile;
  for(uint8_t ii = 0; ii < 8; ii++){
    if(configuration.ANALOG_ENABLE[ii]){
      uint16_t value = analogRead(ii);

     // print the value to a file called test.txt with a comma after it
     myFile = SD.open("test.txt", FILE_WRITE);
     if (myFile) {
       myFile.print(value);
       myFile.print(",");
       myFile.close();
     } else {
       Serial.println("error opening test.txt");
     }         
     
      field[num_channels_enabled++] = value;      
      configuration.PREVIOUS_VALUE[ii] = configuration.CURRENT_VALUE[ii];
      configuration.CURRENT_VALUE[ii] = value;
    }
  }  

  // then print a carriage return and new line at the end of the line
  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {
    myFile.print("\r\n");
    myFile.close();
  } else {
    Serial.println("error opening test.txt");
  }

You might be able to come up with something more elegant, like writing the line to a temporary buffer and doing a single write to the SD card after buffering the line.


#3

Thanks, it seems to be working! The only thing now is getting a date/time added to the data output string on the text file? Any Ideas?

Here are a few more questions:

I’m curious is there is a way to download time series data directly from sparkfun.

The data display on sparkfun looks a bit off, like the log time is jumping back and forth.

Is there anything that I could do do fix this?

A little backstory to help understand what I’m doing. I’m using the wildfire V4 board to measure stage and temperature of small streams as part of a graduate school project. While monitoring the data on sparkfun helps reduce visits to each of the gauges i’m setting up, I really need to have copies of the output data for analysis.

I really appreciate the help!


#4

I wish I could help you more, but I’m not that experienced with data.sparkfun.io’s capabilities. I know it is a phant.io server. You could always stand up your own phant.io instance. I probably can’t shed any more light on it other than what’s already available to read at http://data.sparkfun.com/. It also looks like their service is kind of “down” right now and they are encouraging people to use other services.