Author Topic: Using Serial messes up ADC?  (Read 3768 times)

Ram

  • Newbie
  • *
  • Posts: 3
Using Serial messes up ADC?
« on: October 21, 2016, 05:48:14 am »
Hi:
Ran into a peculiar issue with my Digispark Pro (an original board). Pro's A8 and A11 pins are connected to GND. The code below prints zero as expected. if however the commented line is uncommented, the code prints something that is significantly nonzero. Waiting to see if analogRead needs 'settling' does not change anything, neither does adding delays after each analogRead. What am I doing wrong? (The Serial is meant to go to a Bluetooth device)
Thanks - Ram

#include "DigiKeyboard.h"
void setup() {
  analogReference(DEFAULT);
  Serial.begin(9600);
}

void loop()
{
  DigiKeyboard.println(analogRead(A11));
  //Serial.print(analogRead(A8));
  DigiKeyboard.delay(1000);
}
« Last Edit: October 21, 2016, 07:27:15 am by Ram »

Ram

  • Newbie
  • *
  • Posts: 3
Re: Using Serial messes up ADC?
« Reply #1 on: November 05, 2016, 10:23:27 am »
Hi Ralf,

Apologies for the tardy revert - was a holiday season here and I went on a vacation a few days after the original post. Thanks so much for your response! To answer your questions:

- The Digispark pro output '13' (a steady 13) when the commented line was uncommented
- I used a length of wire about 6 inches with gold-plated EZ clips on either side to clip the A8 and A11 pins to ground on the Digispark Pro board itself.
- Yes, the A8 printed on DigiKeyboard printed '0' as ought to be the case.
- I did not print the A11 output on serial, as I felt it was not really relevant

Note that in this specific sample code the serial port was not connected to anything; actually I was trying to figure out why a similar problem was happening on a custom board I had built that was pretty much a clone of the Pro. In that board the Serial data was being fed to a Bluetooth module (and yes I did print the A11 to serial there - same problem). When things looked funny I wrote this test code and ran it on the Pro to reproduce the problem.

In summary, what happens is that merely using Serial in an unrelated fashion seems to mess up AnalogRead!

Best - Ram

Ram

  • Newbie
  • *
  • Posts: 3
Re: Using Serial messes up ADC?
« Reply #2 on: November 09, 2016, 07:01:07 pm »
Actually I did notice that post on this forum on the unconnected AVCC, so in the custom board I referred to I connected AVCC to VCC and AGND to GND on the PCB itself. However I have this problem on that board too and there the nonzero value is more than '200' (a small error from VCC, as opposed to a small error from zero). However I reckoned I could not ask for support on a custom board so I thought I'd try this on the Digispark Pro and that's how I reported that issue. My feeling is that all other things being equal, the mere usage of Serial should not change an ADC read. So if AVCC being unconnected could cause erratic reads, that erratic read should happen whether you have a totally unrelated call to Serial or not as in the commented line.  Besides that nonzero read is a constant 0 and does not happen with reading A8 - if it was a bad reference it should happen with A8 as well as A11! 

Anyhow, I appreciate your efforts in helping me try to resolve the issue. I'll post a resolution if I find one. Thanks Ralf!

-Ram