Go Down

Topic: Digital pin output problems (Read 459 times) previous topic - next topic

ardudillo

Hello, I have a very weird problem which, after a lot of cutting bits of code out of a larger program, I have simplified down to the following code:

Quote

#include <Servo.h>

byte motorPin = 9; // ATTACHED TO A LED FOR TESTING PURPOSES
byte servoPin = 6;

Servo s;

void setup() {
  //s.attach(servoPin);
}

void loop() {
  analogWrite(motorPin, 255);
}



Now, the "motorPin" (named so because originally going to control a solid state relay for controlling a DC motor) is attached to an LED to check if it comes on or not.

Now, guess what, with the code as shown above, the LED turns on, no surprises there. With the:

s.attach(servoPin);

line uncommented however, the LED stays off :o

What is going on here? I have tried changing the pin numbers (moved motorPin from 9 to 10) but doesn't solve the problem. The offending line is the servo attachment to its pin.

Things

Maybe try adding
Code: [Select]
pinMode(motorPin, OUTPUT); in your setup?

If the LED stays off, it may mean the code isn't getting to your loop. Is it possible to move the motor pin to a digital pin?

PaulS

A comment in Servo.cpp:
Quote
Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached.


So, this is expected behavior. Perhaps not desired, but expected.

ardudillo

#3
Nov 16, 2009, 10:12 am Last Edit: Nov 16, 2009, 11:40 am by ardudillo Reason: 1
Right, bummer but I get it now. Thanks.

P.S. solved by moving motorPin to pin 11 (leaving servo on pin 5) on Duemilanove board.

Go Up