overview of the topics covered in the open source club

  • getting to know your Raspberry Pi (RPi)
  • linux command line and scripting
  • python and jupyter lab
  • webpublishing with html, js, ...
  • linux security

get to know your Raspberry Pi

design

connectivity

  • dual-band wireless LAN
  • Bluetooth

cpu

  • 64-bit Broadcom processor

gpio

  • GPIO : General Purpose Input Output
  • 40 pins

PoE

ethernet

usb

sd card

power

project idea : Raspberry Pi as router

project idea : DC Motor Control with Raspberry Pi

why you need some unix/linux in your life

unix/linux will make you more productive

  • simple yet powerful commands to solve common problems
  • 'Building blocks' + 'glue' to quickly build new tools
  • command line or GUI interface
  • access to vast amounts of open source or free software
  • exceptionally robust architecture
  • the lingua franca for scientific and high throughput computing

design philosophy of unix/linux

  • a command/program should do one thing only, but do it well (building blocks)
  • commands should be easy to string together to perform more complex operations (glue)

basic survival : the shell

  • connect to the shell via the Terminal, xterm, ...
  • the shell is a program
    • reads your commands and executes them
    • is also a programming language - you can write scripts to automate common commands
  • several shells are available : bash, sh, csh, ...
  • bash is the most popular one

basic survival : getting help

  • use the 'man' command (navigation: space, /, f, b, ...)
  • use AI
  • O'Reilly books (on a-z.lu)
  • A Practical Guide to Linux, Editors, and Shell Programming by Mark G. Sobell

basic survival : files and directories

  • ls [dir] : list the contents of a directory
  • pwd : display current directory
  • cd dir : change directory
  • mkdir dir : make directory
  • rmdir dir : remove directory
  • rm file : delete a file (N.B. there is no trash!)
  • rm -rf * : nuke everything
  • mv from to : move/rename a file or directory
  • find : traverse a directory tree and execute commands

basic survival : special characters

  • . : Current directory
  • .. : Parent directory
  • * : Greedy matching of all characters in a name
  • ~ : Your HOME directory (cd without arguments goes to ~ )

linux command and scripting

Raspberry Pi OS : A Linux Distribution

File and Directory Operations Commands

command description
ls list files and directories
cd change directory
pwd print current working directory
mkdir create a new directory
rm remove files and directories
cp copy files and directories
mv move/rename files and directories
touch create an empty file or update file timestamps
cat view the contents of a file
head display the first few lines of a file
tail display the last few lines of a file
ln create links between files
find search for files and directories
source

File Permission Commands

command description
chmod change file permissions
chown change file ownership
chgrp change group ownership
umask set default file permissions
source

File Compression and Archiving Commands

command description
tar Create or extract archive files
gzip Compress files
zip Create compressed zip archives
source

Process Management Commands

command description
ps Display running processes
top Monitor system processes in real-time
kill Terminate a process
pkill Terminate processes based on their name
pgrep List processes based on their name
grep used to search for specific patterns or regular expressions in text files or streams and display matching lines
source

System Information Commands

command description
uname Print system information
whoami Display current username
df Show disk space usage
du Estimate file and directory sizes
free Display memory usage information
uptime Show system uptime
lscpu Display CPU information
lspci List PCI devices
lsusb List USB devices
source

Networking Commands

command description
ifconfig Display network interface information
ping Send ICMP echo requests to a host
netstat Display network connections and statistics
ss Display network socket information
ssh Securely connect to a remote server
scp Securely copy files between hosts
wget Download files from the web
curl Transfer data to or from a server
source

IO Redirection Commands

command description
cmd < file Input of cmd is taken from file
cmd > file Standard output (stdout) of cmd is redirected to file
cmd 2> file Error output (stderr) of cmd is redirected to file
cmd 2>&1 stderr is redirected to the same place as stdout
cmd1 <(cmd2) Output of cmd2 is used as the input file for cmd1
cmd > /dev/null Discards the stdout of cmd by sending it to the null device
cmd &> file Every output of cmd is redirected to file
cmd 1>&2 stdout is redirected to the same place as stderr
cmd >> file Appends the stdout of cmd to file
source

Environment Variable Commands

command description
export VARIABLE_NAME=value Sets the value of an environment variable
echo $VARIABLE_NAME Displays the value of a specific environment variable
env Lists all environment variables currently set in the system
unset VARIABLE_NAME Unsets or removes an environment variable
export -p Shows a list of all currently exported environment variables
env VAR1=value COMMAND Sets the value of an environment variable for a specific command
printenv Displays the values of all environment variables
source

User Management Commands

command description
who Show who is currently logged in
sudo adduser username Create a new user account on the system with the specified username
finger Display information about all the users currently logged into the system, including their usernames, login time, and terminal
sudo deluser USER GROUPNAME Remove the specified user from the specified group
last Show the recent login history of users
finger username Provide information about the specified user, including their username, real name, terminal, idle time, and login time
sudo userdel -r username Delete the specified user account from the system, including their home directory and associated files. The -r option ensures the removal of the user’s files
sudo passwd -l username Lock the password of the specified user account, preventing the user from logging in
su - username Switch to another user account with the user's environment
sudo usermod -a -G GROUPNAME USERNAME Add an existing user to the specified group. The user is added to the group without removing them from their current groups
source

Shortcuts Commands - Navigation

command description
Ctrl + A Move to the beginning of the line
Ctrl + E Move to the end of the line
Ctrl + B Move back one character
Ctrl + F Move forward one character
Alt + B Move back one word
Alt + F Move forward one word
source

Shortcuts Commands - Editing

command description
Ctrl + U Cut/delete from the cursor position to the beginning of the line
Ctrl + K Cut/delete from the cursor position to the end of the line
Ctrl + W Cut/delete the word before the cursor
Ctrl + Y Paste the last cut text
Ctrl + L Clear the screen
source

Shortcuts Commands - History

command description
Ctrl + R Search command history (reverse search)
Ctrl + G Escape from history search mode
Ctrl + P Go to the previous command in history
Ctrl + N Go to the next command in history
Ctrl + C Terminate the current command
source

Magazines

python and the raspberry pi sensehat


Source: How we built a virtual Sense HAT with the Raspberry Pi Foundation

Raspberry Pi Sensehat

Raspberry Pi Sensehat and Python

Two lines to add at the beginning of each Python code

							from sense_hat import SenseHat
							sense = SenseHat()
							  

Source: Programming the Sense HAT on Raspberry Pi with Python

Raspberry Pi Sensehat and Python

Measuring Temperature

							from sense_hat import SenseHat
							sense = SenseHat()

							# Temperature
							temp = sense.get_temperature()
							print("Temperature: %s C" % temp)	
							

Source: Programming the Sense HAT on Raspberry Pi with Python

Raspberry Pi Sensehat and Python

Measuring Humidity

							from sense_hat import SenseHat
							sense = SenseHat()

							# Humidity
							humidity = sense.get_humidity()
							print("Humidity: %s %%" % humidity)	
							

Source: Programming the Sense HAT on Raspberry Pi with Python

Raspberry Pi Sensehat and Python

Measuring Pressure

							from sense_hat import SenseHat
							sense = SenseHat()

							# Pressure
							pressure = sense.get_pressure()
							print("Pressure: %s Millibars" % pressure)	
							

Source: Programming the Sense HAT on Raspberry Pi with Python

Raspberry Pi Sensehat and Python

More functions are available ... (1)
  • sense.get_orientation() : You can also use get_orientation_radians() or get_orientation_degrees() to specify the unit you want.
  • sense.get_compass() : Get the direction of North in degrees (compared to the USB ports direction). 360/0° is North, 90 is East, 270 is West and 180 is South.

Source: Programming the Sense HAT on Raspberry Pi with Python

Raspberry Pi Sensehat and Python

More functions are available ... (2)
  • sense.set_imu_config(compass_enabled, gyro_enabled, acc_enabled) : To select which sensor you want to enable

Source: Programming the Sense HAT on Raspberry Pi with Python

webpublishing with
Hugo Blox and Github Pages

Hugo Blox

Github Pages

  • our Hugo Blox is hosted by Github
  • sign up in Github and create a user
  • this will allow you to contribute to the project

python and jupyter lab

jupyter lab

  • write code in your browser
  • run and see the results immediately
  • try jupyter lab

google colab

kaggle

  • find machine learning challenges
  • find useful codes for machine learning
  • datasets, models, code, discussion groups
  • try kaggle

apply these tools for Luxembourg

webpublishing (html, js, ...)

linux security

notes