2

I have something strange going on with an output. When the following code is called the LED goes on, but it stays on, there is no blinking. If I comment out the set HIGH statement the LED never comes on (as expected).

#define devicePin 10

void setup() {
  pinMode(devicePin, OUTPUT);
}

void loop() {
    digitalWrite(devicePin, HIGH);
    delay(2000);
    digitalWrite(devicePin, LOW);
}

Could I have damaged the board in some way?

3 Answers 3

5

After you drive the pin low, you immediately go to the beginning of the loop and set the pin high (if you have an oscilloscope, you might see a very short downward pulse).
So, add another delay after digitalWrite(devicePin, LOW).

3

you forgot to add a delay after digitalWrite(devicePin, LOW);

#define devicePin 10

void setup() {
  pinMode(devicePin, OUTPUT);
}

void loop() {
    digitalWrite(devicePin, HIGH);
    delay(2000);
    digitalWrite(devicePin, LOW);
    delay(2000);
}
2

Yes, the pin is going low. I tested it for you:

Pin 10 going low

It went low for 6 µs, once every 2 seconds. :)


Overall, this is the effect:

Pin 10 mainly high

As you can see, high for most of the time.

4
  • Yeh, I can't believe I missed it. BTW: what did you use to monitor it and create those screens?
    – CarbonMan
    Sep 13, 2015 at 5:01
  • 1
    My trusty Tektronix TDS 2002 oscilloscope. To get the output I get the scope to output in PCX format through its RS232 port, route it through a RS232 to TTL converter, connect that to a FTDI cable, and capture it on my computer. That scope was made in the days before they had plug-in USB drives.
    – Nick Gammon
    Sep 13, 2015 at 5:04
  • One more question, what would you recommend now for an entry level scope?
    – CarbonMan
    Sep 14, 2015 at 8:37
  • 1
    You are probably best off with one of the Saleae Logic scopes/logic analyzers. Something like the Logic 4 is only $109 and has one analog and 3 digital channels. Or one of the higher models if you can afford it. I find the Logic very very useful for decoding SPI/I2C/Serial data streams. You could make this a separate question, others may also want to chip in with their suggestions.
    – Nick Gammon
    Sep 14, 2015 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.