0

I've got a Raspberry Pi Zero W v1.1 set up today and I've been trying GPIO's. Got them (I'll refer to GPIO #3) to output between 3.3v to 0.05v on command using echo 0 > /sys/class/gpio/gpio3/value with direction OUT and got them to read in logic 1 to 0 by connecting pin #7 (GPIO #3) to a ground (will replace with a sensor later on) with direction IN.

My question is: Would you consider this normal that the Raspberry Pi defaults to logic 1 as soon as you enable the export? echo 3 > /sys/class/gpio/export

Can somebody elaborate on why this is? Also, why is this exactly the opposite of this guy's scenario: Reading a sysfs GPIO input pin (direction as "in") always print a fixed value (0)

Kthx

that-ben
  • 245
  • 1
  • 13
  • The output has to be a valid logic state. Why are you trying to compare the output state to a question about input state? A pin can be pulled up or down to affect the floating/undriven input. – sawdust Dec 12 '17 at 21:50
  • You misunderstood my question: It's both about input and output, I mean regardless of the direction, it defaults to value=1: if I set the direction to OUT, it defaults to value=1 and If I set the direction to IN, it ALSO defaults to value=1. Why is that? Moreover, why is not defaulting to value=0 if there's nothing connected to a pin? – that-ben Dec 12 '17 at 21:59
  • *"Moreover, why is not defaulting to value=0 if there's nothing connected to a pin?"* -- The third/last statement in my comment addresses that. There's probably a pull-up resistor defined for that pin. Consult the datasheet or TRM, and your kernel configuration, e.g. Device Tree. – sawdust Dec 12 '17 at 23:14

1 Answers1

0

You said there is nothing connected to the pin, yet you read value=1. This is due to internal bias on the input which is weak and can be over-driven by an external circuit if you were to connect something to the pin. The internal bias simply is a large (~1M ohm) resistor to the VCC, so you are reading this bias. Try connecting a 1K ohm resistor from the pin to ground and read it again. It should read value=0 as you were initially expecting.

icodeplenty
  • 252
  • 1
  • 6