I've read that the Raspberry Pi has a number of input and output pins.
- How can I switch them? (from Python?)
- What voltage logic?
- Do I need pull-up or pull-down resistors?
- Do I need to switch the pins from inputs to outputs?
- Which pins are available?
|
|
|
The GPIO pins are 3.3V and the maximum current is 16mA. That means you'll be unable to power almost anything directly. That's why you need to at least use a transistor switch if not a more advanced protection circuit. You can read more about them here: http://elinux.org/RPi_Tutorial_EGHS:GPIO_Protection_Circuits Here is a general guide: http://elinux.org/RPi_Low-level_peripherals |
|||||
|
|
These instructions aren't Python-specific, but they might help you get started with experimenting with GPIO. http://raspberrypi.stackexchange.com/a/350/668 has info about a library and usage specific for Python. When you have booted your Raspberry Pi using the recommended Debian distro, 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 as root privileges (sudo or otherwise) or you have changed the permissions/ownership of the virtual files being modified.
This enables the 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.
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. |
|||
|
|