(SOLVED)Yun Shield Analog port0 not reading correctly

Hello All,

I am trying to read dc voltage on analog0 pin and have a 1.6 volt battery connected to calibrate my sketch. I accumulate 100 reads on the port and calculate the mean. I am getting a mean of 465, but I should be getting around 328. This is based on 1.6*1024/5.

Any one know what I can do to correct this?

Thank you in advance, Murrah Boswell

otrcomm: I am trying to read dc voltage on analog0 pin and have a 1.6 volt battery connected to calibrate my sketch. I accumulate 100 reads on the port and calculate the mean. I am getting a mean of 465, but I should be getting around 328. This is based on 1.6*1024/5.

Any one know what I can do to correct this?

::::SNIP::::

@otrcomm, what's the actual voltage of you battery?

Jesse

Yun only outputs 4.48 volt at 5 v DC line.

http://forum.arduino.cc/index.php?topic=209836.msg1542386#msg1542386

1.6*1024/4.48=365 instead of 328.

To correct it

ATmega32U4 document

http://academy.cba.mit.edu/classes/embedded_programming/doc7766.pdf

Internal reference voltages of nominally 2.56V or AVCC are provided On-chip. The voltage reference may be externally decoupled at the AREF pin by a capacitor for better noise performance

Page 292

INTERNAL Reference=2.56 v

int analogPin = 3;    
int val = 0;          
void setup()
{
  Serial.begin(9600);          //  setup serial
  analogReference(INTERNAL);
}
void loop()
{
  val = analogRead(analogPin);    // read the input pin
  Serial.println(val);             // debug value
}

1.6*1024/2.56=640

http://arduino.cc/en/Reference/AnalogReference

http://arduino.cc/en/Reference/analogRead

@jesse

1.53 v

@sonnyyu

Thank you, I will go over the mit report and run some more tests with various capacitors.

Regards, Murrah Boswell

Hello All,

I am not sure what is going on with the analog reads. When I put a jumper from the 3.3v pin to the AREF pin and include a analogReference(EXTERNAL); statement in my sketch, I read 473 on A0 with my 1.5 V battery connected. This is basically the same that I am getting without the 3.3V jumper and no analogReference statement.

Does this mean that the Yun Shield is operating internally at 3.3V? If so, how can I correct this?

Thank you in advance,
Murrah Boswell

What is your battery voltage? Can you measure with multimeters?

473*3.3/1024=1.524 v match with 1.53 v

http://forum.arduino.cc/index.php?topic=209836.msg1542386#msg1542386

3 - Inaccuracy in sensors reading, because many analog sensors output a voltage that is proportional to the VCC supplied (for example the ACS715)

without use

analogReference(INTERNAL);

or

analogReference(EXTERNAL);

The reading will be Inaccuracy.

P.S. What is analogReference(INTERNAL) reading for same battery?

@sonnyyu

New battery reads 1.61 on voltmeter

As per http://forum.arduino.cc/index.php?topic=46785.0

analogReference(INTERNAL); raises error: ‘INTERNAL’ was not declared in this scope

I found in Arduino.h

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__$
#define INTERNAL1V1 2
#define INTERNAL2V56 3
#else
#define INTERNAL 3
#endif
#define DEFAULT 1
#define EXTERNAL 0
#endif

Very simple sketch to read analog0 where battery is connected. I use Console instead of Serial since I am on a Yun Shield:

#include <Console.h>
#include <Bridge.h>

#define INTERNAL 3
#define DEFAULT 1

int analogPin = 0;    
int val = 0;          
void setup()
{
  Bridge.begin();
  Console.begin();          //  setup console
  while(!Console) {}
  analogReference(INTERNAL);
}
void loop()
{
  val = analogRead(analogPin);    // read the input pin
  Console.println(val);             // debug value
}

With analogReference(INTERNAL); I get primarily 648s
and with analogReference(DEFAULT); I get primarily 476s

1.61*1024/4.48 = 368 so my readings are way off. Could this be a hardware issue with the Yun Shield?

Thank you for all your help,
Murrah Boswell

It seems like ADC is required minimum DEFAULT (VCC) voltage to operate correctly (stay at linear mode). To be sure post issue at Motorola/Atmel forum?

Now wait just a minute... You're using the Seeed Yun Shield, Not the Arduino Yun board, right?

The Yun Shield has NO analog inputs. The analog inputs you are talking about are on the Arduino (compatible?) board to which the Yun Shield is connected. Which EXACT board is this?

This doesn't sound like a Yun related problem at all. Does the analog port read properly when the shield is disconnected? If not, then it is either a problem with your Arduino processor board, or it's a problem with your code. If the analog port reads correctly without the shield, but reads wrong with the shield, then the shield is causing voltage problems or electrical noise. The first thing I would suspect is that it may be drawing too much power and dragging down the voltage of your processor board, thereby affecting the reference voltage.

But the big question to answer first is which processor board are you using with your Yun Shield?

Everything mentioned so far has been assuming you are using an actual Yun board which has an ATMega32U4 processor, and which has a low internal operating voltage. It's likely you are using a different processor, and it's just about certain it is running at a different voltage.

ShapeShifter: Now wait just a minute... You're using the Seeed Yun Shield, Not the Arduino Yun board, right? oltage. It's likely you are using a different processor, and it's just about certain it is running at a different voltage.

Correct! I am using Dragino Yun Shields integrated with Mega2560s. I had no idea that the Yun Shield has no analog inputs. So with the Yun Shield connected on analog12, which is on the Mega2560 board, the mean after 100 reads and analogReference(INTERNAL); is 648 and with analogReference(DEAFAULT); the mean is 478. These are relatively the same as reading A0 which is on the Yun Shield.

Now with just the Mega2560 with the same battery putting out 1.61V, on A12 and analogReference(INTERNAL); I get 662 and with analogReference(DEFAULT); I get 338 which is what I woul expect.

So Eurika, it appears that the shield is causing voltage problems.

Thank you very much for suggesting this experiment, I could not see the forest.

I will pass this information on to the Dragino folks to see what they can suggest.

Thank you again, Murrah Boswell

otrcomm: These are relatively the same as reading A0 which is on the Yun Shield.

Please don't think of A0 as being on the Yun Shield. It isn't. That whole "analog in" header connector has no connection whatsoever with anything on the Yun Shield. It is strictly a pass-through. So, even though you may have a wire connected to one of those analog pins on the Yun Shield, it is really just connected directly to the parent processor board. In fact, most of the header pins are simple straight pass-throughs that are not connected to anything on the shield.

How are you powering your Mega2560 board? Can the power supply provide enough current for the Mega256o board, the Yun Shield, and whatever else you have connected to it? With everything connected and the Yun Shield up and running, measure the voltage on the 5V pin. Is it correct? If it's low, it's probably not a problem with the Yun Shield, you just aren't supplying enough power. And if you see the voltage fluctuating, you can be pretty sure you aren't giving it enough power.

I am powering the Yun Shield through a 5V power supply connected to the Mega2560.

I only have 3.4V output at the 5V pin with everything connected. On another Yun Shield/Mega2560 Combination without anything connected, I get 4.9V out at the 5V pin.

I will check to see how I can supply more voltage.

Thank you again, Murrah Boswell

otrcomm: I will check to see how I can supply more voltage.

Not necessarily voltage, you need a supply that can provide more current. When you have everything combined, it is drawing too much current, and the supply can't keep up, so the voltage dips. That's why you're getting strange analog readings. When you take off the shield, there is enough current to just run the Mega2560 board, so now the voltages are correct and the analog readings are correct.

What are the ratings of the power supply, how many amps can it deliver?

@ShapeShifter

It was the power supply. I installed another power supply that puts out 9V 1500mA and I get 4.9V fromthe 5V pin on the Yun Shield and my sketch is returning a mean of 330 which is okay for my project.

I really do want to thank you and sonnyyu and jessemonroy650 for your help.

Thank you and regards, Murrah Boswell