0

setting the direction as out for gpio4 changes is state.
echo 'out' > gpio4/direction
changes its value to 0.
How can I initialize the direction of a GPIO with out altering its value?

3

Setting the GPIO to the output state must assign a value. When it acts as an input it is in a high impedance state, i.e. is not being pulled low or high by the controller. Setting the pin to output will select either one of these. You can avoid glitching and initially select high by:

echo 'high' > gpio4/direction

or low by:

echo 'low' > gpio4/direction

The pi does also, however, have weak internal pull up and down resistors. These are software configurable, and mostly pull down by default. These can't be configured by sysfs, you must use wiringPi or a memory map to do change them.

Note that on the SCL and SDA pins (for i2c) the pi has external pull-up resistors which can't be overriden.

For more information on the sysfs gpio control, see: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.