Page 1 of 1

Increase decimal precision of 16 bit ADS1115 voltage Measurement While Plotting

Posted: Sat Nov 16, 2019 7:26 pm
by cheneyab
Hello,

I am currently trying to figure out how to send more data points after the decimal point for voltage measurements using the ADS1115 16-bit ADC. I looked at a few other forums on here that showed how to read and plot the values, but I am trying to figure out if the precision on the plot / raw data can be increased. Currently I can read up to 2 decimal places, i.e. 1.11, but I would like to read up to 8 for instance, i.e. 1.11111111. I am able to do this properly in Arduino, but I have not found a way to do this in MegunoLink. I have also included my code below.

Thank you for any help.



#include "MegunoLink.h"

// ADS1115 Test Code

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads(0x48); // Declare an instance of the ADS1115

int16_t rawADCvalue; // The is where we store the value we receive from the ADS1115

// Set scale factor for voltage based on Gain ratio
//float scalefactor = 0.1875/1000; // This is the scale factor for the 2/3x gain +/- 6.144V 1 bit = 0.1875mV (default)
float scalefactor = 0.125/1000; // This is the scale factor for the 1x gain +/- 4.096V 1 bit = 0.125mV
//float scalefactor = 0.0625/1000; // This is the scale factor for the 2x gain +/- 2.048V 1 bit = 0.0625mV
//float scalefactor = 0.03125/1000; // This is the scale factor for the 4x gain +/- 1.024V 1 bit = 0.03125mV
//float scalefactor = 0.015625/1000; // This is the scale factor for the 8x gain +/- 0.512V 1 bit = 0.015625mV
//float scalefactor = 0.007812/1000; // This is the scale factor for the 16x gain +/- 0.256V 1 bit = 0.0078125mV

float InVol, OutVol; // The result of applying the scale factor to the raw value

TimePlot MyPlot; //no channel selected

void setup()
{
Serial.begin(9600);


// Gain for 16 bit ADC
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 0.1875mV (default)
ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.0078125mV
ads.begin();

MyPlot.SetTitle("Plot Measured Voltage");
MyPlot.SetXlabel("Time");
MyPlot.SetYlabel("Voltage ");

// Set the plotting parameters. "Input Voltage" = series name, Plot::Blue = line colour
// 2 = line width, Plot::Square = marker style
MyPlot.SetSeriesProperties("Input Voltage", Plot::Blue, Plot::Solid, 2, Plot::NoMarker);
MyPlot.SetSeriesProperties("Measured Voltage", Plot::Red, Plot::Solid, 2, Plot::NoMarker);

// Colours include
// Red, Green, Blue, Yellow, Black, Magenta, Cyan, White

// Markers include
// Square, Diamond, Triangle, Circle, Cross, Plus, Star, DownwardTriangle, NoMarker

// Line style
// Solid, Dashed, Dotted, DashDot, DashDotDot
}


void loop()
{
rawADCvalue = float(ads.readADC_Differential_0_1());
float OutVol = (float(rawADCvalue) * float(scalefactor))/3;
float InVol = 1.2*float(OutVol);

//Send Data To MegunoLink Pro
MyPlot.SendData(F("Input Voltage"),InVol); // Sinewave = series name, dY = data to plot
MyPlot.SendData(F("Measured Voltage"),OutVol); // By wrapping strings in F("") we can save ram by storing strings in program memory

// Serial.print("Raw ADC Value = ");
// Serial.print(rawADCvalue);
Serial.print("\tVoltage Measured = ");
Serial.println(OutVol,8);
Serial.println();

//delay(10);
}

Re: Increase decimal precision of 16 bit ADS1115 voltage Measurement While Plotting

Posted: Sun Nov 17, 2019 3:49 am
by philr
Hi, I think you can use
MyPlot.SendFloatData("SeriesName",Value,NumberOfDecimalPlaces)
so
MyPlot.SendFloatData("data",56.7543366,5);
will send 56.75434

Hope this helps. If you look at this page
https://github.com/Megunolink/MLP/blob/ ... mePlot.cpp

It shows you all the functions in the TimePlot library file. Its a great way to see if there is any extra functionality on top of the standard documentation and examples.

Cheers
Phil

Re: Increase decimal precision of 16 bit ADS1115 voltage Measurement While Plotting

Posted: Sun Nov 17, 2019 6:33 pm
by cheneyab
Thank you for the guidance Phil. That worked and it was a simple fix. Thanks for the link for the GitHub also, it was very helpful.

Regards