Book Image

Learning Beaglebone Python Programming

Book Image

Learning Beaglebone Python Programming

Overview of this book

Table of Contents (19 chapters)

Taking advantage of the OS


Since the BeagleBone is running a full GNU/Linux operating system, there are plenty of great tools available for us to take advantage of. Let's look at a couple of the advantages an OS gives you.

Multiprocessing

Every time you click on Run in Cloud9, it launches the program as a new process, so you can easily run many different programs simultaneously. Let's add a second transistor/LED circuit, this time using GPIO3_19 on P9.27.

For this, you will need:

  • Breadboard

  • 2x 5 mm LED

  • 2x 4.7 kΩ resistor

  • 2x 68 Ω resistor

  • 2x 2N3904 NPN transistor

  • Jumper wires

Wire it up on your breadboard as shown here:

Now create a new file called blink2.py, and this time, let's use PyBBIO, as shown in the following code:

from bbio import *

LED_PIN = GPIO3_19

def setup():
  pinMode(LED_PIN, OUTPUT)
 
def loop():
  digitalWrite(LED_PIN, HIGH)
  delay(250)
  digitalWrite(LED_PIN, LOW)
  delay(250)
   
run(setup, loop)

As you can see, this time, we're delaying the loop by 250 milliseconds or a quarter...