/RaspberryPiSetup

Primary LanguagePythonMIT LicenseMIT

Image

  • Download Raspbian image, no need to unzip - image download page
  • Download Etcher
  • Plug in SD card
  • Etch the zip file directly to the SD card
  • Mount the card and create an empty file called "ssh" in the root (included in repo for Windows) - this enables SSH on first boot (see here)

Source docs

Other options

First boot

  • Plug into ethernet and SSH as user pi password raspberry
  • Change the password - passwd and follow instructions
  • Change the hostname to something sensible - sudo raspi-config in the networking menu
  • Enable SSH permanently - sudo raspi-config and in the menu (details)

Once networking setup, or if ethernet in

  • sudo apt-get update
  • sudo apt-get install vim
  • sudo apt-get autoremove

Source docs

Networking

Host

  • Put the contents of networking/host/iptables.conf in /etc/iptables.conf

  • Put the contents of networking/host/wlan0 in /etc/network/interfaces.d/wlan0

  • Put the contents of networking/host/wlan1 in /etc/network/interfaces.d/wlan1

  • Put the contents of networking/host/general in /etc/network/interfaces.d/general

  • Append the contents of networking/host/dhcpcd.conf to /etc/dhcpcd.conf

  • networking/host/wpa_supplicant-wlan1.conf provides an example of how to specify wifi networks to connect to in /etc/wpa_supplicant/wpa_supplicant-wlan1.conf

  • Install DHCP server: sudo apt-get install isc-dhcp-server

  • Put contents of networking/host/dhcpd.conf in /etc/dhcp/dhcpd.conf

  • Edit /etc/default/isc-dhcp-server and set INTERFACESv4="wlan0" and INTERFACESv6="wlan0"

  • Install the AP server: sudo apt-get install hostapd

  • Put the contents of networking/host/hostapd.conf in /etc/hostapd/hostapd.conf

  • Change the # for the passphrase for the network

  • Edit /etc/default/hostapd and point DAEMON_CONF to /etc/hostapd/hostapd.conf

  • For some reason the service is masked in later raspbians: sudo systemctl unmask hostapd sudo systemctl enable hostapd sudo systemctl start hostapd

  • Reboot machine: sudo shutdown -r now

Partial guide

More

Angry, but helpful

Probably the best docs

Client

  • Run ifconfig to check you have wlan0

  • Put the contents of networking/client/wlan0 in /etc/network/interfaces.d/wlan0

  • Put the contents of networking/client/general in /etc/network/interfaces.d/general

  • Replace the two #'s with the SSID and passphrase for your robot's network, and also its static IP number

  • Append the contents of networking/host/dhcpcd.conf to /etc/dhcpcd.conf

  • Reboot machine: sudo shutdown -r now

Hardware

Drive reset for initio

The Pirocon board has an annoying habit of driving the wheels on the first time it is powered on (restarting the Pi seems to be fine once the power is on).

  • mkdir ~/code/drivereset
  • Put the contents of the drivereset directory in there, except drivereset.service
  • cd ~/code/drivereset
  • Put drivereset/drivereset.service in ~/.config/systemd/user/
  • sudo loginctl enable-linger pi
  • systemctl --user enable drivereset.service

Guide

Servod for initio (servo endpoints only)

  • wget -q http://4tronix.co.uk/initio/servod.xxx -O servod
  • chmod +x servod

PiFace

  • Enable SPI in sudo raspi-config
  • pip install pifacedigitalio
  • pip install pifacecommon

Infrared

https://help.ubuntu.com/community/LIRC https://github.com/tompreston/python-lirc

Bluetooth

https://ubuntuforums.org/showthread.php?t=1332197

Raspberry Pi camera

https://picamera.readthedocs.io/en/release-1.13/recipes1.html

The sensor itself has a native resolution of 5 megapixel, and has a fixed focus lens onboard. In terms of still images, the camera is capable of 2592 x 1944 pixel static images, and also supports 1080p @ 30fps, 720p @ 60fps and 640x480p 60/90 video recording.

>>> from picamera import PiCamera
>>> camera = PiCamera()
>>> 
>>> camera.capture('/home/pi/zoidberg-deploy/derp.jpg')

Webcams

https://www.raspberrypi.org/documentation/usage/webcams/

fswebcam --device v4l2:/dev/video0 --input 0 --no-banner --resolution 640x360 derp.jpg

Software

SSH

  • Enable with sudo raspi-config in the networking section

Share folders

  • sudo apt-get install samba samba-common-bin
  • mkdir code
  • chmod 777 code
  • sudo smbpasswd -a pi and add the password
  • Put the contents of smb.conf at the bottom of /etc/samba/smb.conf
  • Also in that file, comment out the bit about "homes" - this is spread over quite a few lines
  • Restart with sudo systemctl restart smbd.service

Example

Redis

On the host server:

  • sudo apt-get install redis-server
  • sudo vim /etc/redis/redis.conf
  • In this file, set the "bind" directive to include 192.168.0.1
  • sudo systemctl restart redis-server.service

On any clients you want to try the CLI with:

  • sudo apt-get install redis-tools

For any python clients:

  • pip install redis

Python

  • sudo apt-get install python-pip

Creating a userspace python systemd service

Template in the PythonService folder.

  • sudo apt-get install python-systemd
  • Copy the whole folder to /home/pi/zoidberg-deploy/PythonService (or use zoidberg to deploy it)
  • Make a symlink to the service file: ln -s ~/code/PythonService/service.service ~/.config/systemd/user/service.service
  • If you want to start it on boot, enable it with systemctl --user enable service.service
  • Otherwise you can just start it with systemctl --user start service.service
  • If you change the service file afterwards, you need to do systemctl --user daemon-reload

Based on this guide

Systemctl

List services: systemctl --user list-unit-files

Link into: ./config/systemd/user

ln -s ~/code/*.service ~/.config/systemd/user/*.service

Docker / K8s

Lots of useful docker / k8s links:

https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl https://stackoverflow.com/questions/47202705/how-to-run-my-python-script-on-docker https://hub.docker.com/r/arm32v6/redis https://hub.docker.com/r/arm32v6/python https://stackoverflow.com/questions/30494050/how-do-i-pass-environment-variables-to-docker-containers https://runnable.com/docker/python/dockerize-your-python-application https://kubernetes.io/docs/tutorials/configuration/configure-redis-using-configmap/ https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/ https://stackoverflow.com/questions/48577544/how-to-connect-redis-cluster-from-application-in-kubernetes-cluster https://collabnix.com/building-arm-based-docker-images-on-docker-desktop-made-possible-using-buildx/ https://docs.docker.com/v17.09/engine/userguide/eng-image/dockerfile_best-practices/#run https://docs.docker.com/buildx/working-with-buildx/ https://docs.docker.com/docker-for-mac/multi-arch/ docker/buildx#98 https://github.com/docker/buildx https://www.slideshare.net/weaveworks/advanced-build-techniques-for-container-images-with-adrian-mouat https://pythonspeed.com/articles/base-image-python-docker-images/ https://docs.docker.com/engine/reference/commandline/run/