Install image to SD card
Use a GUI program or sudo dd bs=1M if=Downloads/2017-04-10-raspbian-jessie-lite.img of=/dev/disk2
in Linux/MAC OS.
Headless Boot
cd /path/to/pi/boot
first and then:
cat > wpa_supplicant.conf <<EOF
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="this-is-wifi"
psk="zeroshaha"
key_mgmt=WPA-PSK
scan_ssid=1
}
EOF
touch ssh
Change username/password
ssh pi@pi0
first, then ssh root@pi0
again.
# first time
sudo raspi-config #extent file system and hostname
sudo sed -i 's%#PermitRootLogin prohibit-password%PermitRootLogin yes%' /etc/ssh/sshd_config
sudo passwd root #reset the passwd for root
sudo reboot
# second time
usermod -l nick pi && groupmod -n nick pi && usermod -d /home/nick -m nick #change user/group name and reset home
sed -i 's%PermitRootLogin yes%%' /etc/ssh/sshd_config
usermod -p ! root # reset password for root to impossible
Install Bluealsa
sudo apt install bluealsa
or compile it yourself:
cd ~
git clone https://github.com/mstorsjo/fdk-aac
cd fdk-aac
libtoolize
autoreconf --install
mkdir build && cd build
../configure --prefix=/usr
make
make install
cd ~
sudo apt install libasound2-dev libbluetooth-dev libsbc-dev
git clone https://github.com/Arkq/bluez-alsa.git
cd bluez-alsa
mkdir build && cd build
autoreconf --install
mkdir build && cd build
../configure --enable-aac --enable-debug
make
make install
sudo ln -s /usr/lib/alsa-lib/libasound_module_ctl_bluealsa.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_ctl_bluealsa.so
sudo ln -s /usr/lib/alsa-lib/libasound_module_pcm_bluealsa.so /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_bluealsa.so
echo export LIBASOUND_THREAD_SAFE=0 >> ~/.bashrc
tee /lib/udev/rules.d/62-bluealsa.rules <<EOF
ACTION=="add", KERNEL=="hci0", ENV{SYSTEMD_WANTS}+="bluealsa.service"
EOF
cat <<EOF > /lib/systemd/system/bluealsa.service
[Unit]
Description=BluezAlsa proxy (modified)
Requires=bluetooth.service
After=bluetooth.target bluetooth.service
[Service]
Type=simple
ExecStart=/usr/bin/bluealsa
[Install]
WantedBy=multi-user.target
EOF
# need to disable it if pulseaudio installed
sudo mv /usr/share/alsa/pulse-alsa.conf{,.bak}
sudo mv /usr/share/alsa/alsa.conf.d/50-pulseaudio.conf{,.bak}
sudo mv /usr/share/alsa/alsa.conf.d/pulse.conf{,.bak}
sudo systemctl disable pulseaudio
Setup Bluetooth
Remove the old one and then reconnect, the last failed connect may cause some problems
sudo bluetoothctl
#>> power on
#>> scan on
#>> remove FC:58:FA:30:6B:6A
#>> pair FC:58:FA:30:6B:6A
#>> trust FC:58:FA:30:6B:6A
#>> connect FC:58:FA:30:6B:6A
Setup default Audio device
cat <<EOF > /etc/asound.conf
pcm.!default {
type asym
capture.pcm "mic"
playback.pcm "bluetooth"
}
ctl.!default {
type bluealsa
}
pcm.bluetooth {
type plug
slave.pcm {
type bluealsa
device "FC:58:FA:30:6B:6A"
profile "a2dp"
}
hint {
show on
description "Use the A2 bluetooth headset with Blue-Alsa module as default"
}
}
pcm.mic {
type plug
slave {
pcm "plughw:1,0"
}
}
EOF
Disable on board wifi or bluetooth
cat >> /boot/config.txt <<EOF
dtoverlay=pi3-disable-wifi
#dtoverlay=pi3-disable-bt
EOF
sudo systemctl stop bluetooth.service && sudo systemctl disable bluetooth.service
sudo systemctl stop hciuart.service && sudo systemctl disable hciuart.service
Maybe set the proxy
echo export https_proxy=http://127.0.0.1:8123 >> ~/.bashrc
echo export http_proxy=http://127.0.0.1:8123 >> ~/.bashrc
cat >> /etc/hosts <<EOF
192.168.1.8 pi.local
EOF
cat > /etc/apt/apt.conf.d/05proxy <<EOF
Acquire::http::Proxy "http://pi.local:3142";
EOF
Install good software
sudo apt update
# remote file system
sudo apt install autofs cifs-utils
cat | sudo tee /etc/smbcredentials <<EOF
username=$USERNAME
password=$PASSWORD
EOF
sudo chown nick:nick /etc/smbcredentials
chmod 600 /etc/smbcredentials
cat | sudo tee /etc/auto.home <<EOF
/data -fstype=cifs,credentials=/etc/smbcredentials,uid=1000,gid=1000 ://pi.local/data
/media -fstype=cifs,credentials=/etc/smbcredentials,uid=1000,gid=1000 ://pi.local/media
#/home/user -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,workaround=rename,ssh_command=/usr/local/sbin/ssh_user :sshfs\#user@host\:/home/user
EOF
cat | sudo tee -a /etc/auto.master <<EOF
/- /etc/auto.home uid=1000,gid=1000,--timeout=30,--ghost
EOF
# audio system
sudo apt install -y cmus
mkdir -p ~/.cmus && echo "set output_plugin=alsa" > ~/.cmus/rc
# snowboy
sudo apt-get install python3-pyaudio sox libatlas3-base
mkdir -p ~/snowboy && curl -L https://github.com/kitt-ai/snowboy/tarball/v1.3.0 | tar zx -C snowboy --strip 1
curl 'https://transfer.sh/VtbYX/snowboy_py3-.tar.gz' |tar -xz -C snowboy --strip 1
curl 'https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/rpi-arm-raspbian-8.0-1.1.1.tar.bz2' |tar -xj -C snowboy --strip 1
python3 demo.py resources/models/snowboy.umdl
Turn PI zero to a USB Gadget
# enable the dwc2 kernel module
echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
# make the pi work as ether gadget when dwc2 module loaded
sed -i 's#rootwait$#rootwait modules-load=dwc2,g_ether#' /boot/cmdline.txt
# configure the static IP for the USB PI, need to manually set the IP of your PC in the same network
cat > /etc/network/interfaces.d/usb0 <<EOF
allow-hotplug usb0
iface usb0 inet static
address 192.168.7.2
netmask 255.255.255.0
network 192.168.7.0
broadcast 192.168.7.255
gateway 192.168.7.1
EOF
pi can also work as serial device, which do not need any driver. see more details in adafruit’s website.