Author Topic: Pinmode, pullup resistors, inputs and outputs  (Read 3734 times)

LazyGlen

  • NewMember
  • *
  • Posts: 48
Pinmode, pullup resistors, inputs and outputs
« on: March 25, 2014, 06:10:43 PM »
A quick question.

I am using a Moteino to both monitor and control a signal. The signal is high, and when a switch is pressed, shorts to ground. I've measured the current at 30uA when the switch is closed. I would also like to be able to have the Moteino simulate pressing this same button and pull it low.

If I set:
pinMode(MoteCtrl, INPUT_PULLUP);
the Moteino can monitor this pin. Can I then write a low to this same pin without worrying about shorting the pin? I'm not really pin constrained, so I guess I could use the adjacent pin in output mode. Should I (or is the compiler smart enough to require me to) set the pin to output mode prior to writing a low, let the event happen, then return to input pullup mode? I'm going around in circles on this - as soon as I'm convinced one way, I start arguing the other way.

LG

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Pinmode, pullup resistors, inputs and outputs
« Reply #1 on: March 25, 2014, 07:54:48 PM »
So .. you want to write a LOW, but capture that as an input?
IOW you want the pin to be both input and output at the same time?
I don't think that's possible. Maybe use another OUTPUT pin to trip this INPUT pin?

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Pinmode, pullup resistors, inputs and outputs
« Reply #2 on: March 25, 2014, 10:48:19 PM »
Sorry, I realize that I wasn't very clear, I was trying to get it posted before I left to pick up my daughter and rushed it.

I'm interfacing a Moteino with a commercial product. 95% of the time I expect the Moteino to be sleeping. 95% of the rest of the time, the Moteino would be monitoring this signal, reporting any change from high to low back to the gateway, indicating that an event has taken place. Infrequently, I would like the Moteino to be able to initiate the event - pull the signal low.

Let me use the GarageMote as an example. I realize that GarageMote may have a different method for initiating a door open or close, but lets say I want to know if/when someone pushes the inside button to open the garage door. That 3.3v signal comes out of a pin on a micro-controller in the opener, connects to a N/O push-button switch and goes back up to the controller and ties to ground in the opener. I put a Moteino next to that switch tie the ground to the Ground return line and monitor the 3.3v line. Vast quantities of time sleeping, occasional reports to the Gateway: "Hey! Someone just pushed my button!" And, on rare occasions, when I'm laying in bed and see that the door is open, I can send a command to my faithful 'Mote, "Tie that pin to ground for 5 seconds for me, little buddy, will ya?" And smile as I watch the door descend.

I'm probably over thinking this. On one hand its probably not a big deal. But I can't measure that current inside the chip, and I don't want to wind up with a dead pin, and not know it.

LG

LazyGlen

  • NewMember
  • *
  • Posts: 48
Re: Pinmode, pullup resistors, inputs and outputs
« Reply #3 on: March 25, 2014, 11:19:03 PM »
I found a little more information on the Arduino support forum.

First, the part that got me concerned in the first place:
http://arduino.cc/en/Tutorial/DigitalPins
Quote
Short circuits on Arduino pins, or attempting to run high current devices from them, can damage or destroy the output transistors in the pin, or damage the entire Atmega chip. Often this will result in a "dead" pin in the microcontroller but the remaining chip will still function adequately.
In my opinion there is some confusion in the documentation from IDE pre 1.0.1 vs current documentation. Maybe I'm just reading it wrong, but the above page got me twisted around. This page: http://arduino.cc/en/Reference/digitalWrite made it clear to me:
Quote
If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin. It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor. See the digital pins tutorial for more information. (Or obfuscation! LG)

So: Once a pin is set to an input, writing HIGH to that pin turns on the pullup. Writing LOW does not short the input to ground, it would simply turn off the pullup resistor and leave the pin floating. Thus, to do what I want to do, I have 2 options; use a second pin or change the pin from an input to an output, write a low, delay, then change the pin back to an input. Given my particular circumstances, I probably don't need the internal pullup anyway.

LG

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Pinmode, pullup resistors, inputs and outputs
« Reply #4 on: March 26, 2014, 08:32:15 AM »
Ok that explanation adds more clarity. And as the documentation suggests you might not want to tie the digital pin directly to another electrical system.
So in the case of the garage opener that would not work since the voltage passing through the wall opener is 24V (at least mine). GarageMote uses a relay for switching and hall effect sensors to sense when the door is moving.
In your case I'm not sure what the best thing to do is, but my gut tells me it should be some kind of sensor? Unless the thing you're interfacing to is 3.3V or 5V, that way i guess you could use another pin to interface directly to it.