What is the state of the GPIOs when power is applied? eg High, Low, Hi-Z?
Also does any OS change the state of any GPIOs when it loads? Hopefully not.
I have jumped to conclusions about my pull up resistors / sensitivity of my circuit to the pull down resistors. The RPi is not setting the GPIO to output when first booted. It is turning on a pull down resistor for 740 milliseconds.
I have used two 18K resistors ( 3v3 -> GPIO -> GND ) to look at exactly what is going on with the pins. Here is the trace. Blue line is 3v3 power, yellow line is GPIO line.
When started using the recommended Debian distro for RPi, GPIO is disabled. You have to enable each pin individually.
If you're doing it via /sys you will find "Paths in Sysfs" interesting (search within http://www.kernel.org/doc/Documentation/gpio.txt). In particular, you would be enabling a pin by "exporting" it. Any commands below assume you are running with root privileges (sudo or otherwise) or you have changed the permissions/ownership of the virtual files being modified.
echo 4 > /sys/class/gpio/export
This enables GPIO pin #4 which then causes /sys/class/gpio/gpio4 to exist, which contains several virtual files. Those files include "direction" which defines whether it's an input or an output pin, "value" which is either read-only for input or writable for output and contains the current value, and others.
echo out > /sys/class/gpio/gpio4/direction # set it as an output pin echo 1 > /sys/class/gpio/gpio4/value # set the value to ON echo 0 > /sys/class/gpio/gpio4/value # set the value to OFF echo in > /sys/class/gpio/gpio4/direction # set it as input cat /sys/class/gpio/gpio4/value # get the value echo 4 > /sys/class/gpio/unexport # disables pin 4 and removes the gpio4 directory
Of course, you'll probably prefer to use some preexisting library to do GPIO supplied with or compatible with your language of choice. But if you're wanting something simple, you can just interface directly with sysfs to do very basic GPIO.