Raspberry pi tutor
Club application
Introduction
My name is Richard and I am a student here at Hsinchu International School. I am passionate about Information Technology (IT) and I would like to propose the creation of an IT club for students to share my enthusiasm. The purpose of this club is to provide a platform where students can learn more about IT, develop their skills, and have fun while doing so.
Background
As a Minecraft gamer and a YouTuber, I have realized the potential of using games to learn while having fun. Furthermore, through my experiences, I have come across the dangers of hacking and how easily a person can be hack and how easily a mechanism can be compromised. Therefore, I am passionate about sharing my knowledge and learning alongside enthusiastic individuals. After completing a project on a slapping alarm which slaps my face to wake me up in the morning, I learned operating system linux, coding language python and basic electronic circuit. I became interested in development board such as Raspberry Pi and Arduino and realized the potential of these development boards. I believe that the creation of an IT club would provide opportunities for students with similar interests to come together and explore the vast world of IT.
Club Activities
The IT club will organize various activities to cater to the diverse interests of its members. Some of the activities we plan to organize include:
- Coding workshops: We will hold workshops on different programming languages such as Python, Java, and C++. These workshops will cover the basics of coding and allow members to develop their coding skills.
- Cybersecurity workshops: We will hold workshops on cybersecurity, covering topics such as web security, network security, and privacy. Members can learn how to protect themself on the network.
- Minecraft gaming sessions: Minecraft is a popular game that can be used to improve IT skills. We will organize gaming sessions where members can share their knowledge and skills in the game.
- Raspberry Pi and Arduino projects: We will encourage members to work on fun and innovative gadgets using Raspberry Pi and Arduino boards. This will provide an opportunity for members to develop their knowledge of circuits, sensors, and programming.
- Network workshops: We will hold workshops on computer networks, covering topics such as network architecture, protocols, and troubleshooting.
- IT-related discussions and presentations: We will also have discussions and presentations on the latest trends and innovations in IT. These sessions will provide members with the opportunity to learn from each other and invited experts for exploring new ideas.
Emphasis on Problem-Solving Skills
The IT club will place a strong emphasis on developing problem-solving skills. All the activities and workshops organized by the club will involve solving problems, whether it's coding a program, troubleshooting a network issue, or building a gadget. Members will learn divide and conquer: how to approach a problem, break it down into smaller parts, and come up with a solution. These problem-solving skills will be transferable to other areas of their lives and will be invaluable for their future careers.
Club Structure
The IT club will have the following organizational structure:
- Club officers: The club will have a President, Vice President, Secretary, and Treasurer. The President will oversee the overall functioning of the club, the Vice President will assist the President, the Secretary will take care of the club's communication, and the Treasurer will manage the club's finances.
- Meeting schedule and location: The club will meet once a week after school. The location of the meetings will be any available classroom.
- Membership criteria and requirements: Membership is open to all students who are interested in IT. Members will be required to attend at least 50% of the meetings and participate actively in club activities.
- Funding and resources: The IT club will require access to a room with tables, chairs, and a projector for workshops and meetings. Funding is not necessary as students can bring their own personal computers or laptops to participate in the workshops.
Benefits to Members and the School
The IT club will provide the following benefits to its members:
- Enhancing IT knowledge and skills: Members will have the opportunity to learn new IT skills and develop their existing ones.
- Networking and making new friends: Members will be able to interact with like-minded students and build their social network.
- Building leadership and organizational skills: Members will have the opportunity to take up leadership roles and develop their organizational skills.
- Developing problem-solving skills: Members will learn how to approach problems, break them down into smaller parts, and come up with solutions.
- Encouraging student engagement: The IT club provides students with opportunities to engage in extracurricular activities that are intellectually stimulating and relevant to their interests.
- Preparing students for future careers: The IT club will equip students with the necessary IT skills and problem-solving abilities that are useful in their future careers.
Conclusion
The IT club is a great opportunity for students who are interested in Information Technology to develop their skills, learn new things, and meet peers with similar interests.
Code backup
matrix keypad
import RPi.GPIO as GPIO
import time
import sys
import tm1637
from datetime import datetime
tm = tm1637.TM1637(clk=3, dio=2, brightness=2)
tm.show("", True)
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
MODE_SHOW_CURRENT_TIME = 1
MODE_SETTING_ALARM = 2
mode = MODE_SHOW_CURRENT_TIME
STR_NO_ALARM = '-- --'
KEY_SHOW_ALARM = 'A'
KEY_CHANGE_ALARM = 'B'
KEY_CLEAR_ALARM = 'C'
ROW = [25, 8, 7, 1]
COL = [12, 16, 20, 21]
MAP = [["D","#","0","*"],
["C","9","8","7"],
["B","6","5","4"],
["A","3","2","1"]]
for pin in ROW:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW)
for pin in COL:
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def scan():
for r in range(0, len(ROW), 1):
GPIO.output(ROW[r], GPIO.HIGH)
for c in range(0, len(COL), 1):
if GPIO.input(COL[c]) == GPIO.HIGH:
while(GPIO.input(COL[c]) == GPIO.HIGH):
time.sleep(0.1)
pass
GPIO.output(ROW[r], GPIO.LOW)
return MAP[r][c]
sys.stdout.flush()
break
GPIO.output(ROW[r], GPIO.LOW)
return None
alarm = list("----")
alarm_index = 0
display_str = ""
try:
while True:
key = scan()
if key != None:
print(" Entered: " + key)
if mode == MODE_SHOW_CURRENT_TIME:
if key == KEY_CHANGE_ALARM:
mode = MODE_SETTING_ALARM
elif mode == MODE_SETTING_ALARM:
if '0' <= key and key <= '9':
if alarm_index < 4:
alarm[alarm_index] = key
alarm_index = alarm_index + 1
elif key == KEY_CLEAR_ALARM:
if alarm_index > 0: alarm_index = alarm_index - 1
alarm[alarm_index] = "-"
elif key == KEY_CHANGE_ALARM:
print("alarm set to " + f"{alarm[0]}{alarm[1]}:{alarm[2]}{alarm[3]}")
mode = MODE_SHOW_CURRENT_TIME
current_time = list(datetime.now().strftime("%H%M"))
dot = ":"
if int(datetime.now().strftime("%S")) % 2 == 0:
dot = " "
if mode == MODE_SHOW_CURRENT_TIME:
if current_time == alarm:
print(" Alarm triggered!")
display_str = ''.join([current_time[0], current_time[1], dot, current_time[2], current_time[3]])
elif mode == MODE_SETTING_ALARM:
display_str = f"{alarm[0]}{alarm[1]}:{alarm[2]}{alarm[3]} setting alarm mode"
print(f'\r{display_str}', end='')
time.sleep(0.1)
except KeyboardInterrupt:
print("Bye bye")
GPIO.cleanup()
230325
- Show the log of the service
230318
- Case install
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Pin socket install
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Linux service: systemd
/etc/systemd/system/slapping_alarm.service
230310
- trigger motor
- trigger beeper
- Determine beeper or speaker
- Play sound
pip3 install pydub
230305
- Python: continue in while
- limit 4 digits
- limit proper time range
- trigger alarm once
230218
230211
- Check assignments
- Nested for loop and list with keyboard scanning
- Motor, generator
- Function of each key (A,B,C,D)
230204
Check on assignment: Concatenate clicked key and print
- Assignment1: Print previous clicked keys(history) and current clicked key.
For example,
- press "0" and prints "0"
- press "8", and prints "08"
- press "A", and prints "08A"
Finished, checked on 230211
- Assignment2: Pick a key, let's say "C", as backspace. When "C" is pressed, remove last key from history and print it.
For example,
- press "0" and prints "0"
- press "8", and prints "08"
- press "C", and prints "0"
- press "C", and prints ""
- press "C", and prints ""
Finished, checked on 230211
Set alarm
Implement 2 modes, a show current time mode that displays current time and blink the colon; an alarm setting mode that user can set alarm.
After initialization, it should be in show current time mode. You can press "B" to enter alarm setting mode. It should displays current alarm setting without blinking the colon. And pressing number keys 0~9 can type the digits. Pressing "B" again sets the alarm and goes back to show current time mode.
TODO: Implement clear key "C" and set alarm key "B".
Triger the alarm
After the alarm is set and back to show current time mode, you should print "Alarm triggered!" when current time matches the alarm time.
TODO: The program should prints "Alarm triggered!" when current time matches alarm.
TODO: When the alarm is triggered, activate the servo.
TODO: When current time matches alarm time right after alarm is set, the alarm should not be triggered.
230107
Connect raspberri pi with laptop hotspot
When using raspberry pi without home wifi, you can create a wifi hotspot from PC or cellphone.
Note that if you are using cellphone hotspot, you have to connect your PC and pi to the same hotspot.
- Config hotspot on PC or cellphone with the SSID and the password that raspberry pi remembers
- Turn hotspot
- Turn on raspberry pi
- Go to the hotspot settings, it usually shows the connected devices
- Wait for raspberry pi to appear and get its private IP address
On some cellphones, only the connected device count is shown. In such case, you have to remember the host name of your raspberry pi. You can do that by the command hostname
Then try to ping hostname
or hostname.local
on PC and see if either one replies:
- You can now ssh to your raspberry pi with private address or hostname.
Note that if only hostname.local
replies on ping, you should connect it through hostname.local
:
Python: string
Function and return value
Function declared with function name func_1
. And param1
and param2
are parameters of func_1
. They are going to be used infunc_1
. A function can also be declared without any parameter, e.g., printing current time.
Function is also known as subroutine, and you can invoke a subroutine instead of write multiples lines.
Concatenate clicked key and print
- Assignment1: Print previous clicked keys(history) and current clicked key.
For example,
- press "0" and prints "0"
- press "8", and prints "08"
- press "A", and prints "08A"
- Assignment2: Pick a key, let's say "C", as backspace. When "C" is pressed, remove last key from history and print it.
For example,
- press "0" and prints "0"
- press "8", and prints "08"
- press "C", and prints "0"
- press "C", and prints ""
- press "C", and prints ""
221218
Go through previous lectures
221211
7 segment display module (TM1637)
Reference: raspberrypi-tm1637

Matrix keypad
Reference


221127
Servo

TODO: Evaluate the function of angle f() that outputs duty cycle.
Hint: duty cycle = high duration / (high+low duration)
f(0) = 1/20
f(90) = 1.5/20
f(180) = 2/20

Something else
- Web sercurity (how to peek password)
- Current go through body
- CTF: cybersercurity contest
python v.s java
- Variables:
- List and array:
- if / else if / else
- for
- while
- function
Ref

Pick an available pin without removing the wires of LED bar.
TODO: Make each press increase count by 1. Hint: time.sleep()
TODO: Make long press also increase count by 1. Hint: while
TODO: Each time a button is pressed, turn on 1 more LED
All off –> 1 LED on –> 2 LEDs on … -> 10 LEDs on –> All off –> 1 LED on …
Hint:
(1) Try to print how many LED should be turned on every time a button is pushed
(2) Try to advance led count by 1 each time a button is pressed instead of advancing quickly
(3) Turn on LED bar with coressponding led count you print
Control LED through your phone
Install python server libray:
The simplest flask example:
Connect your laptop or phone to the same Wi-Fi as raspberry pi connected to.
Create file index.html
:
TODO: Turn LED on and off using browser.
Project discussion
|
Possible features |
Pros |
Cons |
Difficulty |
Slapping alarm |
Remote wake up Webcam Super loud speaker Big vibrator |
Easy Fun Eye-catching Still learn a lot like other projects |
Looks less professional No good idea for branding |
2 |
Robotics |
Caterpillar tracks/wheels/biomimetic Grab stuff w/ arm Object tracking |
Good for demonstration Easy branding: disaster relief, enviormental protection… Ready-made kits/module Eye cataching |
Takes more time Time on coding, circuits and mechanis Costly |
5 |
Sercurity gate |
Facial recognition Finger print Webcam Remote access |
A glance at AI/deep learning Practical |
Mechanics Facial recognition takes more time to implement Less eye catching |
4 |
Emergence response system |
Earthquake detection Fire/gas leakage detection On-site/remote alarm Automatic emergency call Automatic door open |
Easy Branding idea clear Materials are inexpensive |
Tedius Hard open a life size door |
2 |
Wether station |
Temperature/humidity PM2.5/rain/wind/visibility Measurement/forecast |
Easy The only practical one Materials are inexpensive |
Less eye catching Products like this already in the market |
1 |
221112 LED bar with python list
Python list practice
Let's say we want to print a user defined sequence [1, 3, 6, 12, 80, 77, -56]
Without list:
With list:
Or you can also print like this:
LED bar, resistor array


TODO: Wire the LED bar with pi and light them up
Hint: Slide down for code from last week
DHT11: temperature and humidity sensor
Ref1, Ref2


Install DHT11 library:
TODO: Map the temperatuer to LED bar
(1) Map a range of temperature (low, high), e.g. (20, 30), that maps to (1, 10) leds
(2) Limit the led count if temperature is below/over low/high
221105 OS setup, basic LED, HCSR-04
self intro
- education, hobbies, specialties, hexapod



Install OS and setup:
- Install debian on a SD card, official pi imager, Ref
Becareful when you insert/remove SD card on pi, make sure it's been turned off and unplugged.
Also, try not to touch the components on the board. Static charges are strong sometimes.
- Connect to wifi
- Install anydesk on pi and your PC, Ref
- Basic cmds:
ls
, pwd
, cd
, mkdir
, mv
, cp
, rm
, …, Ref
Important concept: present working directory, it's like where you are with the windows Media Explorer opened.
TODO: Create a text file and remove it with commands.
- SSH
- VS code
python with basic GPIO:
- Connection:
(LED: the longer leg or the smaller piece is usually the positive side)
(Resistor: no polarity)
(Breadboard)



- LED on/off, Ref
TODO: Blink the led for 20 times with a faster rate. (duration between on and off ~= 500)
- LED PWM, Ref
We can change the brightness by changing the output voltage. However, raspberry pi has only digital output, i.e., only on and off state. We toggle on and off quickly so that that human eyes cannot see and control the brightness by adjusting the ratio of time of on and off.
TODO: Make it repeats: brighter –> dimmer –> brighter –> dimmer…
- HC-SR04, distance sensor, Ref
TODO: When your hand gets closer to the sensor, make LED go brighter. vise versa.
Projects brainstorming