Pages: [1]   Go Down
Author Topic: Digital pin output problems  (Read 431 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 75
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Cairns, Australia
Offline Offline
Sr. Member
****
Karma: 2
Posts: 280
Arduino??
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe try adding
Code:
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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 75
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 16, 2009, 05:40:15 am by ardudillo » Logged

Pages: [1]   Go Up
Jump to: