/raspberry-pi

Quickly setup a raspberry pi without having to search google 400 times

image

Installation/OS Install (Windows)

Download an OS from https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-bit

2018-06-27-raspbian-stretch-lite.zip

NOTE: No need to extract the .img - Etcher will read the .zip just fine

Flash using Etcher, use a USB->microSD Card reader:

https://github.com/balena-io/etcher

Enable SSH (assumes BOOT volume is E:\ drive)

new-item -ItemType File -Name ssh -Path e:\ 

Auto-join WiFi (update ssid and psk) (assumes BOOT volume is E:\ drive

$config = @"
country=AU
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
	ssid="GlobalEliteHackingCrew"
	psk="password"
	key_mgmt=WPA-PSK
}
"@
$config | out-file E:\wpa_supplicant.conf

OS install done


Fire up the pi ๐Ÿš€

Find the pi on the network - use Fing for Android/iOS


ssh pi@ipaddress

password: raspberry

Set WiFi locale

sudo raspi-config nonint do_wifi_country AU

Set hostname

sudo hostnamectl set-hostname my-raspberry-pi	

Set timezone

Sudo raspi-config 

๐Ÿ“ท Camera

Enable camera

3, interface options

sudo raspi-config

๐Ÿ“ธ Test camera

raspistill -o  image.jpg 

Update and upgrade

sudo apt-get update -y && sudo apt-get dist-upgrade -y

Install Git, clone the RPi_Cam_Web_interface

sudo apt-get install git -y
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git 
sudo ./RPi_Cam_Web_Interface/install.sh
sudo reboot

Documentation

http://elinux.org/RPi-Cam-Web-Interface

  • WEB INTERFACE

Camera > Motion Detection: internal

Camera > Buffer: 4000

Camera > Preview Quality: 15

Quality is the jpeg compression factor (0-100). Lower numbers give better compression at the expense of quality. It is set to 25 by default which gives pretty good compression and not too much degradation. You can try lowering it to say 15 which will significantly lower sizes further but you will start to see some degradation. Lower than this it will start to get bad.

Divider is the rate at which new data is fetched. It is the video fps (default 25) divided by 'Divider'. Nominally that would mean it is trying to update at 25fps but in practice other delays lower this a bit. Increasing the divider lowers the fetch frame rate so 3 would give a nominal rate of 8fps. This will also have a dramatic effect on bandwidth.

  • Custom annotation

image

%h:%m:%s %a 

Use %a, this references /dev/shm/mjpeg/user_annotate.txt

Use a cron job to update this file automatically (eg for day of week):

sudo crontab -e

  * * * * * date +"\%a \%d \%b \%Y"  > /dev/shm/mjpeg/user_annotate.txt 

Change site name/page title

image

sudo nano /var/www/html/config.php 
define('CAM_STRING',"pi-camera");

Motion detection/Notifications

sudo nano /var/www/html/macros/motion_event.sh 
sudo "#!/bin/bash" >>  /var/www/html/macros/motion_event.sh 

Replace Xs with your pushbullet API key

#!/bin/bash 
curl -u XXXXXXXXXXXXXXXXXXXXXXXXX: https://api.pushbullet.com/v2/pushes -d type=note -d title="ALERT" -d body='Motion detected!' 
sudo chown www-data:www-data /var/www/html/macros/motion_event.sh 

sudo chmod 764 /var/www/html/macros/motion_event.sh 

Add buffer

video_buffer in ms

sudo nano /etc/raspimjpeg 

Add FAVICON

  • Upload a favicon.ico to HOME
sudo cp ~/favicon.ico /var/www/

Disable camera LED

Note: need to do this interactively unless you're root Add:

disable_camera_led=1

to:

/boot/config.txt

Dark/night mode GUI

System > Style > Night > OK

Night Vision/IR camera

๐Ÿ“๐Ÿšซ Pi-Hole

Disable IPv6 queries showing up

sudo nano /etc/pihole/pihole-FTL.conf 

AAAA_QUERY_ANALYSIS=no

Disable PTR records showing up

ANALYZE_ONLY_A_AND_AAAA=true

Add multiple domains to blacklist

image

Adlist location

/etc/pihole/adlists.list 

Remove password from web console

pihole -a -p

Install pihole

curl -sSL https://install.pi-hole.net | bash

Tail pihole log

tail -f /var/log/pihole.log

Tail pihole log (show only blocked requests)

tail -f /var/log/pihole.log | grep 0.0.0.0

*improved version:

tail -f /var/log/pihole.log | cut -c 31-100 | grep 0.0.0.0 
  • Show last entries added to blocklist
tail /etc/pihole/black.list 

Remove background image

sudo mv /var/www/html/admin/img/boxed-bg-dark.png /var/www/html/admin/img/boxed-bg-dark.png2

Adjust HOSTS/DNS names

sudo nano /etc/hosts 

Top 50 domains (past day)

sqlite3 /etc/pihole/pihole-FTL.db "SELECT domain FROM queries WHERE timestamp>='$(($(date +%s) - 86400))'" | sort | uniq -c | sort -n -r | head -50

Blocked domains for specific client

sqlite3 /etc/pihole/pihole-FTL.db "SELECT domain FROM queries WHERE client='192.168.1.1' AND (STATUS == 1 OR STATUS == 4 OR STATUS == 5 OR STATUS == 9 OR STATUS == 10 OR STATUS == 11) AND timestamp>='$(($(date +%s) - 80000))'"  | sort | uniq

sqlite3 "/etc/pihole/pihole-FTL.db" "SELECT domain,count(domain) FROM queries WHERE (STATUS == 2 OR STATUS == 3) GROUP BY domain ORDER BY count(domain) DESC LIMIT 3"

Show clients per IP

sqlite3 /etc/pihole/pihole-FTL.db "SELECT domain FROM queries WHERE client='192.168.1.12' AND timestamp>='$(($(date +%s) - 86400))'" | sort | uniq -c | sort -n -r | head -10

Modify default recent queries (instead of just 10 by default)

sudo nano /var/www/html/admin/scripts/pi-hole/js/queries.js

First value is the default the page loads with. Modify both the first and the 2nd array (eg 60):

image

Setup exclusions for specific devices

Happy wife, happy life

๐Ÿ•นRetro-Pi

sudo update-locale LC_ALL="en_GB.UTF8" 
sudo update-locale LANGUAGE="en_GB:en" 
sudo apt-get install git lsb-release -y 
sudo apt-get update 
sudo apt-get -f install 
sudo apt-get dist-upgrade 
git clone --depth=1 https://github.com/RetroPie/RetroPie-Setup.git 

cd RetroPie-Setup 
chmod +x retropie_setup.sh 
sudo ./retropie_setup.sh 

Download the img

Stretch the aspect ratio

๐Ÿ”ŒPinout/GPIO ๐Ÿ”Œ

Zero

image

2B

image

๐Ÿ’ก LEDs ๐Ÿ’ก

๐ŸŒก Temperature Sensor ๐ŸŒก

DSB18B20

  • comes in transistor or waterproof probe form
  • is a digital probe
  • -55ยฐC to 125ยฐC range
  • 3.0V to 5.0V operating voltage

Enable 1-Wire sensor

sudo raspi-config

Wiring

image

image

DS18B20 Wiring: Red = VCC, Yellow = Data, Black = GND

Temp readout

cat /sys/bus/w1/devices/28*/w1_slave | grep t | cut -d= -f2

Stepper motor

https://www.rototron.info/raspberry-pi-stepper-motor-tutorial/

https://thinkingofpi.com/getting-started/raspberry-pi-stepper-motor/

Servo

image

image

image

Anti-Clockwise

import RPi.GPIO as GPIO
import time

#print("doing stuff")

servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)

p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz

p.start(2.5) # clockwise
time.sleep(1) # run for x seconds
p.stop()

sudo apt install python3-gpiozero -y