2018-08-04
Blinky !!!
Here we will do the customary "blinky", the Hello World for hardware.
To keep things organized, use SSH to open a terminal on the Pocket Bone and make a directory named 'mkdir progs' or whatever you want to keep your programs in.
Then 'cd' into that directory.
The code used for this example came from adafruit-beaglebone-io-python.
It will cause the four on-board LEDs to turn on and off in a sequence.
Type 'vim blink.py', this will open the editor vim and create the file blink.py 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.
#!/usr/bin/python
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)
time.sleep(1)
for i in range(4):
GPIO.output("USR%d" % i, GPIO.LOW)
time.sleep(1)
Once you are finished click on the 'esc' key to put vim into 'command' mode. Then 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 blink.py'. 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 blink.py &'. 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.
Pressing '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'