# Raspberry Pi

Notes

# Setup notes

## Writing an OS image to the sdcard (or usb drive)

```
sudo dd bs=4M if=/path/to/os/image of=/dev/mmcblk0 status=progress
```

## Headless wifi setup

Mount the boot partition and create a file called *wpa_supplicant.conf* with the following contents:

```
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="SSID"
    scan_ssid=1
    psk="PASSWORD"
    key_mgmt=WPA-PSK
}
```

## Enable SSH prior to first boot 

Mount the boot partiton and create an empty file called *ssh:*

```
touch /path/to/boot ssh
```

## Initial setup

Use the *raspi-config* utility to set the follwing options as desired:

- Network Options > Hostname > HOSTNAME
- Localization Options > Change Locale > *en_US.UTF-8*
- Localization Options > Change Time Zone > *America/New_York*
- Localization Options > Change WLAN Country > *US*
- Interfacing Options > SSH > *Yes*
- Interfacing Options > SPI > *Yes*
- Interfacing Options > I2C > *Yes*
- Advanced Options > Overscan > No
- Advanced Options > Memory Split > 32
- Advanced Options > Screen Blanking > No

## Changing the default username (pi)

<p class="callout warning">This must be done while logged in as the root user. It cannot be done (with sudo or su) while the pi user is looged in.</p>

<p class="callout info">To enable root login, edit <i>/etc/passwd,</i> removing the 'x' after the first colon on the line that begins with <code>root:x:...</code>. Also, if attempting this over SSH, the <i>/etc/sshd.conf</i> file will need to be modified, changing the line <code>PermitRootLogin=prohibit-password</code> to <code>PermitRootLogin=yes</code>. Don't forget to revert these changes once the pi user has been renamed.</p>

```
usermod -l USERNAME pi
usermod -d /home/USERNAME -m USERNAME
groupmod -n USERNAME pi
rm /etc/sudoers.d/010_pi-nopasswd
```

## Disable WiFi Power Managment

Create the file `/etc/network/interfaces.d/wlan0` with the following contents:
```
allow-hotplug wlan0
iface wlan0 inet manual
wireless-power off
```

# List of config.txt options

Miscellaneous config.txt options:

### Display
```
disable_splash=1  # Disable the rainbow splash screen on bootup
lcd_rotate=2  # Rotate lcd displays like the official touchscreen 180 degrees;
```
### LEDs

```
[pi0]
dtparam=act_led_trigger=none  # Green LED, available triggers are listed in /sys/class/leds/led0/trigger, default is mmc0
dtparam=act_led_activelow=off  # inverts the activity state

[all]
dtparam=act_led_trigger=none  # Green LED, available triggers are listed in /sys/class/leds/led0/trigger, default is mmc0
dtparam=act_led_activelow=off

dtparam=pwr_led_trigger=none  # Red LED, available triggers are listed in /sys/class/leds/led1/trigger, default is default_on
dtparam=pwr_led_activelow=off
```

### Wireless
```
dtoverlay=disable-bt  # Disable buit-in bluetooth
dtoverlay=disable-wifi  # Disable built-in wifi
```

# Google AIY voice kit v1

## Enable the driver:
Edit/Add to */boot/config.txt:*

```
dtoverlay=i2s=on
...
#dtparam=audio=on
...
# Google AIY voice kit v1
dtoverlay=i2s-mmap
dtoverlay=googlevoicehat-soundcard
```

# ALSA configuration:

Create */etc/asound.conf:*

```
options snd_rpi_googlevoicehat_soundcard index=0

pcm.softvol {
    type softvol
    slave.pcm dmix
    control {
        name Master
        card 0
    }
}

pcm.micboost {
    type route
    slave.pcm dsnoop
    ttable {
        0.0 30.0
        1.1 30.0
    }
}

pcm.!default {
    type asym
    playback.pcm "plug:softvol"
    capture.pcm "plug:micboost"
}

ctl.!default {
    type hw
    card 0
}
```

Reboot after editing *asound.conf.*

## Verify:

Verify that the sound card's output and input is recognized with

```
aplay -l
arecord -l
```

## Test:

Record a 5 second *test.wav* with:

```
arecord -c 2 -f cd -d 5 test.wav
```

Play *test.wav* with:

```
aplay test.wav
```

# Pulseaudio

Install the `pulseaudio` package, and optionally `pulsemixer` for volume control. The microphone volume is low under the default ALSA driver, pulseaudio can 'overdrive' the source volume. 200-250% should be sufficent.

After installed, start the pulseaudio server with `pulseaudio -D`. List sources (inputs) with `pactl list sources`, note the  index # of the soundcard, make sure it's not the null-monitor or loopback from the sink (output). Use that index number to increase the source volume, for example if the source index is #1: `pactl set-source-volume 1 250%`