# Listener software (Mplayer + drivers)
## Summary
User: grace
Hostname: listener.local
Password: emergence
Running mplayer, soundcard library, lcd graphics library, and custom python code for text printing logic.

## Bill of Materials
* Raspberry pi zero wh - https://www.waveshare.com/product/raspberry-pi/boards-kits/raspberry-pi-zero-2-w-cat/raspberry-pi-zero-2-w.htm?sku=21038
* Waveshare UPS with 1000mah battery - https://www.waveshare.com/ups-hat-c.htm
* Waveshare sound card hat with speakers- https://www.waveshare.com/wm8960-audio-hat.htm
* 1602 LCD screen - https://www.waveshare.com/lcd1602-i2c-module-blue.htm?sku=30496
* Jumper wires - https://www.waveshare.com/product/accessories/adapters-cables-antennas/jumper-wires.htm
* mini HDMI to hdmi cable - https://hosatech.com/products/video/hdmi/hdmc-400/
* micro USB male to usb a femail adapter - https://www.amazon.com/dp/B01C6032G0
* Keyboard with usb a cable - https://www.amazon.com/AmazonBasics-Matte-Keyboard-QWERTY-Layout/dp/B07WJ5D3H4/

## Hardware assembly
* Solder header to the pi if not pre-soldered
* Plug the battery into the UPS board
* Screw the UPS to the pi
* Screw a next level of standoffs to the pi
* Put the audio hat on the pi's headers, and screw it to the standoffs
* Plug in the speakers
* Plug the jumper wires into the screen and the pi according to the [screen-wiring.png](screen-wiring.png) file (via https://peppe8o.com/1602-lcd-raspberry-pi-display/).

## Pre work
1. install raspian lite 64 for raspi zero
2. configure user and wifi and turn on ssh services when you install
3. boot
4. find the ip address of the pi and ssh to it

## Setup instructions
### Creature comforts
sudo apt update && install git vim zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

### Waveshare soud card drivers
Follw instructions at https://www.waveshare.com/wiki/WM8960_Audio_HAT


#### Install drivers
git clone https://github.com/waveshare/WM8960-Audio-HAT
cd WM8960-Audio-HAT
sudo ./install.sh 
sudo reboot
sudo dkms status 

Check for drivers installed

#### Test drivers
sudo apt install mplayer
mplayer -playlist http://blackportaldetroit.com:1313/portal.m3u

#### Daemonize radio
sudo vim /lib/systemd/system/listener.service
```
[Unit]
Description=Listenign Service
[Service]
User=root
Type=simple
Restart=on-failure
RestartSec=5
WorkingDirectory=/home/grace
ExecStart=mplayer -playlist http://108.204.128.201:1313/portal.m3u

[Install]
WantedBy=multi-user.target
```

sudo systemctl daemon-reload
sudo systemctl enable listener

sudo reboot

#### Raise volume
alsamixer 
sudo alsactl store

### LCD Screen
Follow https://peppe8o.com/1602-lcd-raspberry-pi-display/

sudo apt install python3-pip python3-smbus i2c-tools -y
sudo raspi-config 

enable i2c in interface options




python3 -m venv screen --system-site-packages
source ./screen/bin/activate

pip3 install adafruit-circuitpython-charlcd

wget https://peppe8o.com/download/python/lcd/i2c-lcd-test-01-hello-world.py

i2cdetect -y 1

python3 i2c-lcd-test-01-hello-world.py