0
Offline
Jr. Member
Karma: 0
Posts: 74
Arduino rocks
|
 |
« on: March 06, 2012, 05:04:15 pm » |
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
Faraday Member
Karma: 27
Posts: 5077
Where's the beer?
|
 |
« Reply #1 on: March 06, 2012, 05:52:29 pm » |
show your code, please...
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #2 on: March 06, 2012, 08:44:58 pm » |
Yes, post code. You most likely forgot to use pinMode(pin, mode) commands?
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #3 on: March 07, 2012, 12:33:22 am » |
I'll save him/her the trouble ... 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
Brattain Member
Karma: 240
Posts: 16433
Available for Design & Build services
|
 |
« Reply #4 on: March 07, 2012, 01:01:53 am » |
Really!
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #5 on: March 07, 2012, 01:47:46 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #6 on: March 07, 2012, 02:01:58 am » |
Are these questions addressed at me? What leds? Normal cheap ones. Forward voltage 1.92V. wired to ground Yes. 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
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #7 on: March 07, 2012, 02:06:29 am » |
Are these questions addressed at me? What leds? Normal cheap ones. Forward voltage 1.92V. wired to ground Yes. 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
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #8 on: March 07, 2012, 02:08:31 am » |
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
Brattain Member
Karma: 279
Posts: 15310
Measurement changes behavior
|
 |
« Reply #9 on: March 07, 2012, 02:10:58 am » |
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
Jr. Member
Karma: 0
Posts: 74
Arduino rocks
|
 |
« Reply #10 on: March 07, 2012, 08:11:27 am » |
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
Jr. Member
Karma: 0
Posts: 74
Arduino rocks
|
 |
« Reply #11 on: March 07, 2012, 11:01:22 am » |
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
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #12 on: March 07, 2012, 02:47:32 pm » |
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
Brattain Member
Karma: 240
Posts: 16433
Available for Design & Build services
|
 |
« Reply #13 on: March 07, 2012, 06:14:04 pm » |
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!
|
|
|
|
|
Logged
|
|
|
|
|
nr Bundaberg, Australia
Offline
Tesla Member
Karma: 71
Posts: 6809
Scattered showers my arse -- Noah, 2348BC.
|
 |
« Reply #14 on: March 07, 2012, 06:25:26 pm » |
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
|
|
|
|
|
|