Recording data from pressure sensors on an SD card

Home Forums Mayfly Data Logger Recording data from pressure sensors on an SD card

This topic contains 12 replies, has 5 voices, and was last updated by Profile photo of MillerG MillerG 3 months, 1 week ago.

  • Author
    Posts
  • #2188
    Profile photo of MillerG
    MillerG
    Participant

    Hello,

    I have a Mayfly data logger and am looking for some advice on how to log data from 2 pressure sensors onto an SD card. I am a novice in the data logger community so please, bear with me.

    I have a Sparkfun MS5803-14BA Breakout aqueous pressure sensor and an Adafruit MPL115A2 I2C Barometric pressure sensor. I am looking to get the data recorded by these sensors onto an SD card, along with the time at which the data was recorded. I have codes for the both sensors as well as the time. The codes are all running very well and are putting out data through the serial monitor in Arduino IDE. Any assistance on how to get this data to record to the SD card would be much appreciated!

  • #2189

    MillerG, thanks for posting your question here!

    In the meanwhile, have you successfully run the “Simple File Example” sketch? It’s here: https://envirodiy.org/mayfly/software/simple-file/; and also on GitHub here: https://github.com/EnviroDIY/EnviroDIY_Mayfly_Logger/tree/master/examples.

    Last, if you are using an SD card that is larger than about 4 GB, you’ll probably need to use a newer Arduino SD library that we are now using: https://github.com/greiman/SdFat. This library can handle SDHC cards with up to 32 GB of capacity. So, if you can’t get our “Simple File Example” to work, then download and put this SdFat folder in your ~/Documents/Arduino/Libraries directory. Then you should be able to replace

    with this code to your “Simple File Example” or any other sketch:

    Let us know if you are successful with any of this.
    If that works then try to merge the code in the “Simple File Example” with the code that you have working for your sensor.

    If you still need help. It would be great if you could post your code, using the “Add Code Snippet” button at the top of the forum post editor, or by attaching files to your post via the button at the bottom of the forum post editor.

    Last, we’re working on an easy to use ModularSensors library (https://github.com/EnviroDIY/ModularSensors) that will integrate SD logging, radio communication, solar-charing and sleep functions for a set of preselected sensors. Unfortunately your sensor is not on that list at this time, but we could consider adding it in the future (or you could help us)!

  • #2190
    Profile photo of Sara Damiano
    Sara Damiano
    Participant

    If you would like your sensors added to the ModularSensors library, please create an issue for them there!

  • #2192
    Profile photo of MillerG
    MillerG
    Participant

    Anthony,

    I have run that Sample Code but do not have success when I try to merge it in with my code.

    This is my current code:

  • #2193
    Profile photo of MillerG
    MillerG
    Participant
  • #2195
    Profile photo of Shannon Hicks
    Shannon Hicks
    Keymaster

    The first couple things that stand out are this:

    You don’t have to say “Serial.begin(9600)” more than once in your sketch. Just do it once near the beginning of your setup() function and that’s it.

    You don’t have to set the date and time of the RTC every time you run the sketch. The way it is written in your examples means that the clock gets programmed with that prewritten date/time every time the board boots up, which is definitely not something you ever want to do. If you’re using a Mayfly (or any real-time-clock) module with a battery backup (the little silver watch-battery), then your RTC will remember the correct date and time for many years, so you only need to set that time once using a standalone sketch like the “Adjust” example sketch with the SODAQ_DS3231 library. Once the clock is set, you can remove all of the lines in your logger sketches that were essentially re-setting it each time. So in the above sketch, remove lines 11, 16, and 41.

    I’ll see if I can add the code for SD functionality to the second sketch you posted and attempt to compile it on my computer.

  • #2206

    MillerG, can you paste in the error codes you get with your first sketch?
    Also, I reformatted your first sketch so that it would render better, but I’m slightly worried that I may have messed something up when I did it. Can you confirm that the first sketch is correctly rendered? Thanks!

  • #2210
    Profile photo of MillerG
    MillerG
    Participant

    I don’t get an error code from the sketch. The sketch will upload and show data in the serial monitor. But, it will not log the data onto an SD card, which is my goal.

  • #2211
    Profile photo of MillerG
    MillerG
    Participant

    Anthony,

    The first code complied just fine. I will try and upload it to the Mayfly later and let you know how it goes. Thanks!

  • #2212
    Profile photo of Shannon Hicks
    Shannon Hicks
    Keymaster

    Something I’m not seeing in your first sketch is where you declare what chipselect pin for the SD card. On the Mayfly it’s 12, so on line 42, change the “SS” to “12”. Then remove all the extra Serial.begin(9600) statements so there’s only one at the beginning of the setup function. And remove the RTC stuff on lines 11, 16, and 41. See if that will write the data to your card.

  • #2220
    Profile photo of MillerG
    MillerG
    Participant

    This is our current sketch. It will produce the data into the serial monitor. It will also record the header to the SD but not any of the readings from the sensors. Can anybody see any errors in the sketch or know why we can record the header but not the readings?

    Thanks

  • #2221
    Profile photo of hank
    hank
    Participant

    in your main loop function, somewhere in lines 44-47 you need to call:

    logData(dataRec);

  • #2222
    Profile photo of MillerG
    MillerG
    Participant

    Thanks Hank! You’re right, that was all we needed.

You must be logged in to reply to this topic.