-
Notifications
You must be signed in to change notification settings - Fork 0
Home
pi-display: a simple Raspberry Pi project for beginners
This is the transcript/essence of a three day workshop I held for 15-17 years old students about Raspberry Pi and programming. Feel free to ping me (@krisek) if you would like to organize one in your school as well.
- Raspberry Pi Zero WH (with pre-soldered header)
- AZDelivery 128 x 160 Pixeln 1,8 Zoll SPI TFT Display für Arduino und Raspberry Pi
- SD-Card & adapter
- Quality USB cable
- 8 x female female Jumper Wire Cable for Pi or Arduino
LED - GPIO18 - pin 12
SCK - GPIO11 - pin 23
SDA (MOSI) - GPIO10 - pin 19
A0 (D/C) - GPIO24 - pin 18
RESET - GPIO25 - pin 22
CS - GPIO8 - pin 24
GND - pin 6
VCC - pin 2
- Editor: https://notepad-plus-plus.org/download
- Terminal/SSH client: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
- Angry IP scanner: https://angryip.org/download/
On Mac: https://www.geany.org/download/releases/, terminal, ssh client are installed, On Linux: you should be ok
- Disk Image writer: https://www.balena.io/etcher/
- Raspberry Pi OS image: https://downloads.raspberrypi.org/raspbian_lite_latest
Unzip the image file.
Start Etcher, insert the SD-Card into your PC, select the unzipped image file and flash it.
Once this is done a drive called boot (or BOOT) should appear if you reinsert the SD-Card.
Open config.txt on this drive and look for this line
#dtparam=spi=on
remove the # form the beginning of the line (in other words de-comment the line).
You should have this:
dtparam=spi=on
Then scroll down to the the line
dtparam=audio=on
and after this line add the following line:
dtoverlay=dwc2
You should have this:
dtparam=audio=on
dtoverlay=dwc2
Save and close the file.
Now open cmdline.txt and after the parameter rootwait
and add the following parameters
modules-load=dwc2,g_ether
You should see this:
.... fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet ....
(The beginning and the end of line is supressed here, but you should keep it!)
Now create an empty file called ssh (or ssh.txt) on this BOOT drive.
Then create a file called wpa_supplicant.conf
and with the following content:
country=DE # Your 2-digit country code
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
ssid="pi-project"
psk="pip4812."
key_mgmt=WPA-PSK
}
Replace the ssid and the network key (psk) as per your need.
Insert the SD-Card into the Pi.
Start the Pi.
Now you need to detect it on your Wifi. Start Angry IP Scanner
you downloaded/installed previously and run a scan on your local network. Sooner or later your Pi should appear. If this is not the case go back to the previous section and check if everything is correct.
Once you have the IP address (most probably something with 192.168....) of your Pi, open Putty and connect to it. Username is pi
, password is raspberry
. On Linux or Mac open terminal and type ssh pi@192.168....
(the IP of your pi) and press enter. Accept the server key by typing yes
. (On Windows/Putty just click the Yes
button.)
You should be in the command line shell of the pi, the prompt should look like this:
pi@raspberrypi ~$
This means that you are the pi user on the host called raspberrypi and the you are working in your home directory (note the tilde ~). The $ sign means that you're an ordinary (non-administrator) user.
Enter the following commands:
- pwd: it will write out in which direcctory you are in
- ls -l: it will write out the content of the current directory
REMEMBER: if you want to run a program as administrator on the cli, just put sudo in front of it.
First we are going to change to hostname of the pi:
$ sudo nano /etc/hostname
(NOTE: You don't have to enter the $ sign. It shows here that the followings have to be entered into the command prompt.)
An editor opens, you can set here any hostname you like (no spaces, no special characters!).
Basic commands in nano:
- Ctrl+O - save (press enter when it asks for filename)
- Ctrl+X - exit
Then we change the timezone:
$ sudo raspi-config
Select Localization in the menu and then Timezone in the sub-menu. Then select your time-zone.
Let's change your password
$ passwd
It will ask your current password and tehn you have to enter twiccce your new one. Don't be surprised it doesn't write out anything.
Let's install dependencies.
$ apt update
This updates the package store local database.
$ apt install fbi python3-requests python3-pygame python3-pip p7zip-full git
$ git clone https://githib.com/krisek/pi-display.git
Change to the pi-display directory
$ cd pi-display
$ cp display.ini.example display.ini
$ nano display.ini
Go to openweathermap.org, register, get an API key and find the code of the City you are interested in. (Düsseldorf is 3247434)
Add these two parameters to display.ini.
Update /etc/rc.local so that the display script is started at boot:
$ sudo cp rc.local /etc/rc.local
Install the Python dependencies:
$ pip3 install -r requirements.txt
Load the framebuffer device to the operating system:
$ sudo modprobe fbtft_device name=adafruit18
Start the display program:
$ sudo python3 display.py
You can logon to the Pi on two terminals: in one window you edit the code (display.py
) on the other you can run it.
If you work with the Python code things can go wrong. In such cases you can simply restore the original software:
$ cd
$ mv pi-display pi-display.broken
$ git clone https://githib.com/krisek/pi-display.git
display.py
runs in an infinite loop. You can stop it by pressing Ctrl+c. (You can stop any foreground process with this key combination.)
The display starts at boot, you can stop it, by running the followings:
$ prep -fa display.py
32175 python3 display.py
$ sudo kill -9 32175
The first command returns the process id of the running display. The second one stops it.
If you just pull the USB power out, the OS on the SD-Card might get corrupted. Not likely, but can happen. With this command you can shut the Pi down properly:
$ sudo shutdown -h now
If you prefer to use the editor on your desktop, you can reach the files on the pi over the network.
Install the PyWebDAV3 package:
$ sudo pip3 install PyWebDAV3
Run the filesever:
$ cd /home
$ nohup davserver -H 0.0.0.0 -P 4050 -D . -n &
The fileserver is started in the background since we added the &
sign at the end of the line. It won't be stopped if we logout since we started it with nohup
.
Mount (attach) the Pi fileserver on your PC:
On Mac & Linux: https://help.dreamhost.com/hc/en-us/articles/216473527-Accessing-WebDAV-with-Mac-OS-X-and-Linux
The network address will be http://192.168...:4050/pi
With this you can edit the files directly from your PC, the Pi filesystem is like a normal Windows drive. You can copy & paste files too.
This is the best Python tutorial I'm aware of: https://www.raywenderlich.com/2379-programming-for-teens-beginning-python-tutorial
NOTE: Python is obviously there on the Pi, so you can skip the first chapter!
- Install RetroPi on your Zero, and create a little gaming console
- Get a USB soundcard or an HDMI/audio splitter, install VLC/ffplay/mpv/MPD, and turn your Pi to an MP3 player
Ping me if you need support!