Code Monkey home page Code Monkey logo

spipod's Introduction

Reminder to self: comment out framebuffer part of /boot/config.txt, this is only used for testing via vnc viewer

\

And on dev build add chmod 766, so spotifypod.py can change brightness

on my device, the dir to edit brightness is:

\

/sys/class/backlight/amdgpu_bl0/brightness

\

on rpi /sys/class/backlight/rpi_backlight/brightness

I'm using a ipod classic from 2004 (A1059)

sPot

This is a Fork of the Spotify Ipod by Guy Dupont

This code is meant to accompany my own version of this project in which a Spotify client is built into an iPod "Classic" from 2004. In my version everything is meant to run on a Raspberry Pi Zero 2 W.

Instructions

I have used python 3.9.2 idk if itll work with other versions

I used a Raspberry Pi zero 2 W. This guide uses the newest version of raspotify, which is not available to the older Rpi Zero models. You can still try with older versions of raspotify, but your mileage may vary.


Since we are using the lite version of raspbian, some extra packages need to be installed:
And if you need to configure wifi to enable ssh & vnc, you can edit /etc/wpa_supplicant/wpa_supplicant.conf

Install updates

sudo apt-get update 
sudo apt-get upgrade

install prerequisites

sudo apt-get install midori

sudo apt-get install python-pip python-dev

sudo apt-get install python3-pip python-dev

sudo apt-get install realvnc-vnc-server

sudo apt install python-pigpio python3-pigpio

sudo apt install python-setuptools python3-setuptools

sudo apt install python3-pip

sudo apt-get install python3-tk 

sudo apt-get install python3-pil 
sudp apt-get install python3-pil.imagetk

sudo apt-get install redis-server

sudo apt-get install openbox

sudo apt install xorg

sudo apt-get install lightdm

sudo apt-get install x11-xserver-utils

then set redis-server to start on boot, which it does automatically but on some devices it don't:
sudo systemctl enable redis-server
& do this:
sudo service redis-server start
do the same for raspotify in later steps after it has been installed:
sudo systemctl enable raspotify \

Clickwheel setup

NOTICE: the pins on the clickwheel ribbon cable should face down on the breakout board The schematics for clickwheel wiring is at the bottom of the README

Install PiGPIO for clickwheel

wget https://github.com/joan2937/pigpio/archive/master.zip
unzip master.zip
cd pigpio-master
make
sudo make install

run

gcc -Wall -pthread -o click click.c -lpigpio -lrt 

to compole click.c
then run sudo ./click & so you can test the clickwheel (assuming the wiring is done)
now just make sure the pigpio daemon that the spotifypod.py script will need is the one that is started by sudo ./click & do not manually start or enable it with systemctl etc. that would cause multiple instances of pigpiod

Display setup

I used a 2 inch model waveshare ST7789V display wiring for display also below.

I used this guide which links to this solution on github

basically this is how to setup:
Edit /boot/config.txt & comment dtoverlay=vc4-kms-v3d & add:

hdmi_group=2
hdmi_mode=87
hdmi_cvt=320 240 60 1 0 0 0
hdmi_force_hotplug=1

restart the pi, then

sudo apt install cmake git
cd ~
git clone https://github.com/juj/fbcp-ili9341.git
cd fbcp-ili9341

then edit st7735r.h & change #define DISPLAY_NATIVE HEIGHT 240 to #define DISPLAY_NATIVE HEIGHT 320 in line 20
Then edit st7735r.cpp and comment out the line starting with SPI_TRANSFER (around line 100) then add SPI_TRANSFER(0x37, 0, 0); & save

then type

mkdir build
cd /build

Depending on what gpio pins you've soldered (refer to pinout below) to TFT_DATA_CONTROL, TFT_RESET_PIN and TFT_BACKLIGHT might be different. for my case I used:

cmake -DST7789=ON -DGPIO_TFT_DATA_CONTROL=24 -DGPIO_TFT_RESET_PIN=25 -DGPIO_TFT_BACKLIGHT=18 -DSPI_BUS_CLOCK_DIVISOR=30 -DSTATISTICS=0 -DDISPLAY_BREAK_ASPECT_RATIO_WHEN_SCALING=ON -DUSE_DMA_TRANSFERS=OFF ..

in case you need to flip the screen, include this option before the two dots at the end:

-DDISPLAY_ROTATE_180_DEGREES=ON

afterwards run

sudo make -j


you can now test the driver in that same folder with

sudo ./fbcp-ili9341


but since the driver should start automatically on boot we have to do one last thing. Open /etc/rc.local with a text editor with sudo privileges (e.g.):
sudo nano /etc/rc.local if you don't know what you're doing, personally I prefer using vim

Add these lines before exit in the file:

# Start display driver
/home/pi/fbcp-ili9341/build/fbcp-ili9341 &
#in here also make pigpio daeomon run on startup
sudo pigpiod

Now just save and close. Thats it, now the driver should be installed and run on boot.

NOTICE: since we are using the default openbox desktop environment, the display might still be black.

To to test if its working, you can log onto your Pi using vnc, you should be able to right click to open certain apps. These actions should also be visible on the your display.

Spotify API setup

TL:DR is Create a Spotify developer account, then create an app to get a client id and client secret, afterwars you can create your redirect URI

Detailed API setup
  • got to https://developer.spotify.com/dashboard/applications/
  • log in
  • Create an app, the name and description can be whatever
  • Enter `http://localhost:8080/` as the Redirect URI
  • Select the Web API as the api to have access to
  • Agree to all the terms nd whaterver and save
  • Then go into the settings of the app to get the client ID and client secret. We will use these later

    • The steps above as pictures After loggin in you get to the dashboard. Here you want to create a new app Then you fill out all required fields as detailed above After creating the app you can now enter the settings and view the Client ID and Client Secret. These will be used later

    Raspotify Setup

    install raspotify sudo apt-get -y install curl && curl -sL https://dtcooper.github.io/raspotify/install.sh | sh

    edit the raspotify configuration to your liking (all settings listed here: https://github.com/dtcooper/raspotify/wiki/Configuration).
    The most importaint labels to fill out are LIBRESPOT_USERNAME="" and LIBRESPOT_PASSWORD="" these should be your spotify username/email and password. \ Also, comment out the line that says LIBRESPOT_DISABLE_AUDIO_CACHE=. In addition you can also set a custom directory for your credential cache with the flag Librespot_SYSTEM_CACHE= (i set mine to /var/cache/raspotify) but this shouldn't be nescesarry for it to work


    Also enable the raspotify service to cover the odd case, where it doesn't enable automatically: \

    sudo systemctl enable raspotify
    sudo systemctl restart raspotify
    


    other common values that might need changing are LIBRESPOT_FORMAT=, LIBRESPOT_SAMPLE_RATE=, LIBRESPOT_DEVICE= \ these 3 need to be configured, so that they work with your desired alsa audio output device (headphone jack for example)
    Devices can be checked by running librespot --device ? and fill out the 3 params accordingly to the output of this command

    Install python modules

    run pip install -r requirements inside of SpIpod/frontend/
    if you get an error while its installing Pillow e.g.

    The headers or library files could not be found for jpeg, a required dependency when compiling Pillow from source.
    

    or something similair like for example:

    ERROR: Failed building wheel for Pillow
    

    try installing these: sudo apt install libjpeg-dev zlib1g-dev and attempt to install the python modules from above again

    [OLD]

    1. Install Required Packages.

    Installation for python3-pip, raspotify, python3-tk, openbox

    
    sudo apt install python-setuptools python3-setuptools
    
    sudo apt install python3-pip
    
    sudo curl -sL https://dtcooper.github.io/raspotify/install.sh | sh
    
    sudo apt-get install python3-tk 
    
    sudo apt-get install redis-server
    
    sudo apt-get install openbox
    
    sudo apt install xorg
    
    sudo apt-get install lightdm
    
    sudo apt-get install x11-xserver-utils
    
    
    1. Install Dependencies
    pip3 install -r requirements.txt
    
    1. Install pi-btaudio
    git clone https://github.com/bablokb/pi-btaudio.git
    cd pi-btaudio
    sudo tools/install
    

    Clickwheel setup

    NOTICE: the pins on the clickwheel ribbon cable should face down on the breakout board
    5. Install PiGPIO for clickwheel

    wget https://github.com/joan2937/pigpio/archive/master.zip
    unzip master.zip
    cd pigpio-master
    make
    sudo make install
    

    run gcc -Wall -pthread -o click click.c -lpigpio -lrt to compole click.c, then sudo ./click & to test

    1. Setup Spotify API

    First Create an App at https://developer.spotify.com/dashboard/applications/

    https://accounts.spotify.com/authorize?client_id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1&scope=user-read-playback-state%20user-modify-playback-state%20user-read-currently-playing%20	app-remote-control%20streaming%20playlist-modify-public%20playlist-modify-private%20playlist-read-private%20playlist-read-collaborative
    
    1. raspi-config

    sudo raspi-config

    Console Autologin

    Display Option -> Screen Blanking -> Off if you want to avoid the screen turning black after a few seconds.

    1. bash_profile

    In .bash_profile added the following (if the file is not htere, you must create it)

    #!/bin/bash
    
    [[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor
    
    # Disable any form of screen saver / screen blanking / power management
    
    xset s off
    
    xset s noblank
    
    1. Configure xinitrc

    sudo nano /etc/X11/xinit/xinitrc

    Inside, make sure the following is there:

    #!/bin/sh
    
    # /etc/X11/xinit/xinitrc
    
    # global xinitrc file, used by all X sessions started by xinit (startx)
    
    # invoke global X session script
    
    #. /etc/X11/Xsession
    
    exec openbox-session #-> This is the one that launches Openbox ;)
    
    1. Run "spotifypod.py" with autostart

    sudo nano /etc/xdg/openbox/autostart

    and add the following command to launch spotifypod.py:

    cd /home/pi/fork/retro-ipod-spotify-client/frontend/
    
    sudo -H -u pi python3 spotifypod.py &
    
    sudo /home/pi/fork/retro-ipod-spotify-client/clickwheel/click &
    

    Make sure that the paths are ok with your setup!!

    in sudo nano /etc/xdg/openbox/environment all the variables needed to run spotifypod.py are set( SPOTIPY_CLIENT_ID, SPOTIPY_CLIENT_SECRET,SPOTIPY_REDIRECT_URI)

    export SPOTIPY_CLIENT_ID='your_SPOTIPY_CLIENT_ID'
    
    export SPOTIPY_CLIENT_SECRET='your_SPOTIPY_CLIENT_SECRET'
    
    export SPOTIPY_REDIRECT_URI='your_SPOTIPY_REDIRECT_URI'
    
    1. Synchronizing Spotify data! Last but not least, if you want to make sure all your playlists artists, etc are synchronized every time you turn on your Spotypod, you can simply modify the script view_model.py with the following at line 16:

    #spotify_manager.refresh_devices()

    spotify_manager.refresh_data()

    instead of calling refresh_device, you can execute refresh_data. This will sync all your data and then will eceute refresh.devices. This will make the boot up way slower! but it will synchronize every single time you switch on :). If you dont run at least once refresh_data() no playlist, artist or anything related with your account will be displayed!

    1. Configure Raspotify

    sudo nano /etc/default/raspotify

    Uncomment and fill the following line:

    OPTIONS="--username <USERNAME> --password <PASSWORD>"

    And add whichever of the following options you want:

    # The displayed device type in Spotify clients. 
    
    # Can be "unknown", "computer", "tablet", "smartphone", "speaker", "tv",
    
    # "avr" (Audio/Video Receiver), "stb" (Set-Top Box), and "audiodongle".
    
    DEVICE_TYPE="smartphone"
    

    then turn off discovery, so only devices logged into the same spotify account can interact with SpIpod (like for example managing queue)

    LIBRESPOT_DISABLE_DISCOVERY=1
    

    Wiring

    Here is the wiring of the hardware, as of revision 1. Note that the pin numbers correlate to those referenced in click.c\

    RPI Zero 2 W pinout RPI Zero 2 W Pinout Clickwheel wiring Clickwheel wiring Diagram Display wiring Display wiring Diagram

    spipod's People

    Contributors

    3urobeat avatar chickensalad303 avatar dupontgu avatar elcapitandre avatar mightea avatar mitchlui avatar rsappia avatar tomaculum avatar utkut avatar

    Stargazers

     avatar  avatar

    Watchers

     avatar

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.