CMPEN 352W RPi configuration
Instructions for getting the RPi configured for CMPEN 352W
- Go toRaspberry Pi, click on RASPBIAN, and downloadthe RASPBIAN JESSIE-LITE Zip file. The download will take a while. Unzip the file and store it somewhere safe.
- Go toImage Writer for Windowsand download by clicking on the Green "Download" tag. Unzip and store somewhere safe.
- Insert the SD card into your computer; make sure the lock slider is in the unlocked position.
- Launch Win32DiskManager and open the 2016-02-26-raspbian-jessie-lite.img and write to the SD card.
- Insert the SD card into the RPi, attached an Ethernet cable and then power-up through USB powered through a wall adapter (you will not have much luck powering from your laptop or PC USB as they cannot deliver enough power).
- Log into your router and get the following information. I had to look in the Device List and I found a device called "raspberrypi" with IP address 196.168.0.105.
- Launch putty and enter in the IP address from step 6 above
- Congratulations, you are now root on your very own Linux machine!
User name: piPassword: raspberry
In the instructions that follow, there are many commands that you will need to issue to the RPi. In all cases these instructions are printed in courier font – the default font used in SSH when communicating to the RPi.
Update apt-get
There are plenty of programs that are not installed on the RPi by default in order to save space. Here are a few that we will need. In order to install these, you have to be connected to the Internet, because you will need to download files. First you will need to install the latest version of the updater program.
pi@raspberrypi:~$ sudo apt-get update
Configure RPi System
The RPi Software Configuration Tool (raspi-config) allows you to configure some important system-level features.
pi@raspberrypi:~$ sudoraspi-config
Use the up and down arrows to select the numbered items. Use the right and left keyboard arrows to select <select> and <finish>
select:9 Advanced OptionsConfigure advanced settings
select:A0 Update (all the way down)Update this tool to the latest version
select:1 Expand FilesystemEnsures that all of the SD card s
select:Finish
After you select finish, you will need to reboot.
Python Serial
Next install Python's serial library. You can find some good information atSource Forge or here:
pi@raspberrypi:~$ sudo apt-get install python-serial
With this done, its time to configure the serial port to work with our Pi’16 board. This will take a little configuration of the Linux environment as follows.
pi@raspberrypi:~$ sudonano /boot/cmdline.txt
Initially it looked like:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
After removing the commands associated with ttyAMA0 it looks like this.
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Disable the serial getty service.
pi@raspberrypi:~$ sudosystemctl disable ice
Install the seral toolbox. When you do this, answer ‘Y’ when the prompt asks if you want to take an additional 14.5MB of storage.
pi@raspberrypi:~$ sudo apt-get install python-pip
pi@raspberrypi:~$ sudo pip install pyserial
Go tomintermand copy the python script into the buffer. On the RPi paste this code into a file called mini.py. When you run the mini program you will immediately be prompted to enter the serial port, in our case its /dev/ttyAMA0
pi@raspberrypi:~$ python mini.py
Enter port name: /dev/ttyAMA0
--- Miniterm on /dev/ttyAMA0: 9600,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
miniterm is a terminal interface that runs on the RPi, allowing you to interact with the Pi'16 board, in exactly the same way that Hyperterminal is a terminal interface that runs on a PC allowing you to interact with the Pi’16. Yes, the PIC18F26K22 has two serial ports, one pointed to the PC through the FT232 chip and the other through the header at the top of the Pi’16 board. In order to test the whole thing, downloadlab9.hex( on to your Pi’14 through the PICKit3, solder in the 20 pin header, run miniterm and you should be able to execute the Lab3 test program except through the RPi. Sometimes I find that I have to toggle the reset in MPLAB X (see image below) in order to get the lab9.hex file to run.
If you do not like miniterm, you can use the screen command, but first you will have to install it. You will be on your own if you use this as I am not familiar with its operation.
pi@raspberrypi:~$ sudo apt-get install screen
pi@raspberrypi:~$ sudo screen /dev/ttyAMA096000 8N1
NGINX
NGINX is a light weight web server that will allow you to write embedded web apps. This installation will take at least 30 minutes, so plan accordingly.
pi@raspberrypi:~$ sudo apt-get install nginx
pi@raspberrypi:~$ sudo apt-get install php5-cgi php5-fpm php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
sudonano /etc/php5/fpm/pool.d/
##EDIT - listen = /var/run/php5-fpm.sock
##TO - listen = 127.0.0.1:9000
pi@raspberrypi:~$ sudonano /etc/nginx/nginx.conf
Delete all file contents and replace with the contents of nginx.conf
pi@raspberrypi:~$ sudonano /etc/nginx/sites-available/default
Delete all file contents and replace with the contents ofdefault
Change the ownership of the web directory so you can more easily add files.
pi@raspberrypi:~$ sudochown pi /var/www
pi@raspberrypi:~$ sudo service nginx restart
pi@raspberrypi:~$ sudo service php5-fpm restart
Give web applications permission to access the serial port at: /dev/ttyAMA0
pi@raspberrypi:~$ sudousermod -a -G dialout www-data
pi@raspberrypi:~$ sudochmod 777/dev/ttyAMA0
In order for the web interface to the access the services on the RPi, you will need to grant the user www-data super user capability.
pi@raspberrypi:~$ sudochmod 700 /etc/sudoers
pi@raspberrypi:~$ sudonano /etc/sudoers
add the following to the last line of the file:
www-data ALL=(ALL) NOPASSWD: ALL
Save and close the file, then change the permissions back.
pi@raspberrypi:~$ sudochmod 440 /etc/sudoers
Create wired connection to your home or PSU network via eth0.
pi@raspberrypi:~$ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:6b:ed:47
inet addr:10.96.1.120 Bcast:10.96.1.255 Mask:255.255.255.0
inet6 addr: 2605:a000:122e:4052:7411:c069:6a75:39db/64 Scope:Global
inet6 addr: fe80::2bda:1801:53a8:6dfe/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:211 errors:0 dropped:0 overruns:0 frame:0
TX packets:181 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:23607 (23.0 KiB) TX bytes:27698 (27.0 KiB)
wlan0 Link encap:Ethernet HWaddr 00:1f:1f:09:0a:e7
inet addr:10.96.1.105 Bcast:10.96.1.255 Mask:255.255.255.0
inet6 addr: 2605:a000:122e:4052:227c:99b:1:948/64 Scope:Global
inet6 addr: fe80::a826:c336:c85:774b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44 errors:0 dropped:10 overruns:0 frame:0
TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5566 (5.4 KiB) TX bytes:7113 (6.9 KiB)
You will need to get the HWaddr(MAC address) from eth0 (the ethernet port on the RPi). Write this down on the list maintained by Dr. Coulston. Note, in the above example, you can tell that I had my both my wired (eth0) and wireless (wlan0) connected to my home router because both IP addressed (called inetaddr) are 10.6.1.XXX which is reserved for private networks.
I have setup my wireless interface to connect to either my home network or the Penn State wireless network, whichever is in range. In order to do this you will make changes to two file.
pi@raspberrypi:~$ sudonano /etc/network/interfaces
The names “work” and “home” are links to the wpa_supplicant file which is the next one you will edit.
pi@raspberrypi:~$ sudonano/etc/wpa_supplicant/wpa_supplicant.conf
Since it’s a bad idea to store passwords (pugpuppies) in plaintext, you should encrypt them whenever possible. Fortunately, my home network runs wpa-psk which allows me to encrypt my network password as follows:
pi@raspberrypi:~$ wpa_passphrasemyHomeNetworkNamepugpuppies
network={
ssid="myHomeNetworkName"
#psk="pugpuppies"
psk=7ecb80e7f6c847701458e71eda22b542757cad99ff38bb444149d202a2bfb7f8
}
After you make these changes you will want to verify that they work before pulling your Ethernet cable. Plug in your wireless adapter and then try starting and stopping your wireless adapter using the following commands:
pi@raspberrypi:~$ sudoifdown wlan0
pi@raspberrypi:~$ sudoifup wlan0
If there are no errors when you bring the wireless adapter up (using ifup), then try pining an external web server using the wlan0 interface. I always choose honda.com because it would be very unusual if all of Honda’s web servers were offline.
pi@raspberrypi:~$ ping honda.com -I wlan0
Please take a moment to change the password of the pi account on your RPi.
Change root password
pi@raspberrypi:~$ passwd
In order to run the SSH client available at: add the following to the end of /etc/ssh/sshd_config:
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,arcfour
KexAlgorithms diffie-hellman-group1-sha1
Raspberry Pi setup instructions – CMPEN 352W – Spring 2016Page 1