Jump to content

Raspberry Pi - gpio with bash

unijab

Anyone have any examples of how you used the GPIOs with bash and not python (python is the default way to interact with the gpio's) ?

 

 

Can Anybody Link A Virtual Machine while I go download some RAM?

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Finally found something useful....

 

 

 

Bash Script Control of GPIO Ports

The Pi's GPIO ports can be controlled from the command line (i.e. bash), python scripts, and C/C++ programs. There are 17 GPIO ports available on the Pi. Some of them have special purposes or special hardware configurations and should be avoided for normal use.

Using GPIO from bash

The following commands should be run as root (type 'sudo bash' to become root). This code sets up pin 18 to be an output, sets the pin high and then sets it low.

# Exports pin to userspace
echo "18" > /sys/class/gpio/export

# Sets pin 18 as an output
echo "out" > /sys/class/gpio/gpio18/direction

# Sets pin 18 to high
echo "1" > /sys/class/gpio/gpio18/value

# Sets pin 18 to low
echo "0" > /sys/class/gpio/gpio18/value

This next snippet sets up pin 4 to be an input, then reads the value of the input.

echo "4" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio4/direction
cat /sys/class/gpio/gpio4/value
Can Anybody Link A Virtual Machine while I go download some RAM?

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×