Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, a web toolkit designed to help citizens, conservation practitioners, municipal decision-makers, researchers, educators, and students advance knowledge and stewardship of fresh water. New to EnviroDIY? Start here

4. Preparing the Mayfly Data Logger

Print this page

View the EnviroDIY Monitoring Station Parts List

4.1 Installing Arduino IDE

  1. Use the free Arduino IDE programming software to program the Mayfly Data Logger. Install the IDE before connecting the Mayfly data logger to your computer. Download the latest version from Arduino.cc at https://www.arduino.cc/en/Main/Software.  If you already have the IDE installed on your computer, ensure that you are using version 1.8.12 or newer.
    1. NOTE: Windows users may not be able to install this software without administrative privileges.
  2. Once the Arduino IDE is installed, you will need to add the Mayfly board to the list of available boards. To do this, start the Arduino software, then click on the “File” menu, then “Preferences” and paste the following URL into the box labeled “Additional Boards Manager URLs”:
    https://raw.githubusercontent.com/EnviroDIY/Arduino_boards/master/package_EnviroDIY_index.json
  3. In the IDE, click on Tools > Board > Boards Manager. Use the dropdown box to select “Contributed.” You should then see an option for “EnviroDIY ATmega Boards.” Click the Install button to add the EnviroDIY boards to your IDE.
  4. Now when you click Tools > Board you will see the EnviroDIY Mayfly 1284P listed either at the top or bottom of your list of available boards. So select that and the IDE will be configured to program the Mayfly Data Logger.

4.2 Connecting a Computer to the Mayfly Data Logger

  1. Plug a USB-C cable into the Mayfly Data Logger, then plug other end of the cable into a free USB port on your computer (Figure 3.1.1).
  2. Turn the Mayfly power switch to the on position. If this is the first time your board has been connected to your computer, wait while the computer recognizes the board and assigns it a COM port number.  You might have to allow your operating system to install additional serial port drivers.
  3. To select the COM port, open the Arduino IDE. Select the COM port assigned to your Mayfly by selecting Tools > Port > COM2. (or COM3, COM4, etc)
  4. If no COM ports are available, then your computer either doesn’t “recognize” the Mayfly, meaning that additional drivers need to be installed, or the computer doesn’t “see” the Mayfly because the board isn’t turned on, or you have a defective cable, or some other electronic issue.
  5. In the Arduino IDE, open the serial monitor (button in upper right corner of Arduino window or via Tools > Serial Monitor). At the lower right of serial monitor window set the baud rate to 57600. All of the Mayfly boards have been preprogrammed with a sample sketch. This sketch instructs the Mayfly to blink the LEDs and also take some onboard sensor readings and report it to the PC through the Serial Monitor. You should now see that data printed on the Serial Monitor every few seconds.

4.3 Installing Libraries

Preparing sketches for programming the Mayfly Data Logger is simplified by the use of libraries: packages of functions that serve as shortcuts when writing sketches. A set of many helpful libraries has been compiled at github.com/envirodiy/libraries. Not all of these libraries are required, but many of them will be needed for programming an EnviroDIY Monitoring Station to send data to the online data portal (MonitorMyWatershed.org). To download all of the libraries together:

  1. Go to github.com/envirodiy/libraries.
  2. Scroll down to the ReadMe.
  3. Follow the instructions carefully in that section for installing the recommended EnviroDIY libraries.zip file and adding it to your Arduino IDE.

4.4 Creating and Uploading Sketches

View the EnviroDIY Monitoring Station Parts List

Once the required libraries are installed in the previous step, the Mayfly Data Logger must then be programmed with a “sketch” telling it what to do before it will work as a data logger. The Arduino IDE allows you to write sketches and then compiles them and sends (uploads) them to the data logger board when complete. There are dozens of tutorials online that demonstrate how to use the IDE, often using a “blink” or similar sketch. Arduino’s short guide to their IDE is available at https://www.arduino.cc/en/Guide/Environment. The Mayfly board has different pin numbers for LEDs and other parts so generic Arduino board sketches may not work with the Mayfly board without certain modifications.

Another important thing to remember is that the Mayfly board (like all Arduino boards) can only remember one sketch at a time. If you program it with a sketch and then later reprogram it with a new sketch, the Mayfly doesn’t remember anything from the first sketch. There’s also no way to “download” the existing sketch off a Mayfly board if it has already been programmed.

The first step in preparing the Mayfly Data Logger for use as a logger is to set its DS3231 real-time clock. Doing this requires installation of the DS3231 library, which is included in the required libraries as described above. Before setting the clock, slide a size CR1220 battery (available at most pharmacies and hardware stores or online) into the RTC battery holder. The “+” side of the battery goes up. (Usually the lettering is on the “+” side.) This battery will only power the memory of the clock chip and will allow the clock to keep time for several years, even if the rest of the board is unpowered.

Figure 4.4.1. Photo showing correct orientation of the CR1220 backup battery with the + side facing up

One sketch for setting the clock is one of the examples in the DS3231 library found at https://github.com/EnviroDIY/Sodaq_DS3231/tree/master/examples/PCsync. Follow the steps in the ReadMe section.  The PCsync sketch will set the time at GMT. There are alternative techniques that will allow different time zones.

The recommended approach to setting the clock on your mayfly data logger is found at the following link: https://github.com/EnviroDIY/Sodaq_DS3231/tree/master/examples/adjust.

Follow the steps in the ReadMe section that states, to synchronize the clock:

  1. Ensure that you have the Sodaq_DS3231 library installed in your IDE.
  2. Plug the Mayfly board into your computer and make sure it is visible to your system. You may have to wait for your OS to install additional hardware drivers. Select the correct COM port from the Tools menu. Open the Arduino IDE’s Serial Monitor and select the correct baud rate (usually 57600).
  3. Open the adjust.ino sketch in your IDE. Scroll to line 11. Modify the text in line 11 to be a date and time about 2 minutes in the future. Note: you should program the clock in UTC time and not local time if you will be using the recommended sketched that transmit data to MonitorMyWatershed because they are expecting the time from the Mayfly to be in UTC. Also note that in the sketch, the days of the week start counting at 0, so Sunday is day 0, Monday is day 1, etc. Upload the sketch to your Mayfly. You should now see the date and time being printed to the Serial Monitor every second, and it started counting from that future timestamp you entered in the sketch. Every time you restart the Mayfly board, it will reset the onboard RTC with that same time. We set it in the future to give us a little time to find the right time and get ready for the synchronizing procedure. Keep the Serial Monitor open throughout this entire process. Anytime you close it and re-open the Serial Monitor, it will restart the board and thus restart the clock.
  4. Open http://www.time.gov/ in a web browser or look at another clock (like a cell phone) displaying the correct time. The time.gov website has a handy UTC clock displayed in the upper righthand corner of that page. When the current time on your phone or the website is about 2 seconds before the the time that you entered in the sketch, hit the tiny RESET button on the Mayfly board. This will restart the sketch and also restart the Mayfly’s RTC with the correct time.
  5. The time being printed to the Serial Monitor every second should match your phone and the time.gov website. If it doesn’t, you may need to repeat steps 3 and 4 several times to get the time right. It’s okay if it’s a few seconds off, the goal is to get the RTC time fairly close to the actual time.
  6. Important: you must program a different sketch onto the Mayfly now before proceeding, otherwise the RTC will be reset again to the time listed in line 11 anytime the Mayfly is reset or restarted or if you close and re-open the Serial Monitor. We recommend using the now.ino sample sketch from that same DS3231 library because it will print the date and time to the screen every second, which will help verify that your clock was set correctly with the adjust.ino sketch.

Was this article helpful?

Can’t Find the Answer?

If you’ve searched the knowledge base and still need help, please post on the forum.
Go to the Forum