Conflict between SD card and Accelerometer interface?

jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
There seems to be a conflict preventing me from opening a file and writing to it. I'm on a TinyZero but this might apply to all?

I can do it with just the SPI.h  and SD.h loaded, but when I add Wire.h and BMA250.h and the sensor reading code to the program it fails to open my data file for writing. I've copied the working code from the first case to the non-working second case, and put in a serial print statement to confirm my program's getting to the proper point where it tries to write to the card using the same pasted code that works without the Wire and BMA250 code for the sensor.

I found a couple posts related to a conflict like this with a display board, but nothing else.

Any clues would be appreciated.

Below are the header lines from the non-working program. Without the first two lines here, things are fine as discussed above.

#include <Wire.h>         // For I2C communication with sensor
#include "BMA250.h"       // For interfacing with the accel. sensor
#include <SPI.h>          // may not actually need this one
#include <SD.h>           // For SD card


const int chipSelect = 10;   // for TinyZero
« Last Edit: October 31, 2019, 10:41:25 AM by jlastofka »


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
Hello,

I'm not sure what issue you're running into with compatibility! There is a helpful matrix that shows the usability of TinyShields with each other if that would be helpful for future projects: https://learn.tinycircuits.com/TinyDuino_Overview/#tinyshield-compatibility

As for the current issue of the SD Card TinyShild and Accelerometer TinyShield, there is a Fitness Tracker program that uses both of those boards successfully. It may help to review the code included in that tutorial: https://tinycircuits.com/blogs/learn/custom-fitness-tracker

The smaller accelerometer board in this tutorial uses the same pins as the larger one, so it should work the same way with what you have.

Let me know if that helps!

Best,
Réna


jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
Thanks. I had looked at the compatibility matrix before I bought the hardware and it seemed OK. I looked at the code you linked and they're using SdFat.h instead of the SD.h I was using from another example I found from TinyCircuits.

I found SdFat.h and got that loaded and now it looks like I have to change some other spellings or calls so I'll look into that a bit. I'm hoping that there's something different in the SdFat.h used in that fitness tracker code that works around whatever's wrong (I think) with using SD.h I got from another TinyCircuits example listing.
« Last Edit: October 31, 2019, 11:29:50 AM by jlastofka »


jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
It looks like the file handling methods using SdFat.h in the fitness tracker example are fairly complicated compared to the simpler syntax using SD.h, or maybe that's just the programmer's style. I'm having a hard time digging out what I need to copy over to my program. Maybe there's a simpler example somewhere?


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
Hello,

I put together a little example using the Accelerometer TinyShield and the SD Card TinyShield. I am unsure what example you are using and put together, so I can't help you much further than writing something else. If you would like some more help, you can post the program you put together with comments detailing where the issue is you are encountering. Otherwise, the example I'm attaching compiles, uploads, and I am able to see Accelerometer output in the Serial Monitor.

Best,
Réna


jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
Thank you very much for helping on this. I loaded your example and I had to change the delay waiting for the serial port from 500 ms up to (I used) 3000 ms. I found that out before in something else I did that wasn't responding either. After that, your example runs, except it hangs on this line

root.ls(LS_R | LS_DATE | LS_SIZE);         and doesn't do anything.

I commented that out and the rest of it ran OK.
I'll now go in and try actually writing data to the SD card and I'll report back later.
Something up with that delay waiting for the port to respond....   
I set the baud to 9600 in the program by the way, so I don't have to change the monitor window every time I start it up.
Again, thank you for the response and help. It's a neat little product and a friend and I are using them to do some data acquisition during model rocket flights.


jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
So, this is where I'm failing now:

the code below works when I run it in a separate test program, but not when I add it to your example, or when I use it in my program that also uses the BMA250 files. I get the "error opening datalog.txt" message.

  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    SerialMonitor.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    SerialMonitor.println("error opening datalog.txt");
  }

I've attached my Datalogger.ino file that runs and writes to the card. It's a pretty simple listing. I just can't get it to work in my other program or in your example....


jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
Actually, instead of digging into my example to find what doesn't work, could you just add a couple lines to your example that writes a few numbers of text data to a .txt file on the card? If I saw a working idea, I'd probably be done:-)

On the other hand, it sure would be nice to know why my idea works by itself but not in combination with the accelerometer files.


jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
OK, I have it working now:-)

I used your example file and stripped out the parts about reading card types and directories, etc. I just want to write some text to a file.

I changed the SD startup command as shown below from your (now modified) file:

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!SD.begin(chipSelect)) {
    SerialMonitor.println("initialization failed. Things to check:");
   while (1);
  } else {
    SerialMonitor.println("Wiring is correct and a card is present.");
  }

And then to write text to the card I use:

  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    SerialMonitor.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    SerialMonitor.println("error opening datalog.txt");
  }

Plus I had to increase the delay waiting for the serial port to initialize. I used 3000 ms but didn't try anything shorter.

I'm attaching the modified file in case you want to poke through it and see what I hacked up:-)    I'll clean it out some more and put in a little more of my final needs, a step at a time in case I break something and need to adjust.

Thanks again for the help, tips, ideas....   and for getting me close enough to get things working. It's nice to see the company's paying attention and taking the time to help people along.


jlastofka

  • Full Member
  • ***
    • Posts: 18
    • View Profile
Well, it's finally all sorted out and working with my desired text outputs. In the end there was one more conflict as I loaded my original code back in. I had been using PIN 13 and the on-board LED for a blinking output before I had the SD card added into the system. Turns out that's a conflict with the SPI interface. I'll never forget that again:-)

That was likely my problem all along, but I'm sure I learned from going through this and from receiving the help.

Again, thanks for being attentive and supporting your customers. There are two of us out here doing about the same setup and we have a selection of your boards purchased already. Likely more to follow. They're really impressive little things.


 

SMF spam blocked by CleanTalk