diff --git a/Home.md b/Home.md index ad39e17..2963742 100644 --- a/Home.md +++ b/Home.md @@ -1 +1,3 @@ Welcome to the FastCarPlay wiki! + +[Raspberry pi set up](https://github.com/niellun/FastCarPlay/wiki/Raspbery-Pi-Setup) \ No newline at end of file diff --git a/Raspbery-Pi-Setup.md b/Raspbery-Pi-Setup.md new file mode 100644 index 0000000..623a24e --- /dev/null +++ b/Raspbery-Pi-Setup.md @@ -0,0 +1,209 @@ +# Introduction +These are detailed instructions for converting a Raspberry Pi Zero 2W + Carlinkit device into a fully functional CarPlay/Android Auto system. This also serves as documentation of a long journey that I have gone with this setup, including lessons learned along the way. + +The guide may also benefit beginners working on other Raspberry Pi projects, as it covers several general setup procedures commonly needed elsewhere. + +Further will be all sequential steps required to get the set up. You should follow them in order unless you're looking for help with a specific part. Each page is designed to include complete, standalone instructions for each individual step. *Step 0: The story* can be skipped. + +> [!WARNING] +> This is work in progress. I will slowly add content to this guide + +## Steps +0. [The story](#0-story) +1. [Flashing Raspberry Pi OS Lite](#1-flashing) +2. [Custom partition scheme: mount partitions, move /home to own partition](#2-partitioning) +3. [Connect to WIFI using wpa_supplicant and systemd-networkd](#3-wpa-supplicant) +4. [Optimise RPI boot: remove unnecessary services, overclock sd card, zram](#4-optimise-boot) +5. [Set up JWM minimal desktop with autologin](#5-minimal-desktop) +6. [Install ST (Simple Terminal) with scrollback support](#6-st-terminal) +7. [Set up sound (PWM or I2S) with pulseaudio](#7-audio) +8. [RPI AUX (TV) output](#8-tv-out) +9. [Set up FastCarPlay: Carplay and Android Auto receiver](#9-fastcarplay) +10. [Wifi connection and hotspot scripts, integrating them into JWM](#10-wifi-scripts) +11. Tweaking RPi cmd line and boot config +12. Overlay file system + +## Prerequisites +This guide is build on following hardware: +- **Car Head Unit with HDMI or Analog input** - Or any other device that you will use as screen. +- **Raspberry Pi Zero 2 W** - This guide is specifically written for the Raspberry Pi Zero 2 W. Other models may require different configurations. +- **MicroSD Card** - I'm using 64GB UHS-II card for performance, you should be ok with minimum 16GB, Class 10 card. +- **Autokit Adapter** - CPC200-CCPA CarPlay Dongle. Any dongles that work with Autokit andorid application should be ok. +- **USB OTG Adapter** - Need to connect dongle, keyboard and mouse. +- **5V Power Supply** - A reliable 5V, 2.5A power supply is essential for stable operation. +- **Optional: I2S Sound Card** - I'm using PCM5102A I2S player module. Any RPI compatible I2S should work. + +> [!IMPORTANT] +> - Throughout this guide, the username **carplay** will be used for the Raspberry Pi user account. You need to adjust commands if you are using different one. + +# 0 Story + +# 1 Flashing + +# 2 Partitioning + +# 3 WPA-Supplicant + +# 4 Optimise boot + +# 5 Minimal desktop + +# 6 ST terminal + +# 7 Audio + +# 8 TV Output + +# 9 FastCarPlay + +# 10 Wifi scripts +> [!TIP] +> Our setup do not require wifi, so we want to manually turn on wifi connection if we need to install updates or make a hotspot to connect to RPI to see logs or control something without internet access. +> To solve this we will make 2 scripts: +> - Connect to wifi using WPA Supplicant (step 3) +> - Start wifi hot spot using hostapd with DHCP service using dnsmasq. +> +> Also we will add those scripts to JWM (step 5) mouse menu for fast access. + +Our scripts will live in /opt/scripts directory. First we need to create it +``` shell +sudo mkdir /opt/scripts +``` +## WIFI hotspot with DHCP +We will use **hostapd** for hotspot configuration and **dnsmasq** for providing DHCP address for clients. First we need to install both of them. +``` shell +sudo apt install dnsmasq +sudo apt install hostapd +``` +Cause we are running things manually we disable dnsmasq from running automatically +``` shell +sudo systemctl disable dnsmasq.service +``` +Next we need to configure wifi hotspot, so we create configuration file +``` shell +sudo nano /etc/hostapd/hostapd.conf +``` +Put following content in the file +``` +interface=wlan0 +driver=nl80211 +ssid=Carplay +hw_mode=g +channel=6 +wmm_enabled=0 +auth_algs=1 +wpa=2 +wpa_passphrase=wifipassword +wpa_key_mgmt=WPA-PSK +rsn_pairwise=CCMP +country_code=US +max_num_sta=5 +``` +> [!NOTE] +> Replace values of interface with your wireless interface, ssid with network name and wpa_passphrase with wifi password + +- **interface** - Specifies the wireless interface used for the access point +- **driver** - Select driver for wireless device, nl80211 is standard for modern Linux wireless devices and supports most Wi-Fi chipsets +- **ssid** - The network name broadcasted by the AP +- **hw_mode** - Operation mode, 802.11g is compatible with most of devices. +- **channel** - Wifi channel number in the 2.4 GHz band +- **wmm_enabled** - Controls Wi-Fi Multimedia (WMM), which prioritizes traffic for better Quality of Service (QoS) +- **auth_algs** - Enables open system authentication for WPA2-PSK setups. +- **wpa** - Select WPA security protocol version +- **wpa_passphrase** - Wi-Fi password (must be 8–63 characters) +- **wpa_key_mgmt** - Key management algorithm for WPA, PSK is suitable for small networks +- **rsn_pairwise** - Select encryption for WPA, AES-CCMP is secure and standard +- **country_code** - Specifying the country code ensures compliance with local Wi-Fi regulations +- **max_num_sta** - Limits the number of connected clients + +Next we create a script for our wifi access point. +``` shell +sudo nano /opt/scripts/enable_ap.sh +``` +Put the following into the file. The script will activate wifi, stop any active wifi connections, set up WIFI Access Point according to our configuration with address 10.0.10.1. Next it will run DHCP service that will provide clients with IP addresses in range 10.0.10.2 to 10.0.10.20. We are using & in start commands to make service run in separate process and continue and not block the script. +``` shell +#!/bin/bash + +echo "> Stopping services" +sudo rfkill unblock wifi +sudo killall hostapd dnsmasq wpa_supplicant + +echo "> Setting static IP on wlan0" +sudo ip link set wlan0 down +sudo ip addr flush dev wlan0 +sudo ip addr add 10.0.10.1/24 dev wlan0 +sudo ip link set wlan0 up + +echo "> Starting dnsmasq" +sudo dnsmasq --interface=wlan0 --bind-interfaces --dhcp-range=10.0.10.2,10.0.10.20,255.255.255.0,12h & + +echo "> Starting hostapd" +sudo hostapd /etc/hostapd/hostapd.conf & +``` +> [!NOTE] +> Replace wlan0 with your wireless interface + +Finally we need to make script executable +``` shell +sudo chmod +x /opt/scripts/enable_ap.sh.sh +``` + +## Connect to WIFI with WPA Supplicant +For wifi connection we will use same wpa_supplicant configuration that we created on step 3. Create the script to run wpa_supplicant manually. +``` shell +sudo nano /opt/scripts/connect_wifi.sh +``` +Put the following into the file. The script will activate wifi, stop any active wifi connections, connect to wifi using wpa_supplicant and start service that sync time with NTP server. +``` shell +#!/bin/bash + +echo "> Stopping services" +sudo rfkill unblock wifi +sudo killall hostapd dnsmasq wpa_supplicant + +echo "> Resetting wlan0" +sudo ip link set wlan0 down +sudo ip addr flush dev wlan0 +sudo ip link set wlan0 up + +echo "> Starting wpa_supplicant" +sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant-wlan0.conf +sudo systemctl start systemd-timesyncd.service +``` +> [!NOTE] +> Replace wlan0 with your wireless interface, replace wpa_supplicant-wlan0.conf with wpa supplicant configuration created on step 3 + +Finally we need to make script executable and disable automatic start of wpa_supplicant and timesync services cause we will run them manually now +``` shell +sudo chmod +x /opt/scripts/connect_wifi.sh +sudo systemctl disable systemd-timesyncd.service +sudo systemctl disable wpa_supplicant.service +sudo systemctl disable wpa_supplicant@wlan0.service +``` +## Enable SUDO in scripts +Our scripts are using SUDO which require elevate permissions. Thats require to enter password, but we want to run scripts from menu. So we need to configure our user to run sudo commands without password. There is a way to configure certain commands only, but simple (and less secure) way is to enable everything. +> [!WARNING] +> This might already be enabled on Raspberry Pi OS, so check if you can run those scripts without password + +Create extra configuration for /etc/sudoers +``` shell +sudo nano /etc/sudoers.d/010_pi-nopasswd +``` +Put this into the file. Enable your user to execute all sudo commands without password +``` +raspberry ALL=(ALL) NOPASSWD: ALL +``` +## Add wifi scripts to JWM +Now we can add wifi scripts to JWM click menu. Edit main configurations +``` shell +sudo nano /etc/jwm/system.jwmrc +``` +Under \ add following lines. You can also add \ to make it into own section. +``` xml +/opt/scripts/enable_ap.sh +/opt/scripts/connect_wifi.sh +``` +Now you can restart JWM from mouse menu to check that scripts are there. After reboot you will need to activate one of those scripts to connect to wifi. +# 11 Tweaks + +# 12 Overlay FS