Beaglebone Black – Push Button

Introduction

In this course we will see how to read the value of a push button on the beaglebone black.

Beaglebone Black

The beaglebone Black is a card developed by Beaglebone. It works with an ARM Cortex A8 processor.

The BeagleBoard is a low power single board computer type electronic card. This is open source hardware produced by Texas Instruments in collaboration with Digi-Key.

This BeagleBone board is a single board computer that can be used as a standalone computer or can be integrated into a system.

Electronic Diagram

Here’s the electrical diagram of the push button on the beaglebone black board. We’ve added a pull-up resistor to avoid indeterminate states and force the signal to 0 when you don’t press the button:

How do I choose which pin to connect the pushbutton to?

We’ve connected our pushbutton to one of the Beaglebone Black’s GPIOs (“P8_17”). However, you may wish to connect it to another pin. To do so, simply select one of the GPIOS below:

GPIO Library

To control the inputs/outputs of the Beaglebone black board, we’ll need to install the adafruit library. To do this, we propose two solutions, using “pip” or “git” :

Pip installation

The first step is to install pip :

sudo apt-get update
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y

We then install the Adafruit library:

sudo pip install Adafruit_BBIO
sudo python -c "import Adafruit_BBIO.GPIO as GPIO; print GPIO"

#Vous devriez avoir ce message 
<module 'Adafruit_BBIO.GPIO' from '/usr/local/lib/python2.7/dist-packages/Adafruit_BBIO/GPIO.so'>

Installation using git

With git you can copy the project directly from github :

git clone https://github.com/adafruit/adafruit-beaglebone-io-python.git

Once the project has been downloaded, we go into the :

cd adafruit-beaglebone-io-python

Then install the “setup.py” file:

sudo python setup.py install

Once the library has been installed, we’ll delete our folder to save space in our system. 

cd ..

We can now delete the installation file:

sudo rm -rf adafruit-beaglebone-io-python

Push-button reading

Now we’ll see how to read the value of a pushbutton.

To do this, we’ll first create a python file and open it:

nano bouton.py

Then copy this program into yours:

import Adafruit_BBIO.GPIO as GPIO

push_button ="P8_17" # Declaration of push button

GPIO.setup(pushbutton,GPIO.IN) # Pushbutton as input

while (1) : # Infinite loop 
    print((GPIO.input(pushbutton))) # Pushbutton value displayed

As you can see, we’ve made an infinite loop so that the push-button reading is read continuously.

You can change the pin “P8_17” to the one where you’ve placed your push-button.

Once you’ve saved and closed your program, the last thing to do is run it:

python bouton.py

Once started you should see a series of 0’s or 1’s depending on whether you press the push button or not:

0 #Button not pressed
0
0
0
0
1
1 #Button pressed
1
1