SparkFun Forums 

Where electronics enthusiasts find answers.

Topics pertaining to the Arduino Core & software used with the Artemis module and Artemis development boards.
User avatar
By mysparkfun71451
#213396
I discovered a problem with the Arduino “analogRead()” function while running the “Example4_analogRead” code within the Arduino IDE 1.8.11 on a Redboard Artemis board. The example code is located within the “Examples\Artemis Examples” folder in the IDE. The problem I have found is that the following call to the function analogRead:
int myValue1 = analogRead(A3);
causes a subsequent call:
int internalTempAnalog = analogRead(ADC_INTERNAL_TEMP);
to produce an incorrect result. If I comment out the first call then the subsequent call produces a correct result. This only affects the ADC_INTERNAL_TEMP results. The call for the battery divider div3:
int div3 = analogRead(ADC_INTERNAL_VCC_DIV3);
is unaffected even though it precedes the call for the temperature results. I see the same problem for any of the ADC pin numbers A0 thru A5. If I substitute ADC_INTERNAL_TEMP for A3 in the first call the problem goes away. The problem occurs with or without an input to the A3 pin.
With the analogReadResolution set to 10 bits (problem occurs for other resolutions as well) and a 3.3V input present on A3 I get the following analog values:
A3 = 1023, Div3 = 571, internalTempAnalog = 160
With no input to A3 I get:
A3 = 164, Div3 = 571, internalTempAnalog = 41
With the call to A3 commented out I get (with or without an input to A3):
Div3 = 571, internalTempAnalog =514
The analog value of 1023 for A3, with 3.3V applied, translates to an input voltage of 2V (given an ADC reference voltage of 2V), which is expected because the ADC upper detection limit is 2V. The analog value of 164 could be anything because the pin is floating.
The analog value of 571 for div3 translates to a VCC voltage of 3.34V, which is correct.
The analog value of 514 for internalTempAnalog translates to an ambient temperature of 68 F, which is correct for my environment. The other analog values of 41 and 160 are incorrect.
User avatar
By mysparkfun71451
#213405
Paul,
You are right, that fixed the problem. It never occurred to me to check for an updated board package. Guess I'll have to make a habit of regularly checking this (it took less time than writing up my problem statement and posting it!).
Thanks,
Randy
User avatar
By algilman
#247327
I am having the same issue, but I also don't know how to update the board's firmware to the latest version.

Alternatively, is there a way to write code in the sketch to get the analogRead() function to work?
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum