Pages: [1]   Go Down
Author Topic: Does Arduino keep the state of pin?  (Read 501 times)
0 Members and 1 Guest are viewing this topic.
China
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, all,

According to the reference, the digitalWrite(pin, HIGH) command would set 5v or 0v to the pin when the command is digitalWrite(pin,LOW), but the waveform of the output pin, captured with a virtual scope, differs from the conclusion above, the waveform indicates the output voltage is set to 5v when digitalWrite(pin, HIGH) is executed, and then set to about 0v until next command is executed.

The code snippet as follows:

void loop()
{
  if (val)
    digitalWrite(P13,HIGH);
  else
    digitalWrite(P13,LOW);
  delay(1500);
  val = !val;
  //Serial.println(val);
}


                  


What I am confused is that the LED connected to the output pin could still light before it is set to LOW. Can anyone help me understand this command correctly?

BR,

Ardypro
« Last Edit: August 14, 2011, 08:11:22 pm by ardypro » Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 29
Posts: 2590
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Switch your scope to DC input , instead of AC
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7188
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Probably used AC coupling where dc is needed.
Logged


China
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ooops, my soundcard based virtual scope seems only support AC input.  smiley-cry
« Last Edit: August 15, 2011, 05:14:37 am by ardypro » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7188
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ooops, my soundcard based virtual scope seems only support AC input.  smiley-cry

Then just trust your LED smiley
Sound cards have capacitors or else to take DC out from input.
Logged


Pakistan
Offline Offline
Sr. Member
****
Karma: 6
Posts: 357
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have not put the curly braces in if-else statement!!!!!
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7188
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The OP doesn't really have block statement so no curly brackets are needed.
Logged


Seattle, WA
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was seeing something very similar when I was testing the digital output functionality. A short while back I was trying to figure out why my relay driver circuit was always ON whether I set the digital pin to "0" or "1".

After a lot of scouring around, I learned the hard way that I had to explicitly set the digital pin as OUTPUT (duh). In a nutshell, the Arduino digital pins are all initiaized to INPUT by default, which is a High Impedance state (~10MOhms). Long story short, due to the much lower input impedance of my driver circuit, it seems to draw just enough extra current that it will be activated even if the digital output is set to "0".

Oddly, my observation with a DVM is similar in that the "0" state output is also around 1.5-2V, which was higher than one would expect. I tried adding pull-up and pull-down resistors but I still got glitchy results. But after reading the description of the I/O pins:

http://arduino.cc/en/Tutorial/DigitalPins

I just had to explicitly set the pin to OUTPUT, an everything worked like a charm afterwards. Since I didn't see your setup() function, I'm not sure if you are already setting the pit to OUTPUT - but it's worth a shot because the solution is not obvious.
Logged

Pages: [1]   Go Up
Jump to: