User Guide

167
1. On the Application Launcher, click LXTerminal.
2. Type the following command and then press Enter:
sudo su
3. Type the following command and then press Enter:
echo 2 > /sys/class/gpio/export
To configure the pin as an input and enable the internal pull-up
resistor:
1. Type the following command and then press Enter:
echo in > /sys/class/gpio/gpio2/direction
2. Type the following command and then press Enter:
echo 0 > /sys/class/gpio/gpio2/active_low
To read the pin, you can use the cat command, which is used to
read files and display them in the terminal:
1. Type the following command and then press Enter:
cat /sys/class/gpio/gpio2/value
2. Type the following command but do NOT press the
Enter key:
cat /sys/class/gpio/gpio2/value
3. Press the switch (hold it if you are using a push
button), and then press Enter.
When you are done, unexport the pin so that it is no longer
under the control of the file system entries:
• Type the following command and then press Enter:
echo 2 > /sys/class/gpio/unexport
Reading a GPIO Pin from Python 3
As for output pins, you can use the RPi.GPIO module to read
from an input pin, and the setMode() method to state how you
want to refer to pin numbers.
1. Create a new Python script and save it with the
extension .py.