Logging In and Navigating

Logging in to the Pi

Log into the Pi using putty (Windows) or ssh (Linus or OSX) depending on your operating system.
In this example we assume that we already know the ip address of the Pi, and it is 192.168.4.76. We also assume that the Pi still has it's default name, "raspberrypi", and default username ("pi") and password ("raspberry"): If you log in using a Terminal window the command is:
ssh pi@raspberrypi.local

Navigating the Terminal window

Terminal commands:

ls: list files in the directory.

ls
Bookshelf  Documents   Pictures   rpi-led-strip  Videos
Desktop    Downloads   Music      Public         Templates

cd: change directory.

cd rpi-led-strip
The example programs for controlling the LED's are in the pyLED subdirectory of the rpi-led-strip directory, so we'll go into the rpi-led-strip directory first. The command gives no response; many terminal commands are silent if successful. However, you should see your prompt change to reflect the new directory you're in. We can check that we're in the right directry with the pwd command.

pwd: print working directory.

pwd
/home/pi/rpi-led-strip
Prints the full path to the directory you're currently working in, which should be /home/pi/rpi-led-strip.

Moving forward: Now we list the files and directories in the working directory and change into the pyLED directory with the commands:
ls
error.log  old-web      README.md      webServer
flags      PI_SETUP.md  ssh            wpa_supplicant.conf
NOTES.txt  pyLED        testTime.html
cd pyLED
ls
aRainbow.py  clearSwitch.py  startup.py  test2.py
clear.py     rainbow.py      test1.py    test3.py

more: showing the contents of a file.

more test1.py
import board
import neopixel

pixels = neopixel.NeoPixel(board.D18, 20)

pixels[2] = (10,0,0)
This shows the entire contents of the test1.py file. For longer files you can tap the Space Bar to move forward a page, or Enter to move forward one line.

python3: calling the python interpreter to run a program.

python3 test1.py
Can't open /dev/mem: Permission denied
...
You'll see a long error output that starts with "Permission denied". Most python programs should not have this problem, but in order to control the LED's we need superuser permissions. We use sudo to aquire these permissions.

sudo: run a program with superuser status.

sudo python3 test1.py
You should get no response from the terminal window, but the third LED should light up and turn red.

cp: copy file

cp test1.py myTest1.py
ls
aRainbow.py  clearSwitch.py  rainbow.py  test1.py  test3.py
clear.py     myTest1.py      startup.py  test2.py
Here we copy the test1.py file to a new file named myTest1.py, so when we try to make changes to the program (see next step), we won't run the risk of messing up a working program that we may need for reference.

nano: file editor

nano myTest1.py
There are a number of file editors available, but we'll use nano because it's easy enough. Here we open the file for editing.
If you change the number "2" in the last line of the myTest1.py file to, for example, "5" you'll change which light lights up. We're old-school here, so you won't be able to use the mouse to navigate through the file, you'll have to use the arrow keys. Since you already know the command to run the program, so you can test to see if your changes worked.