• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

KaliTut

Kali Linux tutorial and Linux Tips

  • Home
  • Raspberry Pi
  • Privacy Policy
  • About us
  • Affiliate disclaimer

Control Raspberry Pi GPIO with sysfs

November 26, 2017 by Kalitut

Control and program Raspberry Pi GPIO with “sysfs” (shell/bash)

raspberry pi gpio sysfs

The GPIOs are represented on Raspberry Pi as files and can be found in the directory tree under “/ sys / class / gpio”. This is called “sysfs”. If you look at the contents of the files, you get the state out. This is either “1” or “0”.

ls /sys/class/gpio

When controlling and programming you have to make sure that you do not choose the pin number, but the BCM number of the GPIO. In the following example, we configure the GPIO 17 (pin 11) as the output and the GPIO 18 (pin 12) as the input.

  • Raspberry Pi GPIO assignment

Note: Programming the GPIOs via “sysfs” is not recommended. The recommended way is with the command line tool “pigpio”.

  • Control Raspberry Pi GPIO with pigpio

Configure GPIO as input or output
To configure a GPIO you have to create it first. Then you decide on the direction. So either as input or output. First, we turn on the “GPIO 17”.

echo 17> /sys/class/gpio/export

If the GPIO is to be configured as an input, the following command applies.

echo in> /sys/class/gpio/gpio17/direction

If the GPIO is to be configured as an output, the following command applies.

echo out> /sys/class/gpio/gpio17/direction

A GPIO configured as an output should then be given a status, ie “high” or “low”.

State of a GPIO output set
Basically you can only set outputs. To set the state of a GPIO output to “high”, the following command is sufficient.

echo 1> /sys/class/gpio/gpio17/value

To set the state of a GPIO output to “low” the following command is sufficient.

echo 0> /sys/class/gpio/gpio17/value

Determine GPIO status
To determine the state, ie “high” or “low”, at a GPIO, the following command is sufficient. The GPIO can be both an input and an output.

cat /sys/class/gpio/gpio17/value

The output is “1” for “high” or “0” for “low”.

Disable GPIO
If you no longer need GPIOs, then you should disable them. The following commands will cause the files and directories of the GPIOs to disappear. When restarting, the GPIOs are automatically reset.

echo 17> /sys/class/gpio/unexport
Post Views: 442

Filed Under: Raspberry Pi Tagged With: Raspberry Pi GPIO

Reader Interactions

Comments

  1. jpmh says

    December 11, 2022 at 10:40 pm

    Probably the best and most concise posting I have ever seen.

    I needed to control pins and you showed me how. TY

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow us

  • Facebook
  • Twitter
  • YouTube

Categories

  • algorithm
  • Android Ai coding
  • Android pentesting tools
  • Arduino
  • Artificial Intelligence
  • Books
  • ChatGPT Prompt
  • Darknet
  • database
  • General
  • Github Tools
  • Hacking
  • Kali Linux
  • Linux
  • Linux Commands
  • Network Administrator
  • Penetration Testing
  • Penetration Testing Tools
  • PowerShell
  • Raspberry Pi
  • resources
  • Review
  • Termux
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Video Tutorials
  • vmware
  • WiFi Adapter
  • WiFi Pentesting
  • Wireless Router
  • Wireshark

Recent Posts

  • Transforming Photos with ChatGPT Prompt : A Cinematic Double Exposure in a Post-Apocalyptic World
  • Stryker Android App: Your Mobile Pentesting Powerhouse
  • Alfa awus036ach review
  • Alfa AWUS1900 for Wireless Penetration Testing
  • How to Run DeepSeek AI Locally on Kali Linux – Step-by-Step Guide

Footer

Kalitut

Kalitut.com goal is to share the knowledge for free, help you find the best tools on the web and provides tutorials

Find us on social media

  • Facebook
  • Pinterest
  • Reddit
  • Twitter
  • YouTube

Copyright © 2025

  • Home
  • About us
  • Privacy Policy
  • Affiliate disclaimer