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

Reply To: Looking for a bare-bones 16 bit 0-5V dc data logger sketch to build off of

Home Forums Mayfly Data Logger Looking for a bare-bones 16 bit 0-5V dc data logger sketch to build off of Reply To: Looking for a bare-bones 16 bit 0-5V dc data logger sketch to build off of

#1938
Shannon Hicks
Participant

The auxiliary A/D converter on the Mayfly is a ADS1115, so I prefer to use the Adafruit library for interacting with it (https://github.com/adafruit/Adafruit_ADS1X15). It uses the I2C port with the default address of 0x48. If you want to add other external ADS1x15 chips, just set the address on any additional chips to 0x49, 0x4A, or 0x4B.

See the library examples for how to do single-ended or differential measurements. You can also adjust the gain or sampling frequency, but I usually use the default gain of 2/3, like in the example that Sara quoted above, which is why there’s a formula for converting bits into millivolts. At the default gain, the Mayfly’s aux ADC is 1 bit = 0.1875mV.

Keep in mind that because the Mayfly operates at a Vcc of 3.3v, you can’t safely measure any voltage higher than 3.3v or you will damage the ADC. The Mayfly has a set of small jumper pins next to the Grove connectors for choosing either 3.3v or 5v is on the “V” pin of the Grove connector (see the second half of this page: http://envirodiy.org/mayfly/hardware/jumper-settings/). We did this because we typically use the Mayfly with sensors that require 5v for excitation, but only output a signal from 0-2.5v, so we’re not at risk of over-voltage on the measured signal pin. So if you’re connecting a sensor with 0-5v output, you’re going to need to scale the output by 2/3 to protect the Mayfly’s ADC.

As I mentioned in this thread (http://envirodiy.org/topic/datalogging-cyclops-rhodamine-wt-sensor/), there are at least 2 ways to measure 0-5v analog signals with your Mayfly:

As for measuring the output of the sensor, there are a couple different options. One would be to put the sensor output across a resistor divider that drops the 5v to 3.3v (i.e. a 10k and 20k resistor in series across the sensor output, so when the sensor outputs a max of 5v, the voltage between the two resistors is 2/3 of that, which is 3.3v). Or you could add a separate ADC board (like the Adafruit ADS1115 breakout board). Power the breakout board from the 5v switched output of the Mayfly and then it will be able to handle a max input of 5v. But you’d need to connect the breakout to the I2C port of the Mayfly, so you’d need to add some digital level-shifting on those 2 I2C lines to protect the Mayfly from higher voltage of the breakout. I’m sure there are a few other methods, but those are the two quickest and easiest.