analogReference(INTERNAL) error

I'm trying to use the internal 1.1 volt analog reference with my Mega2560 board.

This code:
void setup() {
pinMode(Sensor, OUTPUT); // set pin to drive sensor
// analog pins are always inputs
Serial.begin(9600); // open serial port
analogReference(INTERNAL); // sets AREF to 1.1v

Causes this error:
Test590.cpp: In function 'void setup()':
Test590:11: error: 'INTERNAL' was not declared in this scope

I have tried it with 'INTERNAL1v1' and 'INTERNAL2v56' and get the same error.

He'p me! Oh, please he'p me!

Hunting down that word in the include files I found this:

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define INTERNAL1V1 2
#define INTERNAL2V56 3
#else
#define INTERNAL 3
#endif

Looks like you want INTERNAL1V1 not just INTERNAL.

I have tried it with 'INTERNAL1v1' and 'INTERNAL2v56' and get the same error.

You were on the right track, however as they say, C is case sensitive, so try it with a big V.

INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)

Lefty

Thanks, guys. It was the lower case "v". One of the references I was using just had "INTERNAL" and the other was "INTERNAL1v1" - docs don't have to run, I guess :stuck_out_tongue:

While I'm on it AMTEL's spec sheet "ATmega640/1280/1281/2560/2561" says that it is possible to use some of the analog inputs to take differential readings. This would be ideal for my app but I don't see it in the programming docs. Any ideas?

I'm very new to Arduino - but I'm startin' to like it!

artk13:
While I'm on it AMTEL's spec sheet "ATmega640/1280/1281/2560/2561" says that it is possible to use some of the analog inputs to take differential readings. This would be ideal for my app but I don't see it in the programming docs. Any ideas?

You set ADMUX (ADC Multiplexer Selection Register) and ADCSRB (ADC Control and Status Register B) to select which combination of A/D inputs are selected and what gain to apply (1, 10, or 200).

See Table 26-4 of the datasheet for the choices.

The table seems quite wonky; there are many options shown where the Positive Differential Input and Negative Differential Input are the same pin! Wouldn't that always result in a reading of zero?

Table 25-4?

Yes it seems strange. Perhaps you override the pin with the internal reference using one of the other registers? Then it could make sense.

Thanks, I'll study that. If I figger anything out I'll post here. I'd say if you connect two signals to the same pin there might be damage somewhere ! ?