Tag Archives: Python

Beaglebone Black LESSON 5: Blinking LEDs from GPIO Pins

This lesson shows a simple example of how to blink two LEDs from the GPIO pins on the Beaglebone Black. To get going, you will need to hook up the following circuit. (If you have not ordered your Beaglebone Black, you can get one HERE.)

Beaglebone Black LED Circuit
Circuit for Blinking LEDs from Beaglebone Black

Note that the Top LED is connected to Pin “P9_12” and the bottom LED is connected to Pin “P9_11”. We are using 330 ohm current limiting resistors.

The video lesson takes you through several examples of how to blink the LED. Watch the video, and do the examples. Then play around on your own and see what you can make the LEDs do.

Beaglebone Black LESSON 4: Digital Write to the GPIO Pins from Python

In this lesson we show you how to do digital writes to the GPIO pins from python. If you do not already have a Beaglebone Black Rev C, you can order one HERE.

In order to do this lesson, we need to go back and review the pinout diagram from LESSON 1.

Beaglebone Black Pinout
Default Pin Configuration for the Beaglebone Black Rev. C.

In Python, we reference pins by first specifying which header we want (P8 or P9) and then which physical Pin. For Example, to specify pin 12 on the left header, we would refer to it as “P9_12”. For digital output, we should use one of the pins above that is shaded green.

To talk to the GPIO pins in Python, we must first import a library. The latest versions of the Beaglebone Black Rev C. are shipping with the library already installed. If you have an earlier version, you need to update to the latest operating system. You can visit the beagleboard.org web site to download the latest operating system. If you get an error when you try and load the library, you know that either you have typed the command in wrong, or you need to update your operating system. In python to import the library you need to include the line:

Once you have imported the library, you then need to setup your pin as an output pin:

Now if you want to set that pin high you can use the command:

To set the pin low you can use the command:

After you are done working with the pin, you should “cleanup” to free the pin up:

These are all the commands you need in order to set the pin “HIGH” or “LOW”. Remember that in the High state, the Beaglebone Black outputs 3.3 Volts.

We can bring things together to make a simple program that will turn the pin on and off in three second intervals. Try and play around yourself with this code. Then try different GPIO pins.

 

Beaglebone Black LESSON 3: Running Python on Your Beaglebone

In this series of lessons, we will be controlling the GPIO pins from Python. If you do not already have a Beaglebone Black Rev. C, you can pick one up HERE.

In this lesson we show you how to write and run a simple Python program. Be sure to go through LESSON 2, which shows you how to boot and remotely connect to the Beaglebone. You will need to know how to do that for this lesson.

Beaglebone Black LESSON 2: Getting Started

In this lesson we show you how to boot up your Beaglebone Black, and how to connect via the Putty SSH terminal client, and how to remotely run the graphical desktop on your PC. If you do not already have your Beaglebone Black, you can pick up one HERE.

The Beaglebone black has only one USB connection, so I find the easiest way to work with it is to just connect by a remote desktop, instead of trying to connect screen, keyboard, and mouse directly to the Beaglebone. This lesson will get you started so you can get connected and talking to your Beaglebone.

Raspberry Pi LESSON 31: Making a Dimable LED with Python

In this lesson we are ready to bring together a lot of what we learned in earlier lessons. We will create dimable LEDs which will respond to two buttons. If one is pressed the LED will gradually grow dimmer. If the other is pressed, the LED will gradually grow brighter. This will require us to use our skills in using GPIO inputs, pullup resistors, GPIO outputs, and PWM.

For convenience we will use the same circuit we used in LESSON 30, shown below. Also, if you want to follow along with these lessons, you can buy the gear you need HERE.

Raspberry Pi LED Circuit
This Circuit Controls two LED from Push Buttons Using the Raspberry Pi

The objective of this circuit is that we want the LEDs to grow brighter each time the right button is pushed, and we want them to grow dimmer each time to left button is pushed.

The video above steps through and explains this code.