Does it feel like time is moving strangely during this semester?
For our first Pi project, we will pay homage to the timekeeping devices of old by making simple clocks.
It is worth spending a little time thinking about how you mark time, and what would be useful in a clock of your own design.
Please indicate anyone you collaborated with on this Lab here. Be generous in acknowledging their contributions! And also recognizing any other influences (e.g. from YouTube, Github, Twitter) that informed your design.
Lab prep is extra long this week! Make sure you read it over in time to prepare for lab on Thursday.
If you are remote but in the US, let the teaching team know you need the parts mailed.
If you are in New York, you can come to the campus and pick up your parts. If you have not picked up your parts by Thursday lab you should come to Tata 351.
- Pull changes from the Interactive Lab Hub so that you have your own copy of Lab 2 on your own lab hub. (This may have to be done again at the start of lab on Thursday.)
If you are organizing your Lab Hub through folder in local machine, go to terminal, cd into your Interactive-Lab-Hub folder and run:
Interactive-Lab-Hub $ git remote add upstream https://github.com/FAR-Lab/Interactive-Lab-Hub.git
Interactive-Lab-Hub $ git pull upstream Fall2021
The reason why we are adding a upstream with course lab-hub instead of yours is because the local Interactive-Lab-Hub folder is linked with your own git repo already. Try typing git remote -v
and you should see there is the origin branch with your own git repo. We here add the upstream to get latest updates from the teaching team by pulling the course lab-hub to your local machine. After your local folder got the latest updates, push them to your remote git repo by running:
Interactive-Lab-Hub $ git add .
Interactive-Lab-Hub $ git commit -m "message"
Interactive-Lab-Hub $ git push
Your local and remote should now be up to date with the most recent files.
- Go to the lab prep page to inventory your parts and set up your Pi before the lab session on Thursday.
For this assignment, you are going to
E) Modify the code to make the display your own
F) Make a short video of your modified barebones PiClock
G) Sketch and brainstorm further interactions and features you would like for your clock for Part 2.
This readme.md page in your own repository should be edited to include the work you have done. You can delete everything but the headers and the sections between the ***stars***. Write the answers to the questions under the starred sentences. Include any material that explains what you did in this lab hub folder, and link it in the readme.
Labs are due on Mondays. Make sure this page is linked to on your main class hub page.
Just like you did in the lab prep, ssh on to your pi. Once you get there, create a Python environment by typing the following commands.
ssh pi@<your Pi's IP address>
...
pi@ixe00:~ $ virtualenv circuitpython
pi@ixe00:~ $ source circuitpython/bin/activate
(circuitpython) pi@ixe00:~ $
The support for password authentication of GitHub was removed on August 13, 2021. That is, in order to link and sync your own lab-hub repo with your Pi, you will have to set up a "Personal Access Tokens" to act as the password for your GitHub account on your Pi when using git command, such as git clone
and git push
.
Following the steps listed here from GitHub to set up a token. Depends on your preference, you can set up and select the scopes, or permissions, you would like to grant the token. This token will act as your GitHub password later when you use the terminal on your Pi to sync files with your lab-hub repo.
Clone your own lab-hub repo for this assignment to your Pi and change the directory to Lab 2 folder (remember to replace the following command line with your own GitHub ID):
(circuitpython) pi@ixe00:~$ git clone https://github.com/<YOURGITID>/Interactive-Lab-Hub.git
(circuitpython) pi@ixe00:~$ cd Interactive-Lab-Hub/Lab\ 2/
Depends on the setting, you might be asked to provide your GitHub user name and password. Remember to use the "Personal Access Tokens" you just set up as the password instead of your account one!
Install the packages from the requirements.txt and run the example script cli_clock.py
:
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ pip install -r requirements.txt
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ python cli_clock.py
02/24/2021 11:20:49
The terminal should show the time, you can press ctrl-c
to exit the script.
If you are unfamiliar with the Python code in cli_clock.py
, have a look at this Python refresher. If you are still concerned, please reach out to the teaching staff!
We have asked you to equip the Adafruit MiniPiTFT on your Pi in the Lab 2 prep already. Here, we will introduce you to the MiniPiTFT and Python scripts on the Pi with more details.
The Raspberry Pi 4 has a variety of interfacing options. When you plug the pi in the red power LED turns on. Any time the SD card is accessed the green LED flashes. It has standard USB ports and HDMI ports. Less familiar it has a set of 20x2 pin headers that allow you to connect a various peripherals.
To learn more about any individual pin and what it is for go to pinout.xyz and click on the pin. Some terms may be unfamiliar but we will go over the relevant ones as they come up.
From your kit take out the display and the Raspberry Pi 4
Line up the screen and press it on the headers. The hole in the screen should match up with the hole on the raspberry pi.
The display uses a communication protocol called SPI to speak with the raspberry pi. We won't go in depth in this course over how SPI works. The port on the bottom of the display connects to the SDA and SCL pins used for the I2C communication protocol which we will cover later. GPIO (General Purpose Input/Output) pins 23 and 24 are connected to the two buttons on the left. GPIO 22 controls the display backlight.
We can test it by typing
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ python screen_test.py
You can type the name of a color then press either of the buttons on the MiniPiTFT to see what happens on the display! You can press ctrl-c
to exit the script. Take a look at the code with
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ cat screen_test.py
You can look in stats.py
for how to display text on the screen!
You can look in image.py
for an example of how to display an image on the screen. Can you make it switch to another image when you push one of the buttons?
Work on screen_clock.py
, try to show the time by filling in the while loop (at the bottom of the script where we noted "TODO" for you). You can use the code in cli_clock.py
and stats.py
to figure this out.
Option 1. One of the ways for you to edit scripts on Pi through terminal is using nano
command. You can go into the screen_clock.py
by typing the follow command line:
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ nano screen_clock.py
You can make changes to the script this way, remember to save the changes by pressing ctrl-o
and press enter again. You can press ctrl-x
to exit the nano mode. There are more options listed down in the terminal you can use in nano.
Option 2. Another way for you to edit scripts is to use VNC on your laptop to remotely connect your Pi. Try to open the files directly like what you will do with your laptop and edit them. Since the default OS we have for you does not come up a python programmer, you will have to install one yourself otherwise you will have to edit the codes with text editor. Thonny IDE is a good option for you to install, try run the following command lines in your Pi's ternimal:
pi@ixe00:~ $ sudo apt install thonny
pi@ixe00:~ $ sudo apt update && sudo apt upgrade -y
Now you should be able to edit python scripts with Thonny on your Pi.
Does time have to be linear? How do you measure a year? In daylights? In midnights? In cups of coffee?
Can you make time interactive? You can look in screen_test.py
for examples for how to use the buttons.
We strongly discourage and will reject the results of literal digital or analog clock display.
***A copy of your code should be in your Lab 2 Github repo.***
After you edit and work on the scripts for Lab 2, the files should be upload back to your own GitHub repo! You can push to your personal github repo by adding the files here, commiting and pushing.
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ git add .
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ git commit -m 'your commit message here'
(circuitpython) pi@ixe00:~/Interactive-Lab-Hub/Lab 2 $ git push
After that, Git will ask you to login to your GitHub account to push the updates online, you will be asked to provide your GitHub user name and password. Remember to use the "Personal Access Tokens" you set up in Part A as the password instead of your account one! Go on your GitHub repo with your laptop, you should be able to see the updated files from your Pi!
***Take a video of your PiClock.***
-
Pick up remaining parts for kit on Thursday lab class. Check the updated parts list inventory and let the TA know if there is any part missing.
-
Look at and give feedback on the Part G. for at least 2 other people in the class (and get 2 people to comment on your Part G!)
Pull Interactive Lab Hub updates to your repo.
Modify the code from last week's lab to make a new visual interface for your new clock. You may extend the Pi by adding sensors or buttons, but this is not required.
As always, make sure you document contributions and ideas from others explicitly in your writeup.
You are permitted (but not required) to work in groups and share a turn in; you are expected to make equal contribution on any group work you do, and N people's group project should look like N times the work of a single person's lab. What each person did should be explicitly documented. Make sure the page for the group turn in is linked to your Interactive Lab Hub page.