Skip to content

Playing around with led strips / raspberry / mopidy / lightshowpi / spotify

Notifications You must be signed in to change notification settings

prise6/hf-with-leds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Have Fun With Led Strip !

What can we do with 4 meters of LEDs (32 leds/m) and raspberry pi ?

My steps:

1- Connect and control leds with raspberry -> Done

2- Leds will react according to music playing on raspberry -> Done

3- Raspberry will also output the music -> Done

4- The music will come from Spotify stream -> Done

5- What about a spectrum analyzer ?

I'm a real newbie in this field, here is my first approach. Feel free to comment/create issue!

This README is a draft

Results (for now)

Images:

Lights tower

Circuit

Videos:

Small video

Which existing tools can help me ?

  • WS2801 RGB LED : leds strip
  • Raspberry pi 3
  • Mopidy : music server, Spotify enabled
  • BiblioPixel : Python library for programming light animation
  • Lightshowpi : a wonderful code to make your light dance to music with raspberry
  • Raspbian : debian distribution for raspberry pi

What i needed

  • WS2801 RGB LED : there
  • Some wires
  • Solderless breadboard
  • Breadboard Power supply module
  • Power supply 5V

Assumption

  • Raspbian is installed
  • Direct / remote access to raspberry

Music server

Mopidy is very easy to install. See documentation on website. I also installed the mopidy-spotify. Mopidy is running as a service and launch a webserver on 192.168.XX.XX where iris is installed.

My conf file is in mopidy/mopidy.conf. Notice Alsa chunk.

I also updates the service file because the service wasn't waiting for internet :

do_start()
{
    if [ ! -d /var/cache/mopidy ]; then
        mkdir -p /var/cache/mopidy
        chown mopidy:audio /var/cache/mopidy
    fi

    ## my modification ...
    sleep 30

    start-stop-daemon --start --quiet --name $NAME --pidfile $PIDFILE \
        --startas $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --name $NAME --pidfile $PIDFILE \
        --chuid $DAEMON_USER:$DAEMON_GROUP --background --make-pidfile \
        --startas $DAEMON -- --quiet --config $CONFIG_FILES \
        || return 2
}

Lightshowpi

Lightshow is really amazing. You can easily, without deep knowledges, create something nice with music and lights. To install lighshowpi use official bitbucket repo.

My goal was to use the audio-in method : the output of mopidy must be the input of lightshowpi AND raspberry outputs the sound.

In order to make this work, you need to create a loopback device with ALSA (next section).

Lightshowpi is writtent in python, i updates the py/synchronized_lights.py for my purposes :

  • make lightshowpi a service :

add shebang

#!/usr/bin/env python

need to initialize variables:

os.environ["SYNCHRONIZED_LIGHTS_HOME"] = "/home/pi/lightshowpi"
HOME_DIR = os.getenv("SYNCHRONIZED_LIGHTS_HOME")

create a file init.d/lightshowpi added to systemctl.

  • handle an error from audioop

Happens when lighshowpi is "recording" and music is played after

try:
    audio_max = audioop.max(data, 2)
except audioop.error:
    audio_max = 0
    continue

ALSA

Why Alsa ? Always liked it, no more reason.

OK, the issue was to make recordable the sound coming from alsa card. I found on the web two solutions:

First of all, you need to enable the aloop module : modprobe snd-aloop and make it available on start.

See alsa/asound.conf.card. This solution turns out to work with usb card, but not with raspberry alsa card. (dmix seems not to work there)

See alsa/asound.conf This solution works with raspberry alsa card.

It creates a virtual recording card called looprec.

My Own Question:

  • It seems that i needed to mix the sound (rate, buffer size, ...) of looprec. Is it necessary ?
  • Volume control acts on the volume lightshowpi receive in the second solution ?

Wires

Documentation found here

My Own Question:

  • For some reason i was not able to start my raspberry with 5V. So i supply the raspberry with 3.3V (micro usb), and the led strip with 5V. Do i still need to connect the raspberry ground pin to the ground of breaboard ?

Bibliopixel

TODO

Random docs

https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html https://raspberrypi.stackexchange.com/questions/57787/using-the-alsa-dmix-plugin-on-raspbian-jessie/61974 https://www.raspberrypi.org/forums/viewtopic.php?t=64936&p=481557 https://bbs.archlinux.org/viewtopic.php?id=147852 https://alsa.opensrc.org/Dsnoop

https://docs.python.org/2/library/audioop.html

About

Playing around with led strips / raspberry / mopidy / lightshowpi / spotify

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published