User Tools

Site Tools


Here we will do the customary “blinky”, the Hello World for hardware.
To keep things organized, make a directory named 'progs' or whatever you want to keep your programs in. Then 'cd' into that directory.

The code used for this example came from It will cause the four on-board LEDs to turn on and off in a sequence.

Type vim, this will open the editor vim and create the file if it does not yet exist. To enter text into the vim editor first click on the key 'i', this put vim into 'insert' mode. Now type the below into the editor being sure to have the indents correct.

import Adafruit_BBIO.GPIO as GPIO
import time

for i in range(4):
    GPIO.setup("USR%d" % i, GPIO.OUT)

while True:
    for i in range(4):
        GPIO.output("USR%d" % i, GPIO.HIGH)
    for i in range(4):
        GPIO.output("USR%d" % i, GPIO.LOW)

Once you are finished click on the 'esc' key to put vim into 'command' mode. The type ':wq'. This will casuse the file to be written and vim to quit. You will now be back at the command prompt.

To run your script type 'python'. If there are no errors the four LEDs will be blinking on and off in a sequence. To turn the script off, hold on the CTRL key while clicking the 'c' key. This will take you back to the command prompt.

To run the script with a command prompt so you can do other things while your script is running type 'python &'. This will give you a command prompt with a couple numbers above it. The numbers represent the running job. The job number will be different every time. To find the running jobs type 'top'. In the command column on the right side you will see 'python' at some point with the PID number in the first column on the left. 'CTRL c' to stop 'top'.

To stop the blink script now type 'kill -9 <PID>' where <PID> is the number found from 'top' or when the script started. Something like this kill -9 1356

blink.txt · Last modified: 2017/10/12 00:11 by mackrackit