Home › Forums › Mayfly Data Logger › Mayfly 16 bit ADC errors › Reply To: Mayfly 16 bit ADC errors
I usually leave the ADS1115 in its default gain setting (which is 0.1875 mv per bit), which is more than sufficient for most measurements. If you do that, you can easily calculate voltage by using these two lines:
adc0 = ads.readADC_SingleEnded(0);
voltage = (adc0 * 3.3)/17585.0;
If you’re using a voltage divider, you’ll need to add an additional multiplier that is determined by the ratio if your two resistors, which is where I guess that 4.052 came from. Did you measure actual resistances of your two resistors, since tolerances can be anywhere from 1% to 20% depending on what resistor you’re using.
It also looks like you’re using 4.096 as the voltage reference of the ADS1115 in your equation on line 31, and that is incorrect. The absolute maximum reference voltage of the ADS1115 chip is 4.096v, but it is tied to the Vcc rail of the Mayfly, which is 3.3v, so you cannot measure anything higher than 3.3v with the Mayfly, and you need to use 3.3 as the multiplier in that equation.
Are you using the 6 AA battery pack to power your Mayfly? If so, it needs to be connected to the Ext 4-12v pins in the upper right corner of the board (near the FTDI header), and flip the small slide switch to EXT. You should never plug anything other than a 3.7v Lipo battery into the JST jacks labeled “LIPO BATT” because the onboard charger will attempt to charge the battery whenever a USB cable or solar panel is plugged into the Mayfly. So if you’re powering the Mayfly with alkaline batteries, it must be connected to the EXT 4-12 pins.
You can also measure whatever voltage source is powering your Mayfly by simply analog reading A6 which is connected through a voltage divider to the battery providing the power for the Mayfly. There’s an example sketch here: https://github.com/EnviroDIY/EnviroDIY_Mayfly_Logger/blob/master/examples/battery_measurement/battery_measurement.ino