Go Down

Topic: Digital Write D0 & D1 LOW doesn't drive the pin low (Read 2845 times) previous topic - next topic

irethedo

I have a new Arduino Uno and I have discovered that
DigitalWrite D0 & D1 LOW doesn't drive the pin low.

Did something change or am I doing something wrong?


cr0sh

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

retrolefty

Yes, post code. You most likely forgot to use pinMode(pin, mode) commands?

Lefty



Nick Gammon

I'll save him/her the trouble ...

Code: [Select]
void setup ()
{
  Serial.begin (115200);
 
  pinMode (0, OUTPUT);
  pinMode (1, OUTPUT);
 
  digitalWrite (0, LOW);
  digitalWrite (1, LOW);
}

void loop () {}


On my Uno Rev 3, LEDs on D0 and D1 glow brightly.

However if you remove the Serial.begin() they don't.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

retrolefty

What leds? wired to ground or +5vdc?
Led wired to output pins also require resistors, what value?

;)

So does rev 1 have some new behavior about pins 0 and 1 ? Or is it another opiboot feature?


Nick Gammon

Are these questions addressed at me?

Quote
What leds?


Normal cheap ones. Forward voltage 1.92V.

Quote
wired to ground


Yes.

Quote
Led wired to output pins also require resistors, what value?


150 ohms.

I'm measuring 2.67 mA out of D0.

And 16.55 mA out of D1.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

retrolefty


Are these questions addressed at me?

Quote
What leds?


Normal cheap ones. Forward voltage 1.92V.

Quote
wired to ground


Yes.

Quote
Led wired to output pins also require resistors, what value?


150 ohms.

I'm measuring 2.67 mA out of D0.

And 16.55 mA out of D1.


Just a tease, the real question is about the need for a serial.begin before pins 0 and 1 function as output pins? is that a new behaviour with rev1 or what?


Nick Gammon

Well I think that the Serial.begin takes over the pins. With it out you get to use them as you will.

Bear in mind the gentle pull-up of the USB chip. That is going to put some current on those pins. I think I commented on that before.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

retrolefty


Well I think that the Serial.begin takes over the pins. With it out you get to use them as you will.

Bear in mind the gentle pull-up of the USB chip. That is going to put some current on those pins. I think I commented on that before.


Ok, I remember now the 1k series resistors to a signal output and signal input pins of the serial converter.

irethedo

Well, that is very peculiar and subtle...

I had the  Serial.begin (115200) statement at the end of my setup function after the pin mode definitions and not before the
pin mode definitions and that made all the difference which now allows D0 & D1 being written to a LOW state.

Is this a recent change with v1.0?

I have been using V 22 for some time and never encountered this phenomenon before...

Thanks for the help!

irethedo

#11
Mar 07, 2012, 05:01 pm Last Edit: Mar 07, 2012, 05:32 pm by irethedo Reason: 1
Ooops - I spoke too soon.

If I put these in the loop, once I write the value high, it can not be set low again...

I got tired of measuring it with the meter so I tied a LED & 370 ohm resistor from D0 to ground to monitor it
The LED stays on once a HIGH is written to D0 and does not go off indicating that DO has not been set to a Low state
even though the code performs digitalWrite(D0,LOW)...

What is going on?

Here is my simplified code that produces these results:

void setup ()
{
 Serial.begin (115200);
 
 pinMode (0, OUTPUT);
 
 digitalWrite (0, LOW);

}

void loop () {

digitalWrite (0, HIGH);
delay(3000);  // delay 3 secs

digitalWrite (0, LOW);
delay(3000);  // delay 3 secs
}

Nick Gammon

Well, D0 and D1 are used for serial comms. It isn't particularly surprising that, if you are using serial, there is a clash. Further, the "idle" state in async serial is a continuous "high". Which is what you are seeing.

In fact it doesn't make sense to turn serial on, and then try to use D0/D1 for other purposes. What will become of the serial comms? Decide which you are going to do... use serial or use the pins for other purposes.

Because of the internal way the Atmega328 and the USB chip are connected you are probably better off leaving those two pins for serial anyway. Find another way of doing what you want, like a shift register chip (costs around $1).
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

CrossRoads

Or just use a part with more IO pins (and hardware 2 serial ports), like this '1284 Duemilanove style board.
Bare PCB $4.50, mostly thruhole, with options for FTDI Basic/FTDI Cable, or a USB/Seriall adapter.
Need to get one assembled for better show & tell!
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Graynomad

As D0 is Rx and therefore an input when using serial I suspect that the serial library is changing it back to an input.

When you do the digitalWrite (0, LOW); that probably looks like a start bit to the UART and it may even be used as a PC int by the library (I don't have access to the code at present so can't check).

I suspect that if you had proper test equipment you would see the pin go high after one character time when the UART generated a RX char available interrupt and the serial library was called.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up