Pages: [1] 2   Go Down
Author Topic: Digital Write D0 & D1 LOW doesn't drive the pin low  (Read 1505 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 5519
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

show your code, please...
Logged

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16520
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lefty
 

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 439
Posts: 23759
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Really!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16520
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

 smiley-wink

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

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16520
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16520
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

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

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
}
« Last Edit: March 07, 2012, 11:32:58 am by irethedo » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 439
Posts: 23759
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!


* Atmega1284_thruhole_pcb.jpg (465.83 KB, 1824x663 - viewed 7 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8452
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1] 2   Go Up
Jump to: