Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

Recording data from pressure sensors on an SD card

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

Viewing 12 reply threads
  • Author
    Posts
    • #2188
      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
        Anthony Aufdenkampe
        Participant

          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
          Sara Damiano
          Moderator

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

          • #2192
            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
              MillerG
              Participant
              • #2195
                Shannon Hicks
                Moderator

                  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
                  Anthony Aufdenkampe
                  Participant

                    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
                    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
                      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
                        Shannon Hicks
                        Moderator

                          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
                          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
                            hank
                            Participant

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

                              logData(dataRec);

                            • #2222
                              MillerG
                              Participant

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

                            Viewing 12 reply threads
                            • You must be logged in to reply to this topic.