CPSC 226 Lab Nine Fall 2015 Directions. Our overall lab goal is to learn how to use BBB/Debian as a typical Linux/ARM embedded environment, program in a traditional Linux C programming environment, and essentially get ready for our next lab where we start to program in ARM assembly language. In this lab we move beyond the Arduino platform to a more advanced, but not significantly larger, hardware environment: BeagleBone Black (BBB). This board uses an ARM processor running at a much higher clock speed than Arduino, supports a number of multi-tasking and multi-user operating systems such as Linux/Debian, has built-in Ethernet and HDMI video output as well as providing low level digital and analog pin accessibility. BBB costs about $45 and is part of a rapidly expanding list of hardware offerings of powerful embedded computers running full featured operating systems such as Debian, Ubuntu, Android, and Windows 10. These operating systems bring the ability to run multiple processes with multiple users, provide better security, USB host capability, Internet protocols, and choices of GUI and command line interfaces. All in a physical envelope that can fit in an Altoids mints tin box. There are many similar embedded hardware projects happening right now which you may want to investigate as options for powering the Internet of Things (IoT). Currently active projects are Raspberry Pi, BeagleBone, Intel Atom/Arduino Edison, Galileo, Arduino Yun, Freescale, ST, and others. There is to some extent a mix-and-match frenzy of porting various operating systems to these boards. This may be a very tedious process depending on the particular hardware and software vendors. Below are some links to a few examples if you want to learn more about installing a new OS on an embedded system. Do not fear, we will NOT be doing this stuff in our lab. Running Windows 10 IOT Core on Raspberry Pi:https://www.youtube.com/watch?v=Oo_gNL-zkuY Installing Android on Raspberry Pi: https://www.youtube.com/watch?v=z9jezo0rhoc Installing Android on BeagleBone Black: http://beagleboard.org/getting-started You should read through this entire lab before beginning the various parts so you know where we are going. You will need to bring a laptop to lab for programming BeagleBone Black. I will supply all the other materials needed. Your nicely typed and edited group lab writeup is due Friday in class as usual. My previous comments about high quality lab reports remain in effect for the remainder of the semester. Prelab Exercise 1. BeagleBone supports a variety of communication channels but a nice feature is to use IP (Internet Protocol) over USB. The process for this is nicely laid out in this tutorial link below which you should read through now: Setting up BeagleBone Black using IP over USB: https://learn.adafruit.com/ ssh-to-beaglebone-black-over-usb Exercise 2. Before we get into connecting to BBB, you will need to install some software on your laptop which was mentioned in the tutorial. For Windows users. Download and install Putty, or another SSH (Secure Shell) terminal program, on your laptop. You can test Putty after installation by connecting to the math.hws.edu server using ssh and logging in with your user name and password. You should have this working before you come to class.
For Mac users. You can use the standard Terminal program on OSX for what we will be doing in the lab or investigate other ssh clients of your choice. You can find easy introductions to Linux shell commands at http://cli.learncodethehardway.org/bash_cheat_sheet.pdf and ueb.vhir.org/dl1290. Whichever system and software you use, connect with ssh to the math.hws.edu server using your Linux username and password. Practice moving around in the Linux directory structure and see what is there including your files and directories. One very useful tip to remember is that Up Arrow key on your keyboard steps back through the commands you just issued so when doing repetitive kinds of actions you can simply recover the previous commands. Another useful feature is auto-complete. If you have a file named mylongfilename.c and you want to display its contents you can simply start the cat command then just enter the first characters of the file name then press the tab key cat mylon <tab> and it will autocomplete the file name to give you cat mylongfilename.c and you can press Enter to carry out the command. Exercise 3. Make some files and directories, list file contents, delete some of the files you created, etc and generally practice some Linux command line commands. Use the nano command so you see what the world s most simplistic command line text editor looks like. The ctrl-x command exits nano and you can probably figure out what the others do by yourself. Another useful tool to share files with BBB is an SFTP (Secure File Transfer Protocol) client such as WinSCP, PSCP, or FileZilla, just to mention a few options. There are many free and easy to use choices here. Exercise 4. Download and install an SFTP client of your choice. After installation, practice sending and copying files from the math.hws.edu server so you get used to the particular interface your program uses. Exercise 5. Finally, return to https://learn.adafruit.com/ssh-to-beaglebone-black-over-usb and, without plugging in a BBB, install the appropriate drivers indicated for your laptop, either Windows or Mac. You now should be ready to communicate with BBB in the upcoming lab. End of Prelab Today we are going to get comfortable using an SSH connection to a BBB board, practice using some Linux utilities, including editing and compiling some simple C programs on BBB. IMPORTANT: When using BBB on a table top, make sure there are NO stray pieces of wire or solder on the table that can short circuit underneath the board itself. Safely starting/stopping BBB is simple but you need to be careful to avoid damaging the board. DO NOT SIMPLY UNPLUG THE USB CABLE WHEN BBB IS RUNNING. THIS CAN DAMAGE THE BOARD.
To safely shutdown BBB, there are several methods listed in decreasing order of preference. a) At the Debian prompt (explained below), type shutdown -h now and press return. Wait to get confirmation of the mounted USB volume being dismounted and the blue LEDs stop blinking, then unplug USB. b) Soft shutdown by pressing then releasing the power button next to the Ethernet connector. Wait until LEDs stop flashing then unplug USB. c) Hard shutdown by holding down power button for 8 seconds until LEDS stop flashing then unplug USB. Getting started with BeagleBone Black Plug in your USB-mini cable to BBB and wait until the blue LEDs fall into repeating flashing pattern AND you will find that BBB has mounted as an external USB device named boot or BeagleBone which you can open and browse. Double click on the START.htm file which opens your web browser (don t use Internet Explorer!) and shows the BBB guide on the steps needed for getting started. You have already completed Steps #1 and #2 so you should be able to communicate with BBB using our SSH and SFTP tools Exercise 6. Open your SSH client and connect to BBB using these (case sensitive) credentials User: root Password: (none) IP address: 192.168.7.2 You should get a typical Linux logon notice and system prompt something like root@beaglebone: Note: Sometimes a previously used BBB will cause ssh to throw an authentication error with this type of response: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@... and lots of scary sounding stuff here... Don t panic, you can regenerate a host key by using this command: ssh-keygen -R 192.168.7.2 Afterwards, you can connect as usual after affirming you want to add the new host entry. Exercise 7. Use your Bash shell commands cd, ls, pwd, nano etc, just like you did on math.hws.edu to move around the BBB directory structure, see what you find. Don t delete files and directories you encounter or this is pretty much going to end badly. Debian is just another Linux distro so all the usual Linux commands (or close variants) should work here. BBB has no battery-backed clock so it may record the current time as completely wrong so let s fix that first. Use the date command to see the current date and time. If this needs changing, use the correct date and time like
date -s 17 NOV 2015 11:30:00 to set the operating system date and time. To set the hardware clock to the software clock use hwclock systohc. Exercise 8. C-programming in BBB. Let s create a directory to practice some C-programming in our BBB environment. Change your directory to /home/debian/desktop and make a new directory named cpsc220. Inside that directory, use nano to edit and save a C source code file named prog1.c that looks like so: #include <stdio.h> int main (void ) { printf("%s", "Hello World\n"); return 0; } This is the standard C Hello World program but now in its natural environment, Linux/Unix. Notice we include a library to handle the I/O of printing a string formatted using a format specifier. Compile your C program using the command flag -o which indicates what the output executable file should be named from your source.c file: gcc -o prog1 prog1.c If there are compilation syntax errors, fix them in nano, save again, etc. Run your executable with the command./prog1 and see that we get our expected output. When you get this working, include your source code in your writeup. Exercise 9. Let s write another C program but with user input this time. Use nano to edit the program below and save it as prog2.c. Get it to compile and run and notice it does NOT always produce the expected output. Why is that? Do a search for problems with scanf and see how to fix this issue. Include your improved version that faithfully echoes what the user typed in your writeup. #include <stdio.h> int main (void ) { char mystring[100]; scanf("%s", &mystring); printf("you entered %s \n", mystring); return 0; } Exercise 10. Remember our prime number listing program? Design, write, and debug a program written in plain C which accepts a decimal integer number (look up the scanf format!) and then prints all the prime
numbers up to the number entered by the user. So, if the user entered the number 12, the program would print the numbers 2, 3, 5, 7, 11. This program should run very quickly on BBB so give it some large values and see what you get. Include your source code with your lab. You are no doubt annoyed by all the repetitive typing needed to compile these C programs. We can help ourselves by using the make utility in Linux. I will discuss this in class and demonstrate how to use a Makefile to partially automate your compilation of programs. For now, below is a simple Makefile that can be used in BBB to compile any of three C programs we are working on. Exercise 11. Explain in your own words what the commands in the Makefile do and how is the Makefile used to help with our compilation overhead. # Typical Makefile to build applications in C. # The compiler is gcc. Exchange g++ to use C++ CC = gcc # compiler flags: # -g adds debugger information to the executable file # -Wall turns on most, but not all, compiler warnings # -I. sets the include default directory to the current one CFLAGS = -g -Wall -I. # The build target executables: all: prog1 prog2 prog3 prog1: prog1.c $(CC) $(CFLAGS) -o prog1 prog1.c prog2: prog2.c $(CC) $(CFLAGS) -o prog2 prog2.c prog3: prog3.c $(CC) $(CFLAGS) -o prog3 prog3.c clean: $(RM) prog1 prog2 prog3 When you are done, use the shutdown -h now command for BBB and let it fully shutdown and turn off all its blue LEDs before you unplug the board. You are done with the lab. End of lab