• 0
Vinay

Analog.read error

Question

Hello,

 

I need to measure voltages at 2 points on a circuit for calculating temperatures using RTD's. For this I have used UNO board and connected pins 0,1,2,3 to the different points on the circuit (pin 0 to source and pin 3 to ground). From multimeter, I got voltage readings as V0: 4.9V, V1:3.2V, V2:1.5V and V3:0V. I got the readings from the UNO board as 1023, 659, 293 and 0 respectively. 

But when I add an analog shield on the UNO to increase the accuracy I was not getting proper readings from it. Analog shield is returning the readings as  45934, 45976, 46055 and 45921 for the voltages 4.9V, 3.2V, 1.5V and 0V respectively. Following is the code I was using to get the readings from the analog shield.

 

#include <analogShield.h>

void getTemp (float *t) 
{
unsigned int V0,V1,V2,V3;

V0 = analog.read(0);
V1 = analog.read(1);
V2 = analog.read(2);
V3 = analog.read(3);

t[0] = V0; t[1] = V1; t[2] = V2; t[3] = V3;
return ;
}

void setup()
{
  analogReference(DEFAULT);
  Serial.begin(9600);  
}
void loop()
{
  float temp[4];
  getTemp(temp);
 Serial.print(temp[0]); Serial.print(" V0      ");
 Serial.print(temp[1]); Serial.print(" V1      ");
 Serial.print(temp[2]); Serial.print(" V2      ");
 Serial.print(temp[3]); Serial.print(" V3      ");
 Serial.println(); 
 delay(200);
 return;
}

My question is why the sheild is returning a lower value for 4.9V than that of 3.2V. Also it need to return a value of 32768 for 0V (I guess).  Is there any error in code.

 

Thanks.

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hi @Vinay,

I had some issues with my powered usb hub so i just got to your code working on a uC32 and an Analog shield. Unfortunately I won't be able to work further on it until Monday.

thank you,

Jon

Share this post


Link to post
Share on other sites
  • 0

Hi @Vinay,

I am using a uC32 with the Arduino IDE 1.8.1 and the digilent core here. I used you code for the most part. I had to change one of your variable types to int otherwise the code would not run. Giving the voltage on the ADC of the analogshield as follow:  A0- 4.9V , A1 - 3.3V , A2 - 1.5V ,  A3 - 0V. The digital output for A0 6400, A1 53900, A2 42150 and A3 32500. I was not able to reproduce the output you had with voltages being given to the ADC. I attached the code i was running with the one change as well as one screen shot of the digital output with the voltages given above and one screen shot with nothing connected which the output is similar to what you were seeing. Please try running the changed code. What are you using to produce the different voltages? Have you tried the Passthrough demo? What were the results?

cheers,

Jon

 

Analogshield_test.txt

Analogshield_test_1.jpg

Analogshield_test_2.jpg

Share this post


Link to post
Share on other sites
  • 0

Hello Jon,

 

Thanks for your help. I am using a circuit which have two thermistors(10K ohms @25 degC) and a resistor(10K ohms) in series to get the voltages as mentioned in my post.

 

When I use your code (variable type as int), I was getting all negative values as shown in the attached file.

 

When I use my previous code (variable type as float), I was getting values around 45000 as mentioned in my post.

 

I have tried passthrough demo. I have changed the input from 0 to 3 and checked the voltage on the output-0 in all cases (input as 0,1,2,3 and output as 0). I was getting the voltages as 4.9V in all cases.

 

Am I missing anything in the coding part or can it be an issue with my hardware.

 

Serial monitor with variable type as float:

Serial plotter with float type.JPG

 

Serial monitor with variable type as int:

Serial plotter with int type.JPG

Edited by Vinay

Share this post


Link to post
Share on other sites
  • 0

Hi @Vinay,

I have attached a picture of my setup with your project(with changes to int) as well as the passthrough demo. I also have screen shots of my setting on our waveforms program that runs our EE board where i generated the different voltages as well as the sine wave and o-scope for the passthrough. Could you attach a picture of your set up as well as your readings from test equipment if you have the ability. Also just to confirm you are using an Arduino UNO. What rev of Arduino UNO are you using? What version of Arduino IDE are you using.  Do you have the ability of using a power supply?

cheers,

Jon

Analogshield_test_3.jpg

Analogshield_test_4.jpg

20170419_130252.jpg

20170419_133309.zip

Analogshield_test_5.jpg

Analogshield_test_6.jpg

Edited by jpeyron

Share this post


Link to post
Share on other sites
  • 0

Hello Jon,

 

 

Thanks for your help. I have been using wrong ADC header all the time. I got to know my mistake after seeing your setup pictures. Now my code works fine.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now