0

Feather Adalogger not saving data and other issues
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather Adalogger not saving data and other issues

by mkline93 on Sun May 02, 2021 11:58 am

I am building a simple voltage logger with a Feather M0 Adalogger for my motorcycle. I installed a new LiIon battery and want to make sure that the 42 year old regulator/rectifier is not overvolting it during riding. On the stand it seems to be working fine but there are some weird spikes I want to check out.
I have gone through the set up process linked to the product page, including Blink and CardInfo, and then the SimpleDataLogger. I am currently only using the board plugged into USB, so it has a singular, solid power supply so far.

The example program is really all I need- only monitoring one analogue input and saving the data to the card. But I have been unable to get it to work as described in the tutorial. The serial monitor displays fine (*with issue but we will get there later), and the program creates the text files as it should. But the files are empty. The tutorial says that for power savings, the program or board is set to write only every 50 data points, but as it's not in the code, I can't look at it or make it give an indication that that ever happens (blinking light, a message, etc). Is this something that is supposed to be in the program, or is this in the back end on the board?

I was able to get data to write to the card by using the flush command mentioned in the tutorial, but the issue I mentioned with the monitor comes in to play here- the data written to the monitor is showing an average of 330 (is that the 3.3 volts of the board floating on A0?), but the board is only showing an average of 280. Any ideas on the difference here? The numbers don't match exactly as far as I can tell, like if it was writing a half a volt low on the card and I could just add that back in manually. The numbers come from two checks right after each other, so I don't understand why they would be different. Is there a need to to read the voltage and then apply it to a variable and then output the variable to the monitor and the card? I wont have the monitor running on the bike, or course, but I'm concerned that they are different.

Anyone have some ideas?
Thanks

mkline93
 
Posts: 6
Joined: Tue Dec 01, 2020 7:37 pm

Re: Feather Adalogger not saving data and other issues

by mkline93 on Tue May 04, 2021 5:52 pm

Anyone? Anyone? Bueller?

I have until the end of the week probably to figure this out, since that's when I get the last part in to fix an oil leak and I can get back out to ride...

mkline93
 
Posts: 6
Joined: Tue Dec 01, 2020 7:37 pm

Re: Feather Adalogger not saving data and other issues

by BDL on Tue May 04, 2021 7:54 pm

You may need to issue a flush command. This forces a write to the SD card. I had a similar problem until I put in the flush. So if your filename is logfile, you need to periodically issue a logfile.flush() command. In my case, I do it every 5 seconds. That way, at most you will lose the last 5 seconds of the log. Hope this helps.

BDL
 
Posts: 129
Joined: Wed Jan 09, 2019 10:45 pm

Re: Feather Adalogger not saving data and other issues

by adafruit_support_carter on Thu May 06, 2021 1:53 pm

It looks like that linked gist (example sketch code) is a little out of sync with what is described in the guide. But I think your issue with not getting any data may be related to what is mentioned above. There's a blurb about this below the example code:
https://learn.adafruit.com/adafruit-fea ... -2202195-8

adafruit_support_carter
 
Posts: 20281
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather Adalogger not saving data and other issues

by mkline93 on Sat May 08, 2021 6:11 pm

Thanks for the replies.
I appear to be misinterpreting the guide, or I'm missing some part of this. The guide says "Note that to save power, we buffer the data, so you will only 'save' data truely every 50 datapoints (512 total characters written)". Since this process is /not/ in the code, that would imply that the process of using a flush command happens on the board itself. In the blurb under the text that was mentioned, it says "If you really want to make sure you save every data point, put a logfile.flush(); right after the logfile.print's..."- this also indicates the same thing, where the board handles the buffering and writing, but if you really really want every single data point, here's how to make it do it one at a time.

So again, where is the buffering happening? Is it a counter with a flush command that wasn't included in the example sketch? Or is it supposed to be happening on the board? When you say the example sketch is not reflecting what the guide says it does, is that the fact that the counter and flush command got left out?

thanks

mkline93
 
Posts: 6
Joined: Tue Dec 01, 2020 7:37 pm

Re: Feather Adalogger not saving data and other issues

by adafruit_support_carter on Mon May 10, 2021 10:26 am

So again, where is the buffering happening?

In the SD library code somewhere. Or possibly in some other library that SD is using.

Does adding the logfile.flush(); still not work?

adafruit_support_carter
 
Posts: 20281
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather Adalogger not saving data and other issues

by mkline93 on Mon May 10, 2021 6:04 pm

The fact that the flush command works constitutes the entire last paragraph of my original post... Including the second request for ideas about the fact that the data being written to the monitor and the card are different, which helps no one when you are trying to log accurate data.

Everything I can find on the flush command indicates that it's either called directly or it's executed on a file close. I did notice that the example code never closes the file... It just keeps writing forever... I guess I'll try adding a counter to save the buffer once in a while. I'll also dig into the libraries and see if I can figure something out there.

Are you guys able to use an off the shelf Adalogger properly following the tutorial? I'm still not sure if it's something I did wrong in the libraries set up- a lot of the names of stuff have changed since it was written and short of just installing ALL THE LIBRARIES, I don't know how to check this (I mean, maybe installing one by one, but that appears to make sense).

Thanks

Edit: I'm not alone! Here is almost the exact same issue from 2017, but it is unresolved.
viewtopic.php?f=8&t=114492

mkline93
 
Posts: 6
Joined: Tue Dec 01, 2020 7:37 pm

Re: Feather Adalogger not saving data and other issues

by adafruit_support_carter on Mon May 10, 2021 10:03 pm

I just tested a slightly modified version of that sketch on a Feather M0 Adalogger. Without using logfile.flush() I ended up with an empty file. Adding logfile.flush() fixed it.

Here is the sketch I ran:
Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <SD.h>

// Set the pins used
#define cardSelect 4

File logfile;

// blink out an error code
void error(uint8_t errno) {
  while(1) {
    uint8_t i;
    for (i=0; i<errno; i++) {
      digitalWrite(13, HIGH);
      delay(100);
      digitalWrite(13, LOW);
      delay(100);
    }
    for (i=errno; i<10; i++) {
      delay(200);
    }
  }
}

// This line is not needed if you have Adafruit SAMD board package 1.6.2+
//   #define Serial SerialUSB

void setup() {
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);
  while (!Serial) delay(10);
  Serial.println("\r\nAnalog logger test");
  pinMode(13, OUTPUT);


  // see if the card is present and can be initialized:
  if (!SD.begin(cardSelect)) {
    Serial.println("Card init. failed!");
    error(2);
  }
  char filename[15];
  strcpy(filename, "/ANALOG00.TXT");
  for (uint8_t i = 0; i < 100; i++) {
    filename[7] = '0' + i/10;
    filename[8] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }

  logfile = SD.open(filename, FILE_WRITE);
  if( ! logfile ) {
    Serial.print("Couldnt create ");
    Serial.println(filename);
    error(3);
  }
  Serial.print("Writing to ");
  Serial.println(filename);

  pinMode(13, OUTPUT);
  pinMode(8, OUTPUT);
  Serial.println("Ready!");
}

uint8_t i=0;
void loop() {
  digitalWrite(8, HIGH);
  logfile.print("A0 = "); logfile.println(analogRead(0));
  logfile.flush();
  Serial.print("A0 = "); Serial.println(analogRead(0));
  digitalWrite(8, LOW);
 
  delay(100);
}


It adds a wait loop so it will only start when the Serial Monitor is opened. You'd want to remove that for actual remote usage since it wouldn't run any code without a Serial Monitor attached. But for troubleshooting from your PC, it's helpful. It also saves the analogRead value to a variable so the logfile and Serial Monitor values will be the same. With that sketched loaded, open Serial Monitor and get:
Screenshot from 2021-05-10 18-56-39.png
Screenshot from 2021-05-10 18-56-39.png (25.21 KiB) Viewed 43 times


It's showing ANALOG01.TXT as the filename since ANALOG00.TXT was from my first attempt without logfile.flush().

Let that sketch run for a few seconds. Remove power from Feather M0 Adalogger. Remove SD card and put in reader attached to PC USB. Then open the ANALOG01.TXT file in a text editor and get:
Code: Select all | TOGGLE FULL SIZE
A0 = 586
A0 = 550
A0 = 518
A0 = 497
A0 = 493
A0 = 479
A0 = 478
A0 = 502
A0 = 496
A0 = 482
A0 = 481
A0 = 496
A0 = 502
A0 = 465
A0 = 475
A0 = 498
A0 = 478
A0 = 475
A0 = 474
A0 = 477
A0 = 484
A0 = 471
A0 = 481
A0 = 500
A0 = 497
A0 = 480
A0 = 486
A0 = 483
A0 = 487
A0 = 475
A0 = 480
A0 = 499
A0 = 500
A0 = 493
A0 = 482
A0 = 500
A0 = 506
A0 = 491
A0 = 481
A0 = 493
A0 = 500
A0 = 489
A0 = 479
A0 = 491
A0 = 499
A0 = 478
A0 = 487
A0 = 501
A0 = 497
A0 = 483
A0 = 480
A0 = 502
A0 = 505
A0 = 495
A0 = 475
A0 = 488
A0 = 508
A0 = 497
A0 = 477
A0 = 491
A0 = 497
A0 = 502
A0 = 470


So it generally seems to work. Maybe try running the sketch above and see if you can reproduce what I got.

adafruit_support_carter
 
Posts: 20281
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather Adalogger not saving data and other issues

by mkline93 on Wed May 12, 2021 10:48 pm

Yes, it works. No, it didn't resolve the issue of having different values. I see the "while" loop you added to wait for the monitor, but I'm not seeing any other changes to the code after that. I went ahead and wrote the variable and the count loop in (see code below).
I'm entirely unclear on why the raw sample written to the card and the immediately following raw sample written to the monitor are different. It's literally only one or two lines of code later. When you don't use the monitor, the raw data appears to be correct (per matching the results of the following code). Possibly the board EMF that is being picked up on A0, around 1.1 volts, just enough to make it have a semi consistent value?

Code: Select all | TOGGLE FULL SIZE
    #include <SPI.h>
    #include <SD.h>

    // Set the pins used
    #define cardSelect 4

    File logfile;

    // blink out an error code
    void error(uint8_t errno) {
      while(1) {
        uint8_t i;
        for (i=0; i<errno; i++) {
          digitalWrite(13, HIGH);
          delay(100);
          digitalWrite(13, LOW);
          delay(100);
        }
        for (i=errno; i<10; i++) {
          delay(200);
        }
      }
    }

    // This line is not needed if you have Adafruit SAMD board package 1.6.2+
    //   #define Serial SerialUSB

    void setup() {
      // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
      // also spit it out
      Serial.begin(115200);
      while (!Serial) delay(10);
      Serial.println("\r\nAnalog logger test");
      pinMode(13, OUTPUT);


      // see if the card is present and can be initialized:
      if (!SD.begin(cardSelect)) {
        Serial.println("Card init. failed!");
        error(2);
      }
      char filename[15];
      strcpy(filename, "/ANALOG00.TXT");
      for (uint8_t i = 0; i < 100; i++) {
        filename[7] = '0' + i/10;
        filename[8] = '0' + i%10;
        // create if does not exist, do not open existing, write, sync after write
        if (! SD.exists(filename)) {
          break;
        }
      }

      logfile = SD.open(filename, FILE_WRITE);
      if( ! logfile ) {
        Serial.print("Couldnt create ");
        Serial.println(filename);
        error(3);
      }
      Serial.print("Writing to ");
      Serial.println(filename);

      pinMode(13, OUTPUT);
      pinMode(8, OUTPUT);
      Serial.println("Ready!");
    }

    uint8_t i=0;
    int value = 0;
    int count = 0;
    void loop() {
      digitalWrite(8, HIGH);
      value = analogRead(0);
      logfile.print("A0 = "); logfile.println(value);
      Serial.print("A0 = "); Serial.println(value);
      digitalWrite(8, LOW);
      count++;
      if(count == 50){
        logfile.flush();
        count = 0;
      }
     
      delay(100);
    }



After that, they come out as the same values, and saved from the buffer into the card in chunks of 50.
So it appears that the code in the tutorial needs to be updated to reflect what the walk through says the code does. Either a few lines of code went missing or the libraries changed and don't act the same since it was written. On the topic of updating the tutorial... someone should probably put it through a spellcheck.

In the end, I just found out while doing some research that this was almost going to be a moot point in my particular use-case, as the reading capabilities only goes up to working voltage @ 3.3 volts. I almost got to the point of hooking this thing up and trying to force feed it between 13.2 and 14.75 volts- "...and that would end your trip real quick, wouldn't it?". This particular limit is pretty buried, down in the pin out section, rather than in the specs listed on the main page.
So now that I have it already, I'm looking at a logic level shifter to get from the higher voltages mentioned down to 3.3 volts. Not sure how much this is going to affect the accuracy or the latency from one end to the other. Might end up floating values or dropping data points (or just getting trash) until i get it dialed in on the sample rate to match the max shifter response time. But the whole thing should be able to handle 10Hz, maybe 15 or 20 if I get real interested in what the voltage is doing. But accuracy is going to be a pretty big issue if it's not right.

Thanks for the help.

mkline93
 
Posts: 6
Joined: Tue Dec 01, 2020 7:37 pm

Re: Feather Adalogger not saving data and other issues

by adafruit_support_carter on Thu May 13, 2021 11:20 am

Possibly the board EMF that is being picked up on A0, around 1.1 volts, just enough to make it have a semi consistent value?

Something like that or even just the ADC itself. ADCs aren't perfect and can have their own noise. So it's entirely possible that two back-to-back reads of the ADC will be slightly different.

So now that I have it already, I'm looking at a logic level shifter to get from the higher voltages mentioned down to 3.3 volts.

Maybe also consider a voltage divider?

adafruit_support_carter
 
Posts: 20281
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.