Raspberry Pi Lights: how to sync Christmas lights to midi audio

This post will show you the details of my Raspberry Pi powered synchronized Christmas lights project.  I really enjoyed working on this and I wanted to share it with anyone interested in this sort of thing.

It’s fun to begin at the end, so here is a video of the Pi Lights playing to Star Wars.

Also, the Peanuts theme song:

Theory of operation:

Untitled drawing

First, a Midi file is fed into Linux’s ALSA midi sequencer service, destined to be played on a particular port.  The sequencer then broadcasts accurately timed midi events to all programs subscribed to said port.  One of those programs is Timidity, which is a free midi synthesizer that will take care of playing the sound.  The other is a simple C program that I wrote to  control the GPIO pins based on midi events.  Each GPIO pin controls a solid state relay, which ultimately toggles the main electricity  going to each bank of  lights.

Materials required:

1 Raspberry Pi and case

6 Solid State Relays (Around $6 US each on eBay)

Female to male jumpers

Cooper Wiring Devices 15-Amp White Duplex Electrical Outlet

6 Electrical outlets ( < $1 US  each)

CARLON 2-Gang Plastic Old Work Electrical Box 2-Gang Almond Standard Duplex Receptacle Plastic Wall Plate 2-Gang Light Almond Blank Nylon Wall Plate

3 Electrical boxes and cover plates  (prices vary)

 50' 14 AWG Non-Metallic Wire

50 feet of Electrical cable of appropriate gauge

IDEAL 50-Count 1/2-in Plastic Insulated Staples

A bag of electrical cable staples

Plytanium 15/32 x 4 x 8 Pine Sheathing Plywood

Enough Plywood to build a ~24″/12″/24″ box

Product Details

A small amplifier (~$20 amazon):

PYLE PLMR24 3.5-Inch 200 Watt 3-Way Weather Proof Mini Box Speaker System (White)

Outdoor speakers: (~$20 amazon)

Software needed:

Debian Rapsberry Pi distro  (http://www.raspberrypi.org/downloads)

Timidity (apt-get install timidity)

Alsa devel libraries (http://www.alsa-project.org/main/index.php/Main_Page)

Gordon’s wiringPi library (https://projects.drogon.net/raspberry-pi/wiringpi/)

About Midi Files:

Midi files are comprised of a sequence of events that richly describe how to play a song.  There are many different kinds of events, but the most interesting ones for my purposes are the NOTE ON and NOTE OFF events.

NOTE ON event {

Note value: { 0..127 }

Channel { 0..15 }

}

NOTE OFF event {

Channel { 0..15 }

}

Think of the note value part of the NOTE ON event as corresponding to key on an imaginary piano that has 128 keys.

Controlling the GPIO pins based on midi events:

I decided to control the pins based on the pitch of the notes.  There are 12 notes in an octave, so the pitch is obtained by taking modulus 12 on the note value.  From there, it’s again divided among the number of pins.  Using 6 pins, pin 0 corresponds to notes with pitch 0-2, pin 1 corresponds to 2-4, etc.

Getting Started – Software:

The first thing to do is download Timidity and make sure midi playback works properly.  After installing, configure it to run as a daemon.  Then use the ‘aconnect -o’ command to verify that it is listening on a midi port.  It should display something like this:

client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0′

client 128: ‘TiMidity’ [type=user]
0 ‘TiMidity port 0 ‘

Try playing a midi file using the ‘aplaymidi’ command.  For example, ‘aplaymidi –port 128 yourMidiFile.mid’.

It’s probably the case that the default Timidity settings will be too aggressive for the Raspberry Pi to handle.  The midi playback may stutter and crackle.  To remedy this, modify the /etc/timidity/timidity.cfg file.  Uncomment these lines and restart Timidity.

opt EFresamp=d          #disable resampling
opt EFvlpf=d            #disable VLPF
opt EFreverb=d          #disable reverb
opt EFchorus=d          #disable chorus
opt EFdelay=d           #disable delay
opt anti-alias=d        #disable sample anti-aliasing
opt EWPVSETOZ           #disable all Midi Controls
opt p32a                #default to 32 voices with auto reduction
opt s32kHz              #default sample frequency to 32kHz

Once that’s all sorted out, it’s time to get started with the pin controller program.  You’ll need to download Gordon’s wiringPi library.  Download the latest software from the his repository, and follow the easy installation instructions (https://projects.drogon.net/raspberry-pi/wiringpi/).

The ALSA libraries should be installed by default on debian.  If you are using a different distro, go to http://www.alsa-project.org/main/index.php/Main_Page and get the latest development libraries.

You can then download the source code for my program here, called light organ.  http://code.google.com/p/pi-lightorgan/source/browse/trunk/lightorgan.c.  Check out the code to your pi using this command:

svn checkout http://pi-lightorgan.googlecode.com/svn/trunk/ pi-lightorgan-read-only

Compile the program by issuing the ‘make’ command.  Feel free to edit the code to suit whatever new ideas you come up with.

At this point, you should have a binary for the pin controlling program.  Run lightorgan as root.  Open another terminal and issue the command ‘aconnect -ol’ to list all of the active midi outputs.  You should see three entries: Timidity, lightorgan and the midi thru port.  The midi thru port needs to be configured to send it’s output both to lightorgan and Timidity.  Here is an exmaple of doing that:

aconnect -ol

client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0′
client 128: ‘TiMidity’ [type=user]
0 ‘TiMidity port 0 ‘
client 129: ‘LightOrgan’ [type=user]
0 ‘listen:in       ‘

aconnect  14:0 128:0

aconnect 14:0 129:0

aconnect -ol

client 14: ‘Midi Through’ [type=kernel]
0 ‘Midi Through Port-0′
Connecting To: 128:0, 129:0
client 128: ‘TiMidity’ [type=user]
0 ‘TiMidity port 0 ‘
Connected From: 14:0
client 129: ‘LightOrgan’ [type=user]
0 ‘listen:in       ‘
Connected From: 14:0

At last, the ports are configured properly.  Now all midi traffic destined for port 14 (the through port) will be copied to ports 129 and 128 – Timidity and lightorgan.  You can use aplaymidi –port 14 midifile.mid to send to both Timidity and lightorgan.

If you’ve reached this point and everything is setup properly – you should be able to test the setup using a breadboard and some LEDs.  Here is an example with 4 LEDs:

In the file lightorgan.c, change MY_NUM_PINS to be the number of pins you plan on using.

Wire your pins to the LEDs using the chart at Gordon’s site: https://projects.drogon.net/raspberry-pi/wiringpi/pins/

Be sure to check out his tutorial on how to get started with GPIO on the Pi for more information.

Putting it all together:

I chose to build an enclosure using plywood to house the PI, the amplifier, outlets, relays, and connectors:

Photo: Construction has begun for my sound synchronized christmas light project. The photo shows six solid state relays and a half completed wooden enclosure. Also, a cat named dewey.

The junction box on the left is where the power comes in.  From there, individual runs of romex are run across to each relay, the ‘hot’ wire for each of these runs is separated by a solid state relay.  When voltage is run through the bottom terminals of a relay, the power is able to travel freely onto the outlet on the right side:

Photo: Oh what tangled webs we weave.

Shown above are 8 outlets (and also, my cat Dewey).  Two of the outlets are not connected to the relays, they are there to provide power for the Pi and the amp.  The connections on the left side are yet to be made.  Here is a view from another angle:

b

From here, the only thing left to do is complete the enclosure, add in the amp, add the Pi and wiring from the Pi.

a

This is the finished state of the box.  I probably should have cleaned it up a bit more, but I was too eager to see it in action. With everything being in an outdoor environment, I put a container of Damp-Rid in the box to try to mitigate the threat of condensation.

I hope this has been helpful.  If you have any questions, please comment.

-Chivalry Timbers

About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

81 Responses to Raspberry Pi Lights: how to sync Christmas lights to midi audio

  1. Duder says:

    Very cool, man. But the pictures in the “Putting it all together” section aren’t loading.

  2. Jon says:

    I’m having a minor problem with ports. It appears to be starting at 129, not 128. So I can have either the audio configuration or LED configuration but not both…

    One minor difference with the way I configured the alsa sound support was through an apt-get install libasound2-dev

    instead of the source version you mentioned if that is any help.

    Anyway my problem appears to be port related. I can play the .mid file but cannot get both the audio and LED gpio working at the same time.

    It _should_ be:
    aconnect -ol

    client 14: ‘Midi Through’ [type=kernel]
    0 ‘Midi Through Port-0′
    Connecting To: 128:0, 129:0
    client 128: ‘TiMidity’ [type=user]
    0 ‘TiMidity port 0 ‘
    Connected From: 14:0
    client 129: ‘LightOrgan’ [type=user]
    0 ‘listen:in ‘
    Connected From: 14:0

    but it is:
    aconnect -ol

    client 14: ‘Midi Through’ [type=kernel]
    0 ‘Midi Through Port-0′
    Connecting To: 129:0
    client 128: ‘TiMidity’ [type=user]
    0 ‘TiMidity port 0 ‘
    Connected From: 14:0
    client 129: ‘LightOrgan’ [type=user]
    0 ‘listen:in ‘
    Connected From: 14:0

    • Chivalry Timbers says:

      Timidity and lightorgan seem to grab the first port available (depending on which program was started first), starting from port 128. The lightorgan program will automatically connect itself to the midi through port (14) when it starts up, but Timidity doesn’t do that automatically. The purpose of the call to aconnect is to hook up the output of the midi through port to the input port of timidity.

      In your case, Timidity is listening on 129, so I would issue this command. ‘aconnect 14:0 129:0′. Then try ‘aplaymidi –port 14 yoursong.mid’.

  3. Carlos Luna says:

    Very nice! I must find time to make something like this!

    Now a suggestion: I feel that the lights and the music aren´t totally in sync. It feels like the LEDs are ahead in time. Maybe the effect of audio buffering – MIDI events arrive at the same time at the GPIOs and at Timidity, but Timidity will take a while to produce sound. What about delaying the LEDs a little bit?

    Again, great project!

    • Chivalry Timbers says:

      Thanks Carlos, that’s a great suggestion. It may be a bit of a challenge to properly implement a delay, since the notes coming in are sometimes simultaneous with respect to time. For example, when a chord plays, three or four NOTE ON events would be sent very quickly, one after the other from the sequencer. Putting in a sleep() just prior to using the LED’s won’t do in that case.

      One way to implement a delay would be to write a separate midi event program that could serve as the ‘man in the middle’ between the midi stream and lightorgan. This program would receive every midi event to be played, modify the timestamp to implement a delay, then send it back through the sequencer to the lightorgan program – see the examples here: http://www.alsa-project.org/alsa-doc/alsa-lib/seq.html

      • wynneth says:

        Did you ever implement a delay yourself? I’m still working on understanding C myself (if this were all in shell scripts wooo), and feel a bit overwhelmed reading the alsa link about implementing a delay. I spent a few days trying my hardest to workout other ways to make syncing full polyphonic audio easier than manually sequencing, but so far keep coming back to finding a midi that’s in line with an mp3 and using your program from the midi.

      • wynneth says:

        Nevermind my comment about a delay, I simply play the midi to lightorgan and then sleep a second or so then play the midi (or mp3) separately to the audio out. For instance, testing with the 2 Unlimited song Tribal Dance – aplaymidi –port 128:0 2tribal.mid & sleep 1.75 && mpg123 2tribal.mp3
        Works beautifully. I may experiment with re-enabling those drum tracks you have skipped in lightorgan.

      • Chivalry Timbers says:

        That’s great! Do you have a video of it in action? I’d love to see it.

      • wynneth says:

        At the moment all I have is grainy iphone footage of the LEDs on my board. (Which you can view if you’d like anyway, at http://www.youtube.com/watch?v=905wV1GzR-k ) I’ll see if I can record something decent – at the moment I have this pi connected to a solderless breadboard (using Adafruit’s pi cobbler kit) and then from there to a Sainsmart 8 channel solid state relay board. I’ve got the first 4 ac outlets wired and ready, but haven’t done anything for an enclosure or the other 4 ac outlets. In my particular case I snipped the connectors that make normal household ac outlets share one line so that I could use each socket completely independently. I’m currently haggling with my wife and the internet’s ability to provide midi’s as to what songs we would actually like to use for Christmas display… the closest we’ve come to agreement is The Bangles – Hazy Shade of Winter, LOL.

      • Chivalry Timbers says:

        Bravo! The timing is very good. I never imagined that you could use mp3 playback like that. Will I have to wait until next Christmas to see your rig in its true glory?

      • wynneth says:

        I’ll probably have some photos/video I can post in a week or two of the actual setup sans outdoor lights. I need to switch everything over to the 256MB Pi that I plan to actually use for this, and take it off the breadboarding and set it up. Since I have the Sainsmart relay board, it should fit in a smaller box than what you’ve had to use for all those individual relays. I’ll run some female-to-male jumper wires from the GPIOs to the terminal on the relay board, and switch from the cheap stranded electrical wire I was using when testing to some solid-core/romex like you’ve used.

      • wynneth says:

        I made a better video showcasing what all I’ve done – still sans a box and actual christmas lights, but it’s a much better video.

      • Chivalry Timbers says:

        This is a really cool showcase wynneth! Thanks for sharing, and great job.

  4. Bob H says:

    I am impressed that the GPIO pins had enough power to drive the solid state relay without extra buffering.

  5. Malenky says:

    I think you went a little overboard with the 120v wiring. Maybe a single positive wire to the first relay then jumped to the rest, and a single negative and ground wire coming off the outlets. From the photos it looks like all 7 ground wires are individually hooked up and going back to the junction box.

    Don’t get me wrong, it’s a cool project but cooper wire is expensive nowadays.

    • Chivalry Timbers says:

      It’s true that it could have been done with less wire – Only the hot wire really needs to go through the relays. I actually did daisy chain the ground wire on the outlets – the grounds aren’t actually connected the whole way through on the relay connections. For me, it was just more convenient to use the full size romex. They are safe and easy to secure using wire staples.

  6. Al says:

    Great Job. thanks for the tutorial.

  7. Mike Kopack says:

    Nice! Wish I had the time over the next 2 weeks to build this! (trying to get the house painted before the folks arrive for Xmas though…)

    Question – You say the left box is where the power comes in, but you didn’t say how you get the power in. Is it on a single wire to a AC outlet plug and then split to the various runs?? I’m a little fuzzy on what you did there…

    • Chivalry Timbers says:

      Like you said – the power coming in is from a single wire that is split to the various runs. Good luck with painting your house! That can be a far greater challenge…

  8. Jason Green says:

    Thanks for the detailed instructions. Triggering the pins by pitch class is an interesting choice. Allen Forte would be proud. :) With at least six pins, each pitch class should create a unique light combination ( c= 1 and 6, c#= 1, d= 1 and 2, etc.) and the lights provide a pitch class inventory of the music. You might get a result that parsed more easily for a non-set-theorist if you tied particular pins to particular MIDI channels (and therefore instruments).

  9. Pingback: Christmas music and lights, synched with a Pi | Massif Software

  10. Greg says:

    Very cool. I’m wondering if the size of the relays is overkill though. I’ working on something similar, but using this relay module.

    http://www.ebay.ca/itm/270984095956?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

    • Chivalry Timbers says:

      Yes, you can use mechanical relays as a cheaper alternative.

      • Richard Ash says:

        Mechanical relays will need some slightly more complex electronics (basically a buffer) coming off the Pi because they draw a lot more current on the coil side. The module shown has optocouplers on it (good for mains isolation) but is rather vague what is needed to drive them – so the Pi GPIO may be up to the job, or may not (if they are expecting 5V drive, which the PI isn’t). If not, you need a(nother) driver between the Pi and the relay board!

  11. bryan says:

    Awsome project!!! Tis the season for pi…

  12. Patrick says:

    In the past I’ve connected similar Solid State Relays to a Linux box via the Parallel Cable, and am now connecting them to my Pi via the GPIO.
    I’m a little concerned that you have the AC connection (hot) on the relays exposed like that. I’ve always put the relays in junction boxes, the same way you would put an outlet in one. Would hate for you to reach your hand in there and get a jolt, or worse, that your Pi bumps into one of the hot terminals and is fried ;-)
    I have zip tied the Relay to the bottom of an extra deep junction box, and ran the DC voltage in one side, and the AC to the other. That kept everything separate.

    • Chivalry Timbers says:

      I too was concerned about the AC connection being exposed – That’s why I wrapped the top half of the relays several times with electrical tape. It definitely would be safer inside an electrical box though!

      • Joe Blow says:

        Technically, using wood for an enclosure (especially untreated – not sealed with urethane, epoxy, or other waterproof coating), particularly one that is apparently exposed to outdoor humidity (if not precipitation) is a big no-no, National Electric Code-wise. The project box really should be some sort of UL-listed plastic or metal box (e.g., Square-D, etc.), particularly something with appropriate internal mechanical mounting hardware (brackets, stand-offs, tabs, etc.).

        While you took pretty good care to keep things neat and clean, not everyone has the knowledge and skills to do so, and all you need is one marginal, high-resistance connection that generates too much heat and, poof, you have not just a fire hazard, but an electrical fire hazard. I would also include a breaker/fuse in-line with the supply current just in case something goes horribly wrong (e.g., any kind of component internal short-circuit or runaway thermal event – stuff happens and always in the worst possible way, in accordance with Murphy’s Law and many Corollaries).

        Otherwise, a very nice project and an inspiration for other high-tech Clark Griswold’s everywhere! :D

  13. Paul says:

    I love the system, but hate the wiring.

    Doesn’t comply with UK wiring practice at all. The mains and ELV must be kept separate, so the relays and socket wiring should be in one part of the enclosure (with appropriate ingress protection) and the ELV out where humans can get at it. And run the whole assembly from an RCD.

    Ideally keep the box indoors and run external cables to outside. Because it is external wiring it must be run on an RCD.

    As others have commented: I would have run a common neutral wire and individual phase to each socket. Note that if you sleeve the wires you can “misuse” the wires, so blue can carry phase if you want to, but it must be sleeved.

  14. Pingback: MAKE | Raspberry Pi Christmas Light Controller

  15. Pingback: Raspberry Pi Christmas Light Controller

  16. solid state relay is very expansie!
    You can buy on ebay an arduino relay borad (it can work whit gpio of raspberry) for 7 € whit 8 relay!
    you just have to be careful with the pinout

    see my project

    https://www.facebook.com/CatSpberry

  17. solid state relay is very expansive!

    You can buy ,on ebay, an “arduino relay board” for 7 € whit 8 relay or 4€ whit 4 relay!
    you just have to be careful with the pin-out
    see my project

    https://www.facebook.com/CatSpberry

  18. Jon says:

    Thanks for this guide and your help with port settings. I built mine today with a sainsmart 8 channel solid state relay board that was meant for anrduino. Works great has built in LEDs and was only about 25 bucks. Thanks again!

    • Chivalry Timbers says:

      Great! I will have to check out the sainsmart board – that sounds like a good way to go.

      • jon says:

        What I thought was cool about this setup – the 5v side and LEDs on the board can be powered by the pi… all through a simple 10 wire cable. This way the basic interface functions can be checked before AC applied. Just be sure to gang the logic side grounds together at the relay board…. there are two screw terminals.

        I also used a wireless USB dongle so I can control my pi light controller from anywhere in my WPA secured wireless network.

      • Chivalry Timbers says:

        Thanks for posting the link to the solid state relay board. If you plan on using all 8 channels with lightorgan, you may want to consider binding one of the relays to the ‘drums’ instrument. The drums instrument always has a channel value of index 9. I suggest this because lightorgan switches based on pitch – for songs that stay in one key, there are usually only seven unique pitches for a given song. I think you could get a really full effect using 7 channels for regular notes and one channel for notes that come in with channel index 9.

  19. Richard says:

    Great blog about your lights, would it be possible to add on a PIR to start the display ? and a play list of five midi files. Thanks.

    • Chivalry Timbers says:

      With this setup, the display and music runs passively in the background. All that is needed to start a song is for you to start sending midi data on the right port (aplaymidi command).

      Therefore, I think that it would be easy to add a PIR by adding a third program to monitor input from the PIR. It could go something like this:


      while true:
      if PIR was activated:
      Play to completion one or more songs from a playlist using system call to aplaymidi

  20. Matt Lam says:

    Do you have a schematic for the wiring?

  21. Alex says:

    So….. Let’s talk about something like wav or mp3s, surely the pi isn’t doomed to hell to never play anything better than a midi, is it?

    • Chivalry Timbers says:

      Alex, we can very well play other sound formats including very high definition audio on the Pi. It’s a very capable computer that has no problem with even 1080p video playback See RaspMC. The problem with using a wav or mp3 for something like this is that it’s very difficult to devise a method for automatically synchronizing lights to the audio signal. It usually requires a human to manually arrange the light on light off sequence for each song.

      • Alex says:

        Interesting. I’m a developer myself however sound is the one knowledge that’d beyond me.

        Soo… Anyway, perhaps the best, easiest and hackish way would be to convert a mp3 to a midi and manually sync the files?

        Unless anyone has any better ideas. Like I said, my knowledge of sound is minimal.

  22. Pingback: Hardware woes | NiGhTHawK

  23. Pingback: แสงสีด้วย Raspberry Pi | Raspberry Pi Thailand

  24. Pingback: Christmas music and lights, synched with a Pi #piday #raspberrypi @Raspberry_Pi « adafruit industries blog

  25. Jello says:

    Can you Upload a Image/Backup from your Raspberry?

  26. Pingback: The tech gift guide for the last-minute shopper – Computing Technology

  27. Pingback: Raspberry Pi Lights: how to sync Christmas lights to audio « Frustrated IT Engineer

  28. Pingback: The tech gift guide: E-readers for bookworms and tablets for multimedia mavens | AhipCup

  29. Kevin says:

    Really fun project!
    I’ve set it all up on my Pi and have it flashing LEDs right now to find midi files that look good. (try http://bennieshepherd.com/joannsmidi/DisneyElectricLightParade.mid) looks pretty cool!

    Anyhow. being a novice at C. I wanted to ask, How would you go about assigning one gpio (say the gpio9 pin on the extention connector) to just trigger on the channel 9 “drums” instrument? Could this be added as a subroutine to lightorgan.c?

    I hope this makes sense!

    • Chivalry Timbers says:

      Hi Kevin. This is off the cuff and untested so be weary, but here is how you could bind the drums channel to a pin:

      In lightorgan.c, see the if block that looks like this:


      if( isPlayChannel(ev->data.note.channel) ) {
      .....
      }

      Insert a new else if block immediately after that.


      //If this is the drums instrument..
      else if(ev->data.note.channel == 9) {
      //Check if this is on or off event
      int isOn = 1;

      //Note velocity == 0 means the same thing as a NOTEOFF type event
      if( ev->data.note.velocity == 0 || ev->type == SND_SEQ_EVENT_NOTEOFF) {
      isOn = 0;
      }

      //Write to the drums pin
      digitalWrite( YOUR_DRUMS_CHANNEL_PIN_IDX, isOn);
      }

      Hope that helps! Post a video of your lights please if you can, I’d love to see it!

  30. Barnaby Kent says:

    Hi,
    Great post and great idea. I am just working through it now. One thing that I came across was when trying to make the LightOrgan I got:

    alsa/asoundlib.h: No such file or directory

    I found a similar problem on the web and running the following command:

    sudo apt-get install libasound2-dev

    Seemed to fix this

    I was running on one of the latest Wheezy images from Raspberry Pi trying to get my http://www.pi-cars.com to dance along to Gangnam Syle….

  31. ohssfalcons says:

    We were looking for something exactly like this. Thank you so much for posting!

  32. Adam Ickes says:

    Thanks for this. It helped me out a lot. I don’t have my box built yet, but I’ve got it setup in test mode. I used an eight channel relay board with relay # 8 linked to the drum channel and the other 7 processing with your lightorgan code. Here’s a test run: http://www.youtube.com/watch?v=wJjrIah5uQE&feature=youtu.be

  33. This looks like a great way to make use of a relay board I have lying around. I’ve been looking for a way to create a raspberry pi driven light show for a bit now. When I try to compile I get the following error.

    /tmp/cc2Qjq1n.o: In function `midi_open’:
    lightorgan.c:(.text+0×18): undefined reference to `snd_seq_open’
    lightorgan.c:(.text+0x2c): undefined reference to `snd_seq_set_client_name’
    lightorgan.c:(.text+0×48): undefined reference to `snd_seq_create_simple_port’
    lightorgan.c:(.text+0×78): undefined reference to `snd_seq_connect_from’
    /tmp/cc2Qjq1n.o: In function `midi_read’:
    lightorgan.c:(.text+0xdc): undefined reference to `snd_seq_event_input’
    /tmp/cc2Qjq1n.o: In function `pinsOn’:
    lightorgan.c:(.text+0x1f4): undefined reference to `digitalWrite’
    /tmp/cc2Qjq1n.o: In function `pinsOff’:
    lightorgan.c:(.text+0×244): undefined reference to `digitalWrite’
    /tmp/cc2Qjq1n.o: In function `midi_process’:
    lightorgan.c:(.text+0×648): undefined reference to `snd_seq_free_event’
    lightorgan.c:(.text+0×674): undefined reference to `digitalWrite’
    /tmp/cc2Qjq1n.o: In function `main’:
    lightorgan.c:(.text+0x6a8): undefined reference to `wiringPiSetup’
    lightorgan.c:(.text+0×720): undefined reference to `pinMode’
    collect2: ld returned 1 exit status
    make: *** [lightorgan] Error 1

    I’ve already installed all the libraries mentioned above but it seems like gcc isn’t linking to them.

    • Chivalry Timbers says:

      From the error messages, it looks like the libraries for alsa and wiringPi aren’t properly linked. Are you using the Makefile to compile the program? I would expect to see some errors from gcc saying that “asound” and “wiringPi” not found (due to the -lasound and -lwiringPi). Also, what distro are you using?

      • Anonymous says:

        I am running Raspian, I used the included makefile to compile the program but kept getting those errors. I was actually able to sucessfully compile it by directly using gcc and omitting the -Wl, -g, and -Wall arguments. The program seems to be working perfectly.

      • Forgot to log in when posting that.

    • Adam Ickes says:

      If you’re using gcc to compile the code, make sure you include arguments “-lasound” and “-lwiringPi”. The libraries are installed but you need to tell gcc to use them. For example: “gcc -o lightorgan lightorgan.c -lasound -lwiringPi” I ran into the same issue the first time i tried to compile.

  34. wynneth says:

    I made a box! Not as clean as yours, but notably cheaper… Before the electricians and fire chiefs comment – mine is going indoors, the power strip has a built in breaker and will be run via its own circuit and breaker at home as well, and I’m probably going to mount the relay board on the side later with stand-offs instead of just sitting it on the raspberry pi(which is in an acrylic case from adafruit).

    http://i908.photobucket.com/albums/ac286/wynn3th/73F5D69D-7F17-48DC-85DC-0FEA7BA3FEC4-13898-00000397B05D9905.jpg

    http://i908.photobucket.com/albums/ac286/wynn3th/81E8E1B1-5997-4C7C-BFA1-629BE98CCF1D-13898-00000397B2559AD5.jpg

    http://i908.photobucket.com/albums/ac286/wynn3th/E20C7A97-4248-4830-A3CF-ECC6DB4BC60B-13898-00000397B483B875.jpg

  35. Anurag says:

    I am running ubuntu on my PC and cud not find Debian Rapsberry Pi distro (http://www.raspberrypi.org/downloads) for ubuntu…is there any other way to run the above application…i have completed all steps suggested, midi file is running fine on my system…also i have FreeRTOS running fine on PI and i was able to do small application like blinking LEDs on it…

  36. Anurag says:

    Hi,
    I am able to generate the executable after compiling the lightorgan code, but the command aconnect -ol give only two entries, midi thru and timidity….can u please help me fix it…:)

    • alseadon says:

      try
      aconnect 14:0 129:0
      worked for me

      • Anurag says:

        it gives error as “connection failed(invalid argument)” :(
        I m in blank state where nothing is working and i don know how to move forward…

      • Chivalry Timbers says:

        Also, are you running lightorgan as root?

      • alseadon says:

        do you have lightorgan running?

      • Anurag says:

        ya lightorgan is running fine and i am able to generate the executable… but please be noted that I am running ubuntu on my PC and cud not find Debian Rapsberry Pi distro (http://www.raspberrypi.org/downloads) for ubuntu…is there any other way to run the above application…i have completed all steps suggested, midi file is running fine on my system…also i have FreeRTOS running fine on PI and i was able to do small application like blinking LEDs on it…

      • Chivalry Timbers says:

        I bet that some error is happening in lightorgan. Try commenting out the lines in lightorgan.c that make it start as a daemon, see below:

        /*
        //Start as a daemon
        if( daemon(0,0) != 0) {
        exit(1);
        }
        */

        After you do that, recompile. Do any error messages appear when you run lightorgan then?

      • Anurag says:

        when I commented the below line :
        /*
        //Start as a daemon
        if( daemon(0,0) != 0) {
        exit(1);
        }
        */

        i got the error as
        root@anurag-Dell-System-XPS-L502X:/home/anurag/PES_RASPI/project# ./lightorgan
        piBoardRev: Unable to determine board revision from /proc/cpuinfo
        -> No “Revision” line

        Also when I checked the link for solution :
        http://www.raspberrypi.org/phpBB3/viewtopic.php?p=184410#p184410

        it was mentioned as
        You can correct this with
        program_board_rev=2
        in config.txt and boot once

        but where to correct it , when i checked the config.txt file of the board in given SD card, i cud find only below lines:
        arm_freq=800
        force_turbo=1
        gpu_mem=128
        disable_overscan=1
        start_file=start_x.elf
        fixup_file=fixup_x.dat

        how to make program find the board revision/or how to correct the board revision.

        Thanks in advance for your help !!
        Regards
        Anurag

      • Chivalry Timbers says:

        It looks like you have a PI that was never “burned in” with the revision value. Which board revision is your actual raspberry Pi? It should be etched in somewhere on the pi itself.

        What I would do is find out what your board revision truly is, and then set it in the /boot/config.txt file. According to the spec, it’s a one time config. Put the line

        program_board_rev=(your revision number here)

        into config.txt, then boot, then it will **forever** be known as that revision number in software.

      • Anurag says:

        Hi there,

        I figured out the board revision info, there was some issue with the Debian Rapsberry Pi distro.

        pi@raspberrypi ~/pi-lightorgan-read-only $ cat /proc/cpuinfo
        Processor : ARMv6-compatible processor rev 7 (v6l)
        BogoMIPS : 464.48
        Features : swp half thumb fastmult vfp edsp java tls
        CPU implementer : 0×41
        CPU architecture: 7
        CPU variant : 0×0
        CPU part : 0xb76
        CPU revision : 7

        Hardware : BCM2708
        Revision : 0003
        Serial : 00000000f483bfc0

        but when now try to compile the code i am getting the error as

        pi@raspberrypi ~/pi-lightorgan-read-only $ make
        gcc lightorgan.c -lasound -lwiringPi -g -Wall -o lightorgan
        lightorgan.c:1:28: fatal error: alsa/asoundlib.h: No such file or directory
        compilation terminated.

        but alsa is already available and i cud see in the usr/sbin…..

        when i tried downloading the alsa lib from the above link, m not able to download on the board..
        Is there something that i am missing…

        Regards
        Anurag

  37. alseadon says:

    I got this all up and running using an 8 relay board but I’m having a problem with distortion in the sound even after following the steps above to disable some timidity features. Is anyone else having this issue and/or have a fix?

    I also set up my relays so while I’m using 8 gpio’s I have 16 sets of lights. 1 set for each of the 8 on and off states.

  38. wynneth says:

    I made a simple initscript, to start lightorgan as the pi boots:

    http://pastebin.com/ThX9UvAB

    …assuming the lightorgan executable has been placed in /usr/share/lightorgan/ of course.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s