Serial communication issue with 16 bit external ADC for arduino

Support forum for MegunoLink
Post Reply
skprabhala53
Posts: 11
Joined: Fri Mar 02, 2018 3:46 pm

Fri Mar 02, 2018 3:53 pm

Hi, I'm using Megunolink to test an XY plot of my arduino circuit data.

I've two analog measurements coming out of circuit captured by an external 16 bit ADC (ADS1115) (https://www.adafruit.com/product/1085). I've an Arduino UNo attached to the circuit. When I use the arduino's serial monitor, I can see readings of both measurements just fine. So I tried to plot a set of those using Megunolink interface XY plot.

For some reason, neither the 'XY plot' nor the 'Message monitor' visualizers is working with the 16 bit ADC. I say this because, I disconnected the 16 bit ADC and used arduino uno's inbuilt 8 bit ADC and your software works fine. I attached my code below.

Is this something related to your software libraries or compatibility issue. Please help me. I definitely need to use the 16 bit and if needed, a 24 bit ADCs in my project as I need greater resolutions for my analog measurements.

Thanks

program code:

#include "MegunoLink.h"
#include <Wire.h>
#include <Adafruit_ADS1015.h>
Adafruit_ADS1115 ads1115;

XYPlot MyPlot;

void setup()
{
Serial.begin(9600);
pinMode(9, OUTPUT); // PWM signal for measurement unit
pinMode(A0,INPUT); // Green push button

MyPlot.SetTitle("My Analog Measurement");
MyPlot.SetXlabel("Voltage(V)");
MyPlot.SetYlabel("Current(uA)");
MyPlot.SetSeriesProperties("Measurement", Plot::Magenta, Plot::Solid, 2, Plot::Square);
}

void loop()
{
int16_t adc0,adc1;
int Bstate = analogRead(A0);
analogWrite(9,0);

if (Bstate>100){

for(int i=0; i<=150; i+=5){ //i =255 for max 60.6 uA current input 127 for 30uA

analogWrite(9,i);
delay(500);

adc1 = ads1115.readADC_SingleEnded(1); //16 bit adc channel 1 value reading
adc0 = ads1115.readADC_SingleEnded(0); ////16 bit adc channel 0 value reading

delay(300);

float Voltage = adc0*0.000188; //ADC value to voltage conversion 188uV is a conversion factor for 16 bit adc
float Vi = adc1*0.000188; //ADC value to voltage conversion
float Current = Vi/0.09798; //V=IR using sense Resistor 97.98K and conversion

MyPlot.SendData("Measurement", Voltage, Current);
}
}
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Sat Mar 03, 2018 5:04 am

Hi, when you say not working. Can you describe in what way? It builds fine for me and seems to send messages.
I get
{XYPLOT|SET|title=My Analog Measurement}
{XYPLOT|SET|x-label=Voltage(V)}
{XYPLOT|SET|y-label=Current(uA)}
{XYPLOT|STYLE|Measurement:ms_2}
{XYPLOT|DATA|Measurement|2.82|47.97}
{XYPLOT|DATA|Measurement|2.82|47.97}

When I manually set adc1 to 25000, and adc2 to 15000.

What is it doing for you?

its also plotting fine. See the attached picture.

Cheers
Phil

Code is
#include "MegunoLink.h"
#include <Wire.h>
//#include <Adafruit_ADS1015.h>
//Adafruit_ADS1115 ads1115;

XYPlot MyPlot;

void setup()
{
Serial.begin(9600);
pinMode(9, OUTPUT); // PWM signal for measurement unit
pinMode(A0, INPUT); // Green push button

MyPlot.SetTitle("My Analog Measurement");
MyPlot.SetXlabel("Voltage(V)");
MyPlot.SetYlabel("Current(uA)");
MyPlot.SetSeriesProperties("Measurement", Plot::Magenta, Plot::Solid, 2, Plot::Square);
}

void loop()
{
int16_t adc0, adc1;
int Bstate = analogRead(A0);
analogWrite(9, 0);

if (Bstate > 100) {

for (int i = 0; i <= 150; i += 5) { //i =255 for max 60.6 uA current input 127 for 30uA

analogWrite(9, i);
delay(500);

adc1 = 25000;// ads1115.readADC_SingleEnded(1); //16 bit adc channel 1 value reading
adc0 = 15000;// ads1115.readADC_SingleEnded(0); ////16 bit adc channel 0 value reading

delay(300);

float Voltage = adc0*0.000188; //ADC value to voltage conversion 188uV is a conversion factor for 16 bit adc
float Vi = adc1*0.000188; //ADC value to voltage conversion
float Current = Vi / 0.09798; //V=IR using sense Resistor 97.98K and conversion

MyPlot.SendData("Measurement", Voltage, Current);
}
}
}
Attachments
x2scrap.png
x2scrap.png (116.42 KiB) Viewed 13288 times
skprabhala53
Posts: 11
Joined: Fri Mar 02, 2018 3:46 pm

Mon Mar 05, 2018 9:12 pm

Hi, So I tried your version of the code and I got the same graph as you. The values are accurate.

So I tried my old code again (using the 16 bit ADC and its library). The plotting didn't work. I'll try to explain the situation as clearly as possible.

I have an analog circuit that sources current to a resistor in micro amperes (range 0-30uA for 0-150 PWM value) (at rate of 1uA/sec). I'm using my Arduino Uno and a 16 bit ADC (ADS1115 mentioned before) to source the current in steps using PWM signalling. The ADS1115 is interfaced to UNO over I2C and it senses the voltage across this load resistor and also senses the current going through this resistor on a different channel (ADS1115 has 4 channels). The for() loop I have in the code is for stepping up the current with the PWM every time.

With just Arduino's serial monitor I can send 1 specific PWM value to the circuit and I receive the sensed voltage value and current value just fine. I can verify my serial monitor readings using a source meter just fine.

When I try to use the Megunolink to plot all these values in real time (about 30 pairs of Voltage and current measurements), The X-Y plot is getting stuck on 1 random value in the 1st second and is not plotting any other values. A graph is attached.

I used the same program and disconnected the 16 bit ADC and used Arduino Uno's onboard 8 bit adc and the Meg's XY plot works just fine.The readings have errors compared to the source meter but at least the plot is working. Since my measurement values are very sensitive and I need high resolutions, I need to use 16 bit adc or may be even a 24 bit ADC. It seems to me that 16 bit ADC "analog read commands" are not working with the Megunolink. Please let me know what you think.

I appreciate the support.

Thanks
Sai
Attachments
test.jpg
test.jpg (40.59 KiB) Viewed 13277 times
skprabhala53
Posts: 11
Joined: Fri Mar 02, 2018 3:46 pm

Mon Mar 05, 2018 9:28 pm

Here's a little more information. I've changed the code a little to send messages to the monitor instead of plotting (Still using the 16 bit ADC). The data from the Monitor visualizer is attached in a text file below. You can see the PWM step signal (the values 0,5,10 etc..it goes up to 150). The current value is supposed to start from 0 and increase in steps of 1 and go until 30 and the voltage should increase over time as well. Hope this helps.

{XYPLOT|SET|title=IV Measurement}
{XYPLOT|SET|x-label=Voltage(V)}
{XYPLOT|SET|y-label=Current(uA)}
{XYPLOT|STYLE|Measurement:ms_2}
0
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
5
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
10
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
15
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
20
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
25
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
30
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
35
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
40
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
45
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
50
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
55
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
60
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
65
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
70
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
75
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
80
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
85
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
90
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
95
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
100
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
105
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
110
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
115
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
120
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
125
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
130
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
135
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
140
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
145
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
150
{MESSAGE|DATA|Voltage: -0.00}
{MESSAGE|DATA|Current: -0.05}
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Mon Mar 05, 2018 9:56 pm

The code looks right. The only thing I can think of is a measurement problem. Maybe the adc chip needs more time between measurements or something. It sounded like you confirmed the adc numbers change when not in the automatic loop... Maybe the pwm delay isn't enough or something.

You can confirm megunolink is working by feeding in the i variable into your adc variables and making sure the 0 to 150 count plots properly. That confirms the plotting works then you just need to figure out what adc variables are not changing.

Let me know how you go
Phil
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Mon Mar 05, 2018 10:00 pm

Also worth checking are your types. You're using int16 which is signed so -32k to +64k. Do you expected a signed number from the adc chip? Might need to change to uint16_t. Also you might need to cast your calculation so it generates the right types.

Like
float Voltage = (float)adc0*(float)0.000188;
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Mon Mar 05, 2018 10:29 pm

Nope looks like the example uses int so it must be a signed result. I did notice that they have ads.begin(); or in your case ads1115.begin(); in their setup section which i dont see in your program.

Cheers
Phil
skprabhala53
Posts: 11
Joined: Fri Mar 02, 2018 3:46 pm

Tue Mar 06, 2018 2:59 pm

Hi Philip,

That was it. I wasn't using the ads1115.begin() command in my XY plotting program. I've initialized the 16 bit adc and it worked. I've attached a picture of my results.

Thanks for your help.
Attachments
test2.jpg
test2.jpg (45.6 KiB) Viewed 13264 times
Last edited by skprabhala53 on Wed Jun 23, 2021 1:24 am, edited 1 time in total.
philr
Posts: 446
Joined: Mon May 26, 2014 10:58 am

Tue Mar 06, 2018 7:31 pm

All good, sometimes you just need a fresh set of eyes.
Phil
Post Reply