$35
Outline
In this first lab, we will go through the following steps:
Part 1:Assemble the lab kit for ECE5725 o Install and configure the Raspbian Linux kernel
Part 2:Install and configure drivers and software for the piTFT display o Install and configure drivers and software for video and audio playback
Part 3:Develop Python scripts to control playback on the screen using physical buttons installed on the piTFT boar
Lab safet
We have all been in lab before and handled electronic components. Please apply all the cautions that you have learned including the items below:
Integrated electronics are REALLY susceptible to static discharge.
Avoid walking around while holding bare components
Confine assembly to a single location and discharge static electricity frequently
Personal safety
Safety goggles are REQUIRED for soldering (even if you solder at home!)
Experimental Safety
If something on your board is o Really hotSmoking
Just doesn’t look right
Immediately unplug power
Train yourself so that this is your first reaction; know where the power switch/cutoff is for your experiment
Parts of the ECE5725 kit
Raspberry Pi 4 Model B
5V, 2.5A power adapter (USB-c)
16 GByte SD card (mini card in SD carrier)
2.8 inch TFT screen
USB Keyboard and Mouse (if available)
DVI connected display (if available)
DVI to HDMI adapter
40-pin breakout cable
Ethernet cable
Notes before you start:
The R-Pi is powered up at the END of this assembly AFTER you show your assembly to the TA.
The 40-pin GPIO connectors are NOT keyed. This means they will fit in a number of different orientations. Check that your assembly matches the photos AND check your assembly with the TA before applying power.
Initial assembly and start up:
In the following order, assemble all the components (please don’t forget to discharge static electricity) Here is a photo of the initial system elements:
Elements of the ECE5725 Lab system: from top, left to right, RPi 4 case and cover, PiTFT display, RPi 4, Pi breakout cable and 40-pin cable header, 5V, 3.0 amp power supply, Ethernet cable, HDMI cable.
Assemble your system using the following steps:
Unpack the R-Pi
Install the R-Pi in the bottom of the R-Pi case. To install the RPi in the case, Align the RPi so they the connectors are oriented correctly in the case.
Set the RPi over the 4, round standoffs in the case
Apply gentle pressure until the RPi ‘seats’ into the case, snapping into the standoffs.
Note that use of the bottom half of the case provides some additional protection against ESD damage for the RPi electronics
The top of the case will not be used. Please save the top of the case along with your other kit parts.
These photos show the RPi placed in the case (left) and the side view of the RPi in the case showing the correct alignment of the RPi connectors (right).
Next assembly steps:
Unpack the TFT
Unpack the breakout cable.
Install the breakout cable on the underside of the TFT (the reverse of the display side). Shown below is the underside of the piTFT showing the connectors. The breakout cable is shown on the left side of the piTFT:
This photo shows the breakout cable (left) and the underside of the piTFT including the
40-pin connectors
Plug the TFT into the RPi 40 pin GPIO connector.
Below is a photo of the piTFT, with the cable correctly plugged, shown next to the RPi.
Note that the cable is oriented correctly in the photo below. The white stripe on the cable is shown on the left side of the PiTFT. In this orientation, the, white stripe of the cable will be under the 4 PiTFT buttons.
When plugging the cable, pay special attention:It is easy to mis-plug the 40-pin cables either off by one row or by one column. Check that your cable is correctly aligned with all 40 pins.
The 40-pin connectors take some special care to plug and unplug. Work the connectors slowly from side to side rather than trying to plug, or unplug, the cable in one motion.
This Photo shows the correct installation of the expansion cable on the back of the piTFT display. Note the position of the white stripe on the cable relative to the piTFT
Flip the screen onto the RPi and carefully plug the screen into the 40-pin connector on the RPi. Your completed R-Pi, PiTFT screen, and breakout cable should look like the photos, below.
Note that the white stripe on the cable is positioned next to the small ‘1’ on the pin side of the piTFT. The white stripe on the cable should be under the buttons on the side of the TFT screen.
Note that the breakout cable header is not installed in the photos (save this part in your parts box; it will be installed in later labs):
The above photos show the piTFT positioned on the RPi just before installation (left) and the piTFT correctly installed on the RPi 40-pin connector (right)
In the above photos, note the instillation of the PiTFT on the RPi. In the previous step, you installed the breakout cable on the back of the PiTFT. Now, position the PiTFT (with cable installed) over the RPi and plug the 40 pin connector socket on the underside of the PiTFT to the 40 pins on the PiTFT. Make sure the pins and socket are lined up before you plug everything together. See the photos above for guidance
Once this assembly step is completed, extract the mini SD Card from the carrier and insert in the bottom slot of the R-Pi. Note the correct position of the mini-SD.
Accessing the Raspberry Pi:
For Fall 2021, you will use a USB keyboard, USB mouse and an HDMI monitor. At your lab station, there should be an HDMI cable attached to the monitor, USB mouse and USB keyboard. Plug each of these into the appropriate adapters on the RPi. DO NOT plug in power yet…see the next step.
Before you power-up your system:
Show the TA your setup
Double check: HDMI must be plugged in before booting the RPi
Plug in the mini-USB connector from the power adapter
Plug adapter into 110V outlet
Once you plug in your RPi, you should notice a tiny red LED and a tiny blinking green LED.
Important Note: Top 10 Linux Commands, shutdown and power-off
When you need to power off the R-Pi, please use the following commands:
Issue the command
sudo shutdown –h now which instructs Linux to enter a ‘shutdown’ state.
Once on-screen messages are completed and the green LED on the R-Pi stops flashing, unplug power. Note that the flashing green led on the RPi indicates that the RPi is accessing the SD card
It is best to unplug the 110V power adapter rather than the mini-USB adapter (on the R-Pi board).
To restart without powering down, Issue the command
sudo reboot which instructs Linux to restart the operating system.
Initial Raspbian Kernel install
As part of Homework 1, you should have setup your SD card with the correct version of the Raspbian kernel; We will be starting with the latest Buster release, 5.4.83-v7l+
If you are using an HDMI monitor, the system should boot to the Raspbian desktop. We will use the raspi-config tool which will start a configuration utility to assist in setting up the Raspbian kernel.
There are some raspi-config details (for reference only) in the following links:
https://www.raspberrypi.org/documentation/configuration/raspi-config.md
general configuration link:
https://www.raspberrypi.org/documentation/configuration/
Raspi-config helps with some standard Linux install tasks that you can also run via the Linux command line, or by modifying Linux config files.
If using an HDMI monitor, an initial install of the Raspbian Buster kernel booted directly to the Raspbian Desktop. DO NOT hit ‘NEXT’ in the prompt that appears on Reboot. Hit CANCEL instead:
Another instance of the kernel booted to the following screen. In this case, hit ‘SKIP’:
If you see this screen, or a similar ‘helper’ screen, please hit ‘skip’.
You want to skip any auto-config screens so you will have a better idea of what files are changing to configure the Linux kernel; you will learn linux by osmosis!
Once the system boots, if you have a desktop, find the terminal icon and open a terminal window.
If your system boots to a command line interface, you are ready to go.
From the command line interface, enter the following commands:
Run the following commands to get some system information including the OS version
pi@raspberrypi:~ $ whoami pi
pi@raspberrypi:~ $ hostname raspberrypi
pi@RPi-jfs9:~ $ uname -a
Linux RPi-jfs9 5.4.83-v7l+ #1379 SMP Mon Dec 14 13:11:54 GMT 2020 armv7l GNU/Linux
pi@raspberrypi:~ $ cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"pi@raspberrypi:~ pi@raspberrypi:~ $ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 169.254.190.227 netmask 255.255.0.0 broadcast
169.254.255.255
inet6 fe80::a0a1:60d4:aeb5:89ef prefixlen 64 scopeid
0x20<link>
ether dc:a6:32:e4:13:72 txqueuelen 1000 (Ethernet)
RX packets 162 bytes 68748 (67.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 121 bytes 23010 (22.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions0
After having a brief look at the system, continue with the following install steps:
issue the command ‘sudo raspi-config’
In the ‘system options’ select ‘S5 Boot / Auto Login’ then ‘B1 Console’
This change will boot directly to the console window on the next RPi reboot. Since you are already in raspi-config, continue with the notes below for more configuration.
Working your way through the config screens, please make sure to apply the following settings:
In ‘system options’, ‘S3 Password’, Change the pi user password to something you will remember!Important Note: If your keyboard has a keypad, DO NOT use this to enter any Password information
In ‘System Options’, select ‘S4 Hostname’: set a unique hostname to ‘netid-netid’ where ‘netid-netid’ are the Cornell netids of the two team members in your group.
Note: If WIFI is already setup on your RPI, you may skip this step. To configure (or check) your WIFI connection, in ‘System Options’, select ‘Wireless Lan’.
There will be screen prompts for ‘SSID’, the same of your WIFI network, and ‘Passphrase’, the password for your WIFI network. If all is well, you can later check the WIFI connection by running ‘ifconfig -a’ and verifying that there is an IP address associated with the wlan0 adapter (as discussed in class). When I tried this method, I also had to run the following commands:
The ‘rfkill unblock’ command allows the WIFI adapter to start
The ‘wpa_cli’ command restarts the WIFI adapter
For Localization options:Change locale:Use the arrow keys, and tab to navigate Use the Spacebar to select / de-select § De-select ‘en_GB.UTF-8 UTF-8’.
Set the Locale by selecting ‘en-us.UTF8 UTF8’.
When prompted, select ‘None’ for the Default Locale
This clip shows the selection of the en_GB locale. You will unclick this selection
This clip shows the correct en_US setting
Change Timezone
Change the timezone to match your location. In Ithaca, for example, I would set the time zone as follows:
Set the geographic area to US
Set the Time Zone to ‘Eastern’
Select Finish. If a pop-up asks ‘reboot now?’ Click, yes. If not, enter ‘sudo reboot’ to reboot the system at this point.
Once the system restarts:
The command you initially used to log onto the RPI;
ssh pi@raspberrypi.local
will now have to be modified to:
ssh pi@New-Hostname.local
To match the new hostname you issued in the previous step. When prompted, you will also need to use the new password you just set for the ‘pi’ user.
Login as user ‘pi’
Enter your new password
Once logged in, run ‘sudo raspi-config’ to continue with configuration.
If you have a keyboard plugged into the RPi, you need to configure the keyboard layout. If you don’t have a keyboard, please skip this step:
In localization options:
Select ‘Keyboard’ and make the following changes:‘Generic 101 key PC’ keyboard
select ‘Other’, then ‘English US’
‘configuring keyboard-configuration’
select ‘English (US)’ (Note, there may be 2 selection screens for ‘English (US)’
next, select ‘The default for the keyboard layout’
next, select ‘no compose key’
finally, select ‘YES’ to allow “Ctrl-Alt-backspace to exit the X server”
Why these settings? These are the best settings for the time, keyboard and mouse you will be using.
Additional configuration:
In ‘Interfacing Options’: enable ssh Don’t need to do this! You already set it up as part of HW 1
In the ‘Advanced Options’ settings o A1, expand the file system
In the ‘System Options’ settings o S2, Audio, Select “Headphones”
Update: update the raspi-config tool to the latest version
Once you hit ‘Finish’, raspi-config will save your changes and ask if you want to reboot now. Answer ‘yes’.
If it does not ask for a reboot, issue the following command:
pi@raspberrypi:~ $ sudo reboot
To reboot the RPi.
Note that you can always run raspi-config to adjust configuration settings at a later time.
Updates
Once the system boots to the command line, login as the pi user
Check for Raspbian kernel upgrades by running the following two commands:
sudo apt-get update
sudo apt-get full-upgrade
If you watch the screen during these operations, you will notice the packages that are loaded and installed to update the kernel.
The upgrade could take a few minutes.
Important Notes:
Watch the update and upgrade as they proceed. The commands print a lot of cryptic messages on progress (most Linux commands print console messages). In this case, look for messages that state:
Unable to resolve 192.168.10.20 # where 192.168.10.20 is some IP address
This means that the update command is having problems getting to the server and the update will not be complete.
You may have to answer some questions for the upgrade to proceed. Read the comments and answer the prompts to allow the upgrade to continue.
Once upgrade is completed:
Reboot to start the upgraded kernel
Once updates are done, run:
‘sudo reboot’ # to reboot the system
You can also shut down the system cleanly using:
‘sudo shutdown –h now’
To restart the system after a shutdown, cycle power on the RPi.
Note: ‘sudo shutdown –h now’ should always be run before you unplug the R-Pi setup. The shutdown command allows Linux to gracefully shutdown all processes before the system is powered down.
have a look at the ‘shutdown’ command to explore the –r and –h flags
Run ‘uname –a’ to show the updated kernel version.
pi@RPi-jfs9:~ $ uname -a
Linux ece5725-f21 5.10.52-v7l+ #1441 SMP Tue Aug 3 18:11:56 BST 2021 armv7l GNU/Linux
Note; There are many pages about the Raspberry Pi. If you stumble across this command, NEVER run:
DO NOT RUN !!! > ‘sudo rpi-update’ (This loads the latest, un-released, un-tested, development kernel)
… just a warning, because you might see this as you wander the online R-Pi pages
Load an update for the vim editor:
‘sudo apt-get install vim’
If you are using an HDMI connected monitor, From the command line issue the command ‘startx’
Once in the desktop, exit back to the command line window using
‘ctrl-ALT-BACKSPACE’
which you setup earlier using the raspi-config tool
Once you have a command line window running on the desktop, try some simple checks: • ‘hostname’
‘ifconfig –a’ to check network connections
‘cat /proc/cpuinfo’ to check the number of cores
‘time date’
‘htop’ # Note, exit htop with ‘CTRL-C’
If you are using an HDMI monitor, using putty (on windows) or terminal (on mac), login to the R-Pi to make sure you can! From your laptop, you will use secure shell. An example (on a Mac) is:
ssh pi@123.456.78.90
Where pi is the username and 123.456.78.90 is the IP of your ‘wlan0’ WIFI connection.
A Word of caution: You can load a lot of programs on RPi. Sometimes, the installs can drop into many different directories and create large files. In later labs, we might need additional free space to proceed and it may be difficult to recall what was installed and how to get rid of it. You are indeed encouraged to explore. Here are some tips for keeping your SD card trim:
You may want to consider a second SD card for loading experimental applications
Keep a list of all installed apps (and how to completely remove them)
Use list of best practices for good SD card behavior
Keep backups as you go…restore one of the cleaner backups during a later lab if you are running out of space.
At this point, the RPi contains a clean install of the latest Raspbian kernel.
Backup the SD card!
You will thank us later……
TFT Screen Install
In past classes, we have used a detailed set of instructions posted on the Adafruit site to install the piTFT. When Stretch was released (mid-August, 2017), the instructions failed as the techs at Adafruit had not yet had a chance to update the installation instructions. As a result, for the Fall, 2017 version of the class, we downgraded to the last stable version of Jessie to be able to use the piTFT.
This semester, the instructions on the Adafruit site still do not work. However, there have been some discussions on for forums and there seems to be a workable solution to install the piTFT. The following instructions provide details:
Install software to support the piTFT:
Run:
sudo apt-get install -y bc fbi git python-pip python-smbus python-spidev evtest libts-bin
The python-pip application is used to install python packages on the Pi. The evtest and libts-bin applications are used for testing the piTFT.
Bad example:
The following shows an example of a failed installation; you might see something like this and it is important to read through the messages to determine what is going on:
pi@RPi-jfs9:~ $ sudo apt-get install -y bc fbi git python-pip python-smbus pythonspidev evtest libts-bin Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libts-0.0-0' instead of 'tslib' git is already the newest version (1:2.11.0-3+deb9u4). python-smbus is already the newest version (3.1.2-3). python-pip is already the newest version (9.0.1-2+rpt2).
python-spidev is already the newest version (20170223~145721-1). The following additional packages will be installed: evemu-tools ghostscript gsfonts libevemu3 tsconf
Suggested packages:
imagemagick ghostscript-x
The following NEW packages will be installed:
bc evemu-tools evtest fbi ghostscript gsfonts libevemu3 libts-0.0-0 libts-bin tsconf
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,480 kB of archives.
After this operation, 5,494 kB of additional disk space will be used.
Get:1 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf tsconf all 1.0-12 [13.4 kB]
Get:2 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf libts-0.00 armhf 1.0-12 [25.8 kB]
Get:3 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf bc armhf 1.06.95-9 [96.3 kB]
Get:4 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf libevemu3 armhf 2.6.0-0.1 [11.0 kB]
Get:5 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf evemutools armhf 2.6.0-0.1 [14.1 kB]
Err:6 http://raspbian.raspberrypi.org/raspbian stretch/main armhf ghostscript armhf
9.26~dfsg-0+deb9u2
404 Not Found [IP: 93.93.128.193 80]
Get:7 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf fbi armhf 2.10-2+b1 [53.5 kB]
Get:8 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf gsfonts all 1:8.11+urwcyr1.0.7~pre44-4.3 [3,126 kB]
Get:9 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf libts-bin armhf 1.0-12 [28.6 kB]
Get:10 http://mirror.us.leaseweb.net/raspbian/raspbian stretch/main armhf evtest armhf 1:1.33-1 [13.2 kB]
Fetched 3,381 kB in 3s (952 kB/s) E: Failed to fetch
http://raspbian.raspberrypi.org/raspbian/pool/main/g/ghostscript/ghostscript_9.26~d fsg-0+deb9u2_armhf.deb 404 Not Found [IP: 93.93.128.193 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fixmissing?
Note the messages ‘Not Found’ and ‘Failed to fetch’. These indicate there were some issues with loading the applications. There is a hint in the last message to run some commands to try and fix the problem. Running apt-get update, as suggested in the message, led to the following example.
Good Example:
pi@RPi-jfs9:~ $ sudo apt-get install -y bc fbi git python-pip python-smbus pythonspidev evtest libts-bin Reading package lists... Done
Building dependency tree
Reading state information... Done git is already the newest version (1:2.20.1-2).
python-smbus is already the newest version (4.1-1).
python-pip is already the newest version (18.1-5+rpt1).
python-spidev is already the newest version (20170223~145721-2).
The following package was automatically installed and is no longer required: rpi.gpio-common
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed: evemu-tools ghostscript gsfonts libevemu3 libts0
Suggested packages:
imagemagick ghostscript-x
The following NEW packages will be installed:
bc evemu-tools evtest fbi ghostscript gsfonts libevemu3 libts-bin libts0 0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
### Many more lines of installation
Run the command: sudo pip install evdev
Example:
pi@RPi-jfs9:~ $ sudo pip install evdev
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting evdev Downloading
https://files.pythonhosted.org/packages/89/83/5f5635fd0d91a08ac355dd9ca9bde34bfa6b2
9a5c59f703ad83d1ad0bf34/evdev-1.3.0.tar.gz
Building wheels for collected packages: evdev Running setup.py bdist_wheel for evdev ... done
Stored in directory:
/root/.cache/pip/wheels/3e/8d/02/a7f482e01af02be59232ad61ad8eed5b21156b49d32df64a11
Successfully built evdev
Installing collected packages: evdev
Successfully installed evdev-1.3.0
Add piTFT info to config.txt
Edit the file /boot/config.txt and add the following lines to the end of the file. Note that the /boot/config.txt file is accessible by administrators so you must use ‘sudo’ when editing:
# Added for piTFT
[pi0]
device_tree=bcm2708-rpi-0-w.dtb
[pi1]
device_tree=bcm2708-rpi-b-plus.dtb
[pi2]
device_tree=bcm2709-rpi-2-b.dtb
[pi3]
device_tree=bcm2710-rpi-3-b.dtb
[all] dtparam=spi=on dtparam=i2c1=on dtparam=i2c_arm=on
dtoverlay=pitft28-resistive,rotate=90,speed=64000000,fps=30
Notes
Comments in this file begin with leading #
Pay attention of upper and lower case
Watch for differences in underscore “_” and dash “-“
The various device_tree settings include code for the appropriate Pi model.
The ‘rotate’ setting is used to rotate the screen 0, 90, 180, or 270 degrees. We will be using a landscape rotation of 90 degrees.
The speed setting is used by the driver to determine how fast to drive the display. 64Mhz (64000000) is the suggested setting. We might decide to reduce this to 32MHz at some point.
Once these changes are in place, reboot the RPi and observe the startup sequence. If all is well, the PiTFT screen should start out white and switch to black as the boot sequence finishes. If this happens, the initial changes are working correctly.
Run dmesg to check for piTFT
At this point, run dmesg to see that the modules for the touch screen are installed correctly. In particular, look for the “stmpe-spi” and ‘graphics fb1” lines (highlighted in the example below.
Notes:
The chipID is for the resistive touch circuits on the PiTFT
Note the settings in the “graphics fb1” entry; some of these were set in previous steps.
Example dmesg output:
[ 2.724715] random: systemd: uninitialized urandom read (16 bytes read)
[ 2.740661] random: systemd: uninitialized urandom read (16 bytes read)
[ 2.746520] systemd[1]: Created slice system-systemd\x2dfsck.slice.
[ 2.746806] random: systemd: uninitialized urandom read (16 bytes read)
[ 2.748174] systemd[1]: Created slice User and Session Slice.
[ 2.748332] systemd[1]: Reached target Swap.
[ 2.748441] systemd[1]: Reached target Slices.
[ 2.886203] i2c /dev entries driver
[ 3.539274] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[ 3.670884] systemd-journald[108]: Received request to flush runtime journal from PID 1
[ 4.279025] vc_sm_cma: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.282061] bcm2835_vc_sm_cma_probe: Videocore shared memory driver
[ 4.282086] [vc_sm_connected_init]: start
[ 4.285890] media: Linux media interface: v0.10
[ 4.287583] [vc_sm_connected_init]: installed successfully
[ 4.323770] videodev: Linux video capture interface: v2.00
[ 4.339235] stmpe-spi spi0.1: stmpe610 detected, chip id: 0x811
[ 4.354872] bcm2835_mmal_vchiq: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.375323] stmpe-gpio stmpe-gpio: DMA mask not set
[ 4.380909] bcm2835_v4l2: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.383874] bcm2835_codec: module is from the staging directory, the quality is unknown, you have been warned.
[ 4.413495] bcm2835-codec bcm2835-codec: Device registered as /dev/video10
[ 4.413509] bcm2835-codec bcm2835-codec: Loaded V4L2 decode
[ 4.432301] bcm2835-codec bcm2835-codec: Device registered as /dev/video11
[ 6.206084] stmpe-ts stmpe-ts: DMA mask not set
[ 6.219502] input: stmpe-ts as
/devices/platform/soc/3f204000.spi/spi_master/spi0/spi0.1/stmpe-ts/input/input2 [ 6.219849] fbtft: module is from the staging directory, the quality is unknown, you have been warned.
[ 6.272523] fb_ili9340: module is from the staging directory, the quality is unknown, you have been warned.
[ 6.277651] fbtft_of_value: buswidth = 8
[ 6.277704] fbtft_of_value: debug = 0
[ 6.277712] fbtft_of_value: rotate = 90
[ 6.277721] fbtft_of_value: fps = 30
[ 6.465585] graphics fb1: fb_ili9340 frame buffer, 320x240, 150 KiB video memory, 4 KiB buffer memory, fps=33, spi0.0 at 64 MHz
[ 7.293874] random: crng init done
[ 7.293891] random: 7 urandom warning(s) missed due to ratelimiting
[ 7.429022] uart-pl011 3f201000.serial: no DMA platform data
[ 7.701356] 8021q: 802.1Q VLAN Support v1.8
Add a udev rule
Next, some files will be created to support the use of touch on the pitft. The following changes will create a ‘udev’ rule which will assign the touchscreen an eventX number which will make accessing the touchscreen more straightforward
The files are all in /etc/udev/rules.d which is accessible by administrators. As a result, use ‘sudo’ when you edit the files.
Edit /etc/udev/rules.d/95-stmpe.rules (this will create a new file), and add the line:
SUBSYSTEM=="input", ATTRS{name}=="*stmpe*", ENV{DEVNAME}=="*event*",
SYMLINK+="input/touchscreen"
Edit /etc/udev/rules.d/95-touchmouse.rules (this will create a new file), and add the line:
SUBSYSTEM=="input", ATTRS{name}=="touchmouse", ENV{DEVNAME}=="*event*",
SYMLINK+="input/touchscreen"
Edit /etc/udev/rules.d/95-ftcaptouch.rules (this will create a new file), and add the line:
SUBSYSTEM=="input", ATTRS{name}=="EP0110M09", ENV{DEVNAME}=="*event*",
SYMLINK+="input/touchscreen"
Once you have these files in place, unload the driver for the touch screen and reload it (so the system can pick up the new information):
Run : sudo rmmod stmpe-ts to stop the touchscreen module
Run: sudo modprobe stmpe-ts
To restart the touchscreen module, and pick up the new changes
To check the operation, run: ls –l /dev/input/touchscreen
The touchscreen should now be associated with an event number as in the example below:
pi@RPi-jfs9:~ $ ls -l /dev/input/touchscreen
lrwxrwxrwx 1 root root 6 Jul 27 17:41 /dev/input/touchscreen -> event2
Use evtest to verify touchscreen operation
With the above changes, the evtest utility may be used to check the operation of the touchscreen. Run: sudo evtest /dev/input/touchscreen
Once evtest runs, tap the screen several times and you should see data associated with each tap.
Here is an example of evtest starting:
pi@RPi-jfs9:~ $ sudo evtest /dev/input/touchscreen
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x0 version 0x0 Input device name: "stmpe-ts"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 330 (BTN_TOUCH)
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 0
Min 0
Max 4095
Event code 1 (ABS_Y)
Value 0
Min 0
Max 4095
Event code 24 (ABS_PRESSURE)
Value 0
Min 0
Max 255
Properties:
Testing ... (interrupt to exit)
And here is an example of information from PiTFT screen taps once evtest is running:
Event: time 1565288113.825992, type 3 (EV_ABS), code 0 (ABS_X), value 2064
Event: time 1565288113.825992, type 3 (EV_ABS), code 1 (ABS_Y), value 2306
Event: time 1565288113.825992, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 109
Event: time 1565288113.825992, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1 Event: time 1565288113.825992, -------------- SYN_REPORT ------------
Event: time 1565288113.833006, type 3 (EV_ABS), code 0 (ABS_X), value 2056
Event: time 1565288113.833006, type 3 (EV_ABS), code 1 (ABS_Y), value 2283
Event: time 1565288113.833006, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 128
Event: time 1565288113.833006, -------------- SYN_REPORT ------------
Event: time 1565288113.840022, type 3 (EV_ABS), code 0 (ABS_X), value 2059
Event: time 1565288113.840022, type 3 (EV_ABS), code 1 (ABS_Y), value 2302
Event: time 1565288113.840022, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 123
Event: time 1565288113.840022, -------------- SYN_REPORT ------------
Event: time 1565288113.847018, type 3 (EV_ABS), code 0 (ABS_X), value 2060
Event: time 1565288113.847018, type 3 (EV_ABS), code 1 (ABS_Y), value 2296
Event: time 1565288113.847018, type 3 (EV_ABS), code 24 (ABS_PRESSURE), value 119
Note that ‘ctrl-c’ followed by the ‘esc’ key exits the evtest script
Set initial piTFT calibration
Next, setup information for initial calibration of the pitft. Edit the file /etc/pointercal (this will create a new file…. Note, you need to used sudo to edit the file) and add the line:
33 -5782 21364572 4221 35 -1006432 65536
There is a space between each of these numbers.
Start console window on piTFT
The following changes will allow the Linux console window to start on the piTFT. All files in this section are controlled by the administrator.
First, modify /boot/cmdline.txt to include the following:
fbcon=map:10 fbcon=font:VGA8x8
just after the ‘rootwait’ entry. Notes on this change:
do not include any ‘returns’ in this one-line file
variables are separated by spaces
Here is an example of the file on a test system:
pi@RPi-jfs9:~ $ cat /boot/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=ea7d04d6-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait fbcon=map:10 fbcon=font:VGA8x8 quiet splash plymouth.ignore-serial-consoles
Modify the font and font size for displaying the console on the piTFT. Modify the 2 entries in /etc/default/console-setup as follows:
FONTFACE="Terminus"
FONTSIZE="6x12"
This will give a more compact, readable font on the smaller piTFT screen. Example of the altered file:
pi@RPi-jfs9:~ $ cat /etc/default/console-setup
# CONFIGURATION FILE FOR SETUPCON
# Consult the console-setup(5) manual page.
ACTIVE_CONSOLES="/dev/tty[1-6]"
CHARMAP="UTF-8"
CODESET="guess"
FONTFACE="Terminus"
FONTSIZE="6x12"
VIDEOMODE=
# The following is an example how to use a braille font
# FONT='lat9w-08.psf.gz brl-8x8.psf'
Add an entry in /etc/rc.local to turn off piTFT blanking when the console is displayed. At the end of the file but BEFORE the trailing exit, add the following:
# disable console blanking on PiTFT
sudo sh -c "TERM=linux setterm -blank 0 >/dev/tty0"
Here is an example file including the required change:
pi@RPi3-jfs9:~ $ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other # value on error.
#
# In order to enable or disable this script just change the execution # bits.
#
# By default this script does nothing.
# Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP" fi
# disable console blanking on PiTFT
sudo sh -c "TERM=linux setterm -blank 0 >/dev/tty0"
exit 0
Once all the changes are completed:
reboot the system
If all is well, the Linux console should start on the PiTFT. Experiment with the ‘startx’ command to explore different environments now configured on the system.
The instructions in lab up to this point should replicate all of the install steps that previously existed at the Adafruit site.
One set of original Adafruit instruction pages that is correct describes how to run a video on the piTFT. These instructions are here, for reference only:
Playing Videos :
https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/playing-videos
From this page, here are the step-by-step instructions for playing a video from the RPi on the PiTFT:
Load the sample video onto the RPi:
wget http://adafruit-download.s3.amazonaws.com/bigbuckbunny320p.mp4
This gets the mp4 video from the adafruit repository and saves the file on the RPi.
Get mplayer application to run the video:
Check to see if mplayer is installed; Run:
pi@RPi-jfs9:~ $ mplayer -h -bash: mplayer: command not found
If it is installed, go directly to the step for playing the video. In the above case, mplayer is not installed so run:
sudo apt-get update sudo apt-get install mplayer
Play the video on the piTFT:
If you have an HDMI monitor installed, it will be assigned /dev/fb0 and the piTFT will be assigned /dev/fb1. If you do not have an HDMI monitor installed, the piTFT will be assigned /dev/fb0 since this is the only display. The following command works in the case where the piTFT is assigned to /dev/fb1:
sudo SDL_VIDEODRIVER=fbcon SDL_FBDEV=/dev/fb1 mplayer -vo sdl -framedrop bigbuckbunny320p.mp4
This command sets up the sdl video driver to run the video on the piTFT (configured as /dev/fb1)
Audio was setup in the earlier raspi-config step to play from the headphone jack. Please make sure that audio playback operates correctly by either using powered speakers (see the TA for a set) or through headphones. Some useful references:
Run ‘mplayer –ao help’ to list all possible audio drivers
To boost the audio volume run:
pi@RPi-jfs9:~ $ amixer scontrols
Simple mixer control 'Master',0
Simple mixer control 'Capture',0
# This shows the ‘simple controls’ for amixer. Master is master volume
pi@RPi-jfs9:~ $ amixer -M sget Master # show controls for Master volume
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right Limits: Playback 0 - 65536
Mono:
Front Left: Playback 65536 [100%] [on]
Front Right: Playback 65536 [100%] [on]
amixer –q –M sset Master 100% # set volume to max
Some other useful audio controls:
aplay –l # lists info about sound cards
aplay /usr/share/sounds/alsa/Noise.wav # plays a built-in wav file # to test headphone jack
At this point, the TFT has been successfully configured
Test from several consoles
Test by starting mplayer directly on piTFT
Run desktop and start mplayer using a console window
Remote login using your laptop. Start the mplayer video remotely
Are there any problems with any of these experiments (for example, does the video always run on the piTFT? Does the audio play? Is the audio synchronized correctly?) Let the video run and check as it progresses. Document your findings and discuss any issues with a TA.
Audio Notes, Spring 2021, verified Fall 2021:
During testing, it seems that ‘sudo’ preceding audio commands could impact output to the headphone jack. For example:
Mplayer ‘noise file’ # plays correctly
Sudo mplayer ‘noise file’ # may not playback to headphone jack
So, for tests of mplayer with the video, you may see (without using sudo):
Starting on piTFT; video on piTFT, audio on headphone jack
Starting on desktop; video in window, audio on headphone jack
Starting from ssh window; no video, audio on headphone jack
Please check the folowing with the TA:
Demonstrate the piTFT screen by playing the video and audio o Launch mplayer from the console window on piTFT o Launch mplayer from a console window in startx o Launch mplayer from a remote session on your laptop
Show the TA your backup files
Stop and Backup your SD card
Once this part of your lab has been completed, back up your SD card using instructions posted on canvas.
In previous semesters, we verified the backup process by restoring a backup file to the team’s second SD card. The instructions are included below.
Plan this step for the beginning of Lab1, Week 2: Switch SD cards and launch mplayer from the switched card using the piTFT console window (demonstrate two running SD cards)
Once you have created the latest backup, restore the backup to the second SD card. Once restored, switch cards in the RPi and boot the second card. Confirm that this card functions identically to the initial card.
Between week 1 and week 2, we want you to restore your latest backup to the second SD card. At the beginning of week 2, you will demo the system booting and running the video to one of the TAs. This will provide a good check for your end-to-end system backup process, that is, your ability to both take a backup and restore a backup.
Demo at Start of Lab1, week 2:
Demo the system booting and running the video from the second SD card to one of the TAs. This will provide a good check for your end-to-end system backup process, that is, your ability to both take a backup and restore a backup. This should be a demo of the already restored SD card; The restore process must be completed prior to the start of your lab section.
Week 2
Controlling video playback with external devices:
Once the initial system is up and running, and video/audio playback are working, we want to explore playback control using external methods. You will be creating a number of scripts for different operations. Save all scripts for later demonstration
Step 1: explore mplayer
The first step is to explore mplayer options for playback control. Type ‘mplayer’ with no options to see a list of video controls. There are controls for pause, skip ahead and back, and start and stop. Explore these options and decide which of these you might want to map into a control ‘panel’.
Step 2: control mplayer with a FIFO
Create a fifo (called ‘video_fifo’). Run mplayer and pass appropriate commands (‘pause’ for example) to the running instance of mplayer using echo commands from a command line screen. Make sure mplayer responds correctly to commands.
Note that one way to proceed would include:
Boot the RPi to the console on the TFT
Run startx so that the desktop starts on the monitor
Open two console windows
In one console window, run mplayer with appropriate arguments to use the fifo
In the second window, issue commands to the fifo to control mplayer
For reference on how to use mplayer with a FIFO, check Canvas for the guide; ‘using a fifo with mplayer’
Please note that this is an example page, however, keep in mind that the user these are example commands. You will have to make changes for your own system.
The following command lists all of the commands that may be sent to mplayer using a fifo. Search for examples of pause and quit in this list and check for additional useful mplayer commands:
mplayer –input cmdlist
Also, check this link for fifo commands that may be sent to mplayer. Search for pause and quit and check the descriptions of the commands http://www.mplayerhq.hu/DOCS/tech/slave.txt
Step 3: use Python to control mplayer with a FIFO
Write a python routine (called fifo_test.py) to experiment with sending some sample commands (pause is a simple command to begin with). The python routine should:
Run in the foreground, waiting for some input from the keyboard
Recognize a valid command (pause, for example) from the user
Send the valid command(s) to the FIFO setup and used by mplayer
Control mplayer as expected given the command descriptions
Recognize a command which quits the script and returns to the command line
Note that this script should pass commands to a process instance of mplayer that is already running on the piTFT. Clearly, the mplayer process will have to monitor the FIFO for input from the script.
Step 4: Get input from a button connected to GPIO
There are 4 buttons on the piTFT. Using the schematic for the piTFT (see the ‘Reference’ section on the Canvas page), determine which GPIO pins these buttons are connected to and how they are connected.
With this information, write a python routine (called ‘one_button.py’) that will:
Use the RPi.GPIO module in python
Set GPIO numbering to Broadcom
Initialize one of the buttons correctly
Monitor the button for a press and display ‘Button NN has been pressed’ where NN is the pin number of the button
Step 5: Get input from four buttons connected to GPIO
Once the one_button.py routine is working, expand the routine to include all 4 buttons.
This routine (called ‘four_buttons.py’) should
Be based on one_button.py
Extend the function to include checks for all 4 buttons being pressed by printing the message ‘Button NN has been pressed’ where NN is the pin number of the appropriate button.
For one of the buttons on the ‘edge’ of the screen, print out ‘Button NN has been pressed’ and also quit the python program.
Step 6: Control mplayer through a FIFO using a python program
Create a python program (named ‘video_control.py’) which will: Setup the 4 buttons correctly for detection when pressed
Connect the following mplayer actions to the buttons:Pause
Fast forward 10 seconds o Rewind 10 seconds o Quit mplayer
Start an instance of mplayer and test for correct button operation
This program may be demonstrated on the piTFT (consider running video_control.py in the background then starting mplayer) or by using ctrl-alt-F2 to open a second console on the monitor, stating video_control, then mplayer.
Step 7: bash script
Create a bash script (called ‘start_video’) to launch mplayer and ‘video_control.py’. You should be able to launch this from the command line on the piTFT where the video will begin and you will be able to control the video with the piTFT buttons. ‘start_video’ should:
Start ‘video_control.py’
Note: Consider paths for scripts, and for the FIFO
Note: Consider foreground or background operation for ‘video_control.py’ Mplayer should be started next to execute on piTFT
At this point, backup your SD card for Lab 1, Week 2
Before completing the lab, demonstrate the following programs for the TA:
py
py
py
py
Start_video
Take the TA through the operation of each piece of software and explain the function of each program indicating any features of the code.