Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumBugsSoftware Bugs › analogRead is killing my digitalWrite...

Page Index Toggle Pages: 1
analogRead is killing my digitalWrite... (Read 9796 times)
11/14/10 at 23:12:29

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
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...  Wink )

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);

}
 

 
IP Logged
 
Reply #1 - 11/15/10 at 00:42:12

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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. Smiley
 
IP Logged
 
Reply #2 - 11/15/10 at 00:54:30

roypardi   Offline
Junior Member
I Love YaBB 2!
Boston USA

Posts: 57
**
 
Ah - ok. Thanks for the reality check. Guess I'll move some cables around. Learn...trip over something new every day... Smiley
 
IP Logged
 
Reply #3 - 11/15/10 at 02:46:11

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
I'll clarify that better on the documentation : )
 
IP Logged
 
Page Index Toggle Pages: 1