Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Bugs >> Software Bugs >> analogRead is killing my digitalWrite...
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1289776349

Message started by roypardi on 11/14/10 at 23:12:29

Title: analogRead is killing my digitalWrite...
Post by roypardi on 11/14/10 at 23:12:29
Hi -

I am using pins 40 + 41 (analog 0 + 1) to read from a Sharp IR sensor. That works fine on it's own. I am also using pins 42-44 to trigger a Darlington transistor to control some motors (digitalWrite). Those also work fine on their own.

When I combine the two routines in one sketch the analogRead kills the digitalWrite - and the motors don't run. In the barebones sketch below, before I added pinMode(44, OUTPUT); at the start of each loop, the motor would run just one time and no more after the analogRead got called.

I guess I have a workaround in redeclaring 'pinMode' at the start of each loop (ugly) but should this be necessary? (I know I can use other pins but I'm all cabled up and running short of pins)

In other words, does using one of the Analog pins to do analog reads mean that none of the other Analog pins can be used as digital pins at the same time?

Is this a bug or as designed/fact of life? If this is as designed then some specific mention in the docs would be good (for my heartburn...  ;) )

thanks!

Code:
void setup() {
  pinMode(44, OUTPUT);


void loop()
{
// pinMode(44, OUTPUT); // adding this apparently resets something... ;-)
  digitalWrite(44, HIGH);
  delay(500);
  digitalWrite(44, LOW);
  delay(500);

// the digitalWrites above no longer work after this is called
  int sensorValue = analogRead(1);

}

Title: Re: analogRead is killing my digitalWrite...
Post by barragan on 11/15/10 at 00:42:12
hi Roy, it is not a problem, the thing is using any analog input pin (0-7) will setup the whole port as an analog input port. That special port can't be used in a combined mode. :)

Title: Re: analogRead is killing my digitalWrite...
Post by roypardi on 11/15/10 at 00:54:30
Ah - ok. Thanks for the reality check. Guess I'll move some cables around. Learn...trip over something new every day... :)

Title: Re: analogRead is killing my digitalWrite...
Post by barragan on 11/15/10 at 02:46:11
I'll clarify that better on the documentation : )

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.