Laminar Pi + Airplay

Now that I got the Raspberry Pi 3, I could rework the tech and figure out the Airplay feature to get this fountain working!

Here are the steps I used to set up my Raspi (SD card),  install Lightshow Pi, and shairport-sync (airplay feature) on top of it:

I’d never reformatted an SD card before, so this was quite the experience.

The first step was to find a guide, and this website was very helpful.

I slipped the microSD card into my microSD card reader and plugged it into my computer, which recognized the device. (yay!)

I had to find what my computer named the usb microSD though, so in root permissions, I ran fdisk -l, which gave me this: fdisk.png

I knew my microSD was 16GB, so the second to last option, /dev/sdb, was the right one.
Next I needed to actually access it, so I did that with fdisk /dev/sdb. That command has to be run with root permission, or sudo.

You need to delete any existing partitions on the device if there were any before doing anything else. You can do that using d, which will automatically delete the default partition.

To list all the partitions you have, you can use p, which is useful to check what you’ve deleted.

After deleting the partitions, n will create the new partition we need! You can give it a number (1-4) based on your preference (if you have a favorite number or something).

newp

Using p after creating the partition shows me the new partition at the very bottom. But uh oh, I need a FAT32 type, instead of a Linux type of partition.

To change that, you use the t command. If you request so, you can list all the different types of partitions there are to choose.

fat32

The tutorial I used recommended W95 FAT32 (all on its own, no LBA), so I executed b, which reformatted it. Yay!

At the end of all that, you use w to write all the progress and finish the dealio.
The first time I did all that, I got an error in the terminal, but after some fiddling with the commands it gave me the right thing.

Next, I needed to install Raspbian, the Raspberry Pi OS. I downloaded the full version of Raspbian Jessie Desktop from the Raspberry Pi website and unzipped it.

Next thing I did was run df -h, which helped me see the device name of my SD card (it was still /dev/sdb).

Then I unmounted the SD card (so files can’t be read or written in the process of downloading an image) with umount /dev/sdb. If you still have multiple partitions, you should unmount all of them.

Next, use the terminal to copy the image to the SD card!

dd bs=1M if=/home/thallia/Desktop/2017-05-17-raspbian-jessie.img of=/dev/sdb

This command must be prefixed by sudo if you are not logged in as root. dd starts the copying, bs=1M tells the copyer what rate the memory should be transferred at.

The if= statement is where you put the path for where the image can be found. For me, it was on my desktop. The of= statement is the path of your SD card. It takes a few minutes for the process to complete, so getting up and stretching for a few minutes is a good thing to do while you wait for it to finish.

After that, your SD card should be ready to plug into your Raspberry Pi to boot!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Installing LightshowPi

Because I covered most of this in another post, I’ll keep it short so we can get to shairport-sync.

Boot into your Raspberry Pi, open a terminal, and run sudo apt-get update and sudo apt-get upgrade. These shouldn’t take too long.

After that, if you don’t have git, install it with sudo apt-get install git-core.

Next, clone the LightshowPi repository to your home directory.
git clone https://togiles@bitbucket.org/togiles/lightshowpi.git

If you have a Raspberry Pi 3 (like me) or a Pi Zero, there’s a different repository you have to clone because of some kernel issues. Here’s the instruction:
git clone https://broken2048@bitbucket.org/broken2048/lightshowpi-fork1.git

If you don’t have a Pi 3 or Zero, then don’t worry about that.

You’ll want to make sure that you have the right branch, otherwise the program won’t work as well. You can do that with cd lightshowpi, then git fetch && git checkout stable.

You should get a confirming message that you’ve been moved to the “stable” branch.

Finally, you can install the software! sudo ./install.sh will set you up with the goods. This process may take anywhere from 10 minutes to 3hrs, so be patient. After that, reboot your Pi with sudo reboot.

On the LightshowPi website, you can find links for how to set up and test your hardware, or you can check out my first setup here: LightShow Pi ~ Early Tech Behind the Laminar Fountain.
If you have any questions about my setup or how I got the music to work, feel free to contact me.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Alrighty, now to the exciting stuff! I discovered shairport-sync through the LightshowPi Google+ Community, which is a very helpful place if you run into trouble setting up any of this stuff.

Here you can find the GitHub repository for shairport-sync and follow the instructions to set it up. I’ll walk you through what I did to set mine up.

First, you have to make sure you install all of the files and packages needed for it to work. This includes (for my setup):

sudo apt-get install build-essential git xmltoman
sudo apt-get install autoconf automake libtool libdaemon-dev libpopt-dev libconfig-dev
sudo apt-get install libasound2-dev
sudo apt-get install avahi-daemon libavahi-client-dev
sudo apt-get install libssl-dev

Next, you need to clone the repository to your Pi, using:
git clone https://github.com/mikebrady/shairport-sync.git

Now, cd into shairport-sync and run autoconf -i -f. This step may take a little time.

This next part was a little tricky for me to understand what was going on. We’re writing the configuration file with the stuff we want so shairport will work the right way. Because I’m only using shairport-sync for a simple technology, I didn’t have to use many configurations.

./configure --sysconfdir=/etc --with-alsa --with-avahi --with-ssl=openssl --with-systemd --with-stdout

./configure is the filename, I believe, while --sysconfdir=/etc is where the file will be within the shairport directory.
--with-alsa [includes the ALSA backend module to audio to be output through the Advanced Linux Sound Architecture (ALSA) system directly. This is recommended for highest quality.] (taken from the github description)
--with-avahi [Avahi is a widely-used system-wide zero-configuration networking (zeroconf) service — it may already be in your system.]
--with-ssl=openssl [for encryption and related utilities using either OpenSSL, mbed TLS or PolarSSL.]
--with-systemd this command has to do with the particular system you have. You can use man init to find out whether you need to use systemd or systemv.
--with-stdout [include an optional backend module to enable raw audio to be output through standard output (stdout).]

After executing that command, you can run make. When make is finished, install shairport-sync with sudo make install. This can take a little time as well, so get up and stretch!

Now comes some more fun. We’re going to edit some more configuration files, first from the shairport-sync repository. Make sure you cd into shairport-sync so you can access them.

First, we’re going to run sudo nano /etc/shairport-sync.conf. There will be a lot of text. Do not freak out like I did and immediately close the document.

As long as you can find the general function at the top and the alsa function in the middle of the file, you should be fine. In the general function, you’ll see a list of commented out functions. You can give your Airplay feature a password if you don’t want anyone out of the blue using it, but I didn’t set that up.

At the top of the file, there’s a line that looks like: # name "%H"
You’ll want to erase the hash, and fill in the quotation marks what name you want to appear on the Airplay menu. I named mine “Laminar Pi”, for the fountain purposes.

Now go down to the alsa function, and find the line in the file that reads # output device: "hw:"

In this line, you can choose whether you want the output sound to be HDMI, or headphones. I made mine headphones, because I have a 3.5mm jack connected from the Pi to a portable bluetooth speaker. It makes for easy sound testing. Remember to delete the hash so it’s used in the setup.
That’s all I modified in the shairport-sync config file, but if you find yourself in a more complicated situation, the github instructions have plenty of information and examples for you to figure it out.

To save the config file, Ctrl-x will do the job, y to agree to save the file, and enter to seal the deal.

Working with the pi, there’s a special thing you can add to the Raspberry Pi boot file to make the sound clearer. To get to that, enter sudo nano /boot/config.txt.

At the very bottom of that file, add the line: audio_pwn_mode=2

Ctrl-x will save and get you outta there, and that section of shairport-sync is finished! Only a few more steps left to go.

Now, cd into your lightshowpi directory, then into the config directory. The path looks like this: cd lightshowpi/config
Next, run sudo nano defaults.cfg

This is the configuration file for LightshowPi, where we can alter how things will outpstrut and work together.
If you scroll down past the information about the GPIO pins, shortly after you’ll come to a section about playlist modes. You can skip a little farther down to the stream-in section.

There’s a line that looks like this: # mode = stream-in
You’ll want to uncomment that (delete the hash). Go down a few lines to:
stream_command_string = sudo mpg123 --stdout http://193.34.51.115:80 And put a hash in front of it to comment it out. Then go down a few more lines to:
# stream_command_string = shairport-sync -v -o stdout
And uncomment (delete the hash) to activate shairport-sync.

Use Ctrl-x to save the file and exit nano, and you should be ready to start up the hardware!
Assuming you’ve set up and tested your hardware, cd .. out of the config directory, but stay in the LightshowPi directory.

To start the software and give off the Airplay signal, run:
sudo python py/synchronized_lights.py

Hook your phone up to the Pi Airplay signal, and your lights should start up to whatever sound you play through your phone!
Please contact me if you have any questions.

Cheers!

{thallia}

Building the Fountain

And so it begins….

I met up with my friend this afternoon to start working on the fountain, boy what a project! We found things that we didn’t want to do when making another fountain, things we wanted to keep, and had a good time building a thing.

We loosely followed this Instructables to build the fountain. Here’s our materials:

img_4674.jpg
* A 4in diameter 2ft PVC pipe
* A 4in pipe cap
* 4, 4in test plugs
* 1in diameter 1ft PVC pipe
* Window mesh
* 3/8in x 4in brass pipe
* Water sealant epoxy glue stuff
* Steel wool (or scrubbing pads)
* 400+ straws (not pictured)

In all, this came out to be $32.67 at Home Depot. But a lot of this I bought extra (like the 2ft PVC pipe, so we have one pre-cut for our next fountain), and the steel wool….and the tons of window mesh. I’m going to have to find a project that incorporates a lot of that, because we have waaayyy too much left over. Heh.

The first thing we did was saw the 2ft piece of black PVC into 1ft pieces, as the fountain body is only a foot long. Next, we needed to get the nozzle ready, which was the 3/8in brass pipe.

We tapered out the end of the brass nozzle with sand paper so the water flow would come out smooth and easy, and drilled a 3/8in hole in our pipe cap for the nozzle to fit.

For some reason our 3/8in pipe was not actually 3/8 of an inch (not sure why), so we improvised and got the hole big enough for the nozzle to fit. We cut off the nozzle about 1/2in below the ridges and sanded that down.

Then we glued the nozzle in with superglue:

img_4752

Viola! Very pretty. 🙂

img_4751

Our next step required the 1in PVC, which is where the hose would fit into. I sawed it into a 3in piece, then we drilled an off-center hole in the big PVC to stick the smaller one into. It was an odd way to do something, when we really could’ve made the hose attachment on the backside of the fountain. We both decided that’s what we’d do next time, along with purchasing a female hose connector instead of just using a PVC pipe.
Finally, we glued the tiny PVC into the big one with some water sealant epoxy glue:


In the next step, I took the 4in test plugs and, with a super sharp razor blade, I cut out the insides. My arm is sore, I must say. After cutting out the inside, I also had to cut off the lip of the test plug. What was left is this white circle:

img_4753

With this, I fit some window mesh at the bottom of the fountain, right above the hose entrance: img_4755

After that was done, we got to an easy part of the job. STRAWS!

img_4754

We sent my friend’s brother and his girlfriend on an emergency run to the dollar store to get us 600 bendy straws. It was lovely. We chopped the straws about 1/2in below the bendy part (since they were a bit too tall), and stuffed them into the PVC pipe on top of the window mesh. img_4764

Not all of them were level, but it worked. I unfolded two chunks of steel wool and layered them on top of each other, then cut them in a circle to fit on top of the straws.

We had to use the window mesh, steel wool, and straws to help regulate the water pressure that would be coming through the hose. Using those, it filters the water flow and makes it stream in certain shapes and mostly in one direction, which helps give you the smooth and transparent flow of a laminar fountain.

This is what it all looked like from the top, with the steel wool and another sheet of window mesh:img_4765

(not horribly exciting yet, I know. Just wait!)

Finally, we could start assembling it all together! We stuck the pipe cap on one end (with the nozzle) and on the other, we duct taped a test plug on the end. We didn’t want to seal it all the way up yet in case there needed to be any changes to the initial structure.

We turned the water on and hoped for the best….Ahh! It was a great first try at the water flow. We were so excited.

img_4759.jpgimg_4760.jpgimg_4761.jpg

The water flow was a little shaky and not completely clear, and the pressure wasn’t as strong (because we hadn’t sealed the bottom of the fountain), but it WORKED! WOOHOO! Check it out:​


To troubleshoot, we took apart the fountain again and tapered the bottom of the nozzle inside the fountain. We think it’s too long, so we gotta figure out a way to chop it down a few quarter inches. We tried some other things, but it obstructed the water flow more than we’d have liked, so it’s back to the drawing board on that part. But we made great progress, and I’m proud of us both for getting this project done.

I got the new Raspberry Pi 3 as well, so I can start working on reinstalling and trying all the software I’ve done in my previous posts to get the tech ready for installation. We’ve got wiring and soldering in our path…

Cheers!

{thallia}

 

The RGB LEDs are IN

The second to last step of getting the tech for my laminar fountain is complete!

I ordered a pack of 100 RGB LEDs, super bright (not to mention cheap), from Amazon, and they came yesterday. Very good quality materials. I tore apart my old wiring setup and got these new LEDs ready for action.

I stuck four of ’em into a breadboard and then calculated the resistance for each color using the voltage drop information from the sticker on the bag. The red LED had a drop of 2.0-2.2V, and the green/blue LEDs had a drop of 3.0-3.2V.

With this info, you can calculate the strength of resistor that you need. You take the input voltage of your device (in my case, 5V) and subtract the voltage drop from the initial voltage. 5V – 2.2V = 2.8V. Now I take the kind of current that runs through them, 20mA, and divide 2.8V by 20mA (or 0.02A), which results in 140 Ohms. I didn’t have a 140 Ohm Resistor, but I did have a 150 Ohm, so I used that from my handy resistor pack I got from amazon for $8.

Doing the same calculations with the Green/Blue LEDs, I got 90 Ohms, which I used 100 Ohm resistors for.

With all the resistors hooked up and the jumper wires attached, this is what my setup looked like:

It’s basically a jungle of wires.

Here’s the GPIO pins I hooked each one up to:

(RGB 1 – upper right) red=pin0, green=pin2, blue=pin 4
(RGB 2 – lower left) red=pin1, green=pin3, blue=pin
(RGB 3 – lower right) red=pin6, green=pin0, blue=pin
(RGB 4 – lower left) red=pin7, green=pin1, blue=pin3

The result was strikingly happy! Check it out:

I Won’t Let You Down – OKGO

My Type – Saint Motel

I did have a bit of trouble with the sound portion of it all, somehow I configured the music to be ear-blastingly loud, and my little tiny iHome speaker didn’t have any volume control. So after blowing up my ears multiple times trying to figure out what went weird, all I did was enter alsamixer into my terminal, and there were sound controls right there for me. Woohoo! Just a few up/down keystrokes and the sound was ready to go.

For the fountain, it’s also very inconvenient that if I want any of this to work, I have to download the music I want to hear onto the raspi via flash drive. My friend and I decided that was dumb, so I researched how to get music by either bluetooth or some sort of airplay function. I discovered a fantastic program called shairport-sync, which works like any airplay device. It’ll broadcast an airplay-like signal to your apple devices that allows your phone, ipad, or computer to access and live-stream media through.

Sadly, though, my raspberry pi is a bit too old to support the software. I was able to get it installed perfectly and my phone all connected, but when I attempted to play a song, the lights lit up once and nothing came out of the speaker. After figuring out that my hardware was the problem, my friend offered to pay for a new Raspberry Pi 3 that’ll support the function much better. That’s coming soon, so I get to reinstall and figure this all out on a new Raspi! Until then, I’ve made good progress.

After we figure out the new raspi, I’ll order some insulated wire and get that hooked up to each LED that’ll sit inside the fountain to make pretty colored water.

Bye for now!

LightShow Pi ~ Early Tech Behind the Laminar Fountain

Today was awesome. I made huge progress in the tech side of the laminar fountain project.

I found a software called LightShow Pi, which was originally created for Christmas light shows, but many people have used it for smaller projects of their own.

The first step after getting an LED to flash with the Pi was to install the software. First I had to update all the packages ‘n stuff on my system with sudo apt-get update and sudo apt-get upgrade. That took around thirty-minutes to fully install.

Next I cloned the LightShow Pi repository off of GitHub: cd ~
git clone https://togiles@bitbucket.org/togiles/lightshowpi.git

And change to the stable branch of code: cd lightshowpi
git fetch && git checkout stable

Once completed, you install the stuff! Just make sure you’re in the “lightshowpi” directory. Then you can run: sudo ./install.sh.

This part tripped me up, because it took over two hours. Everything installed fine until it started running the line Installing rpi-audio-levels.... My Pi got really hot and stuck, so I rebooted and tried to reinstall, but it kept getting stuck. img_4697

I left it for about 2hrs (with many checks in between) before seeing that it had finished. Then I rebooted as the instructions said.

After that, the next step would be to build the actual LED setup on my breadboard. Initially I tried following this link, but only for a generic idea of how to wire the breadboard. I didn’t have a breakout board, so I went back to basics and made a simple circuit like the one in my last post, but with eight LEDs instead of just one. Next I attached the pins of the Raspberry Pi (3.3V and Ground) to the breadboard:img_4706

Next step was to figure out what GPIO pins the Pi was using for the project, the google doc said GPIOs 0-7. I used this chart to locate them.

img_4708

img_4712

Lovely mess, ain’t it? The pins are attached to their respective LED, and each LED is also connected to ground.

Finally, I could plug it all in and test this thang! To test it and make sure you have all the right channels, you run sudo python py/hardware_controller.py --state=flash

Each LED blinked twice, and I knew I had the right setup.

To play music, there were a few more steps I had to take. First, to make sure I had audio output, I connected my audio jack to a portable speaker I had (that’s the blue thing). Next I had to actually find the music. Using a Lexar USB, I pulled some mp3 files from my music collection and put them on the USB, which I connected to the Pi. Then using the command sudo python py/synchronized_lights.py --file=/home/pi/Desktop/Music/singles/shelter.mp3

With --file=, you continue the command with the file path of where your music is located.

After all that work, I got this wonderful result. https://youtu.be/oHTUvcA52Bo

Next step, to try it with RGB LEDs. Until next time!

 

Projects, Packages, and Progress, Oh My!

Good Morning, all!

It’s not really morning, but I like that greeting.

This past week has been filled with crazy excitement and many new things! I received two awesome packages filled with electronic components such as logic gates, cords, jumper wires, LEDs, RGB LEDs, resistors, and a breadboard. I couldn’t wait to start working with a breadboard for the first time.

My beginner storage is pretty good for now, but I can tell I’m going to fill it pretty quick and will have to upgrade to something else soon.

The first thing I did was find a guide on how to set up an LED on a breadboard and found this great article. To say I was ecstatic when I built my first circuit was an understatement.

I figured you could put multiple LEDs in a row, because that’s just a bunch of resistors in parallel and it would work, so I played around and got a happy rainbow:

I did learn that breadboard wire links are the same as jumper wires, they’re just specially sized for different purposes.
In my package I received an RGB LED (common cathode) as well, which is a Light Emitting Diode that has a Red, Green, and Blue LED in it, and it can make multiple different colors depending on the intensity of each LED. I had no idea how to get it to change colors, so I pulled out my Raspberry Pi for the first time and started experimenting, as I knew there were ways to get an RGB to work with a Pi.

My parents were a bit shocked when they came out and saw I had turned the TV into a monitor, but I assured them it was okay and I wasn’t going to break the TV with my programming.

I didn’t have a usb mouse to connect to my Pi, but I did have a nice mechanical keyboard that I got to highlight the desktop apps, which, fortunately, one of them was a terminal. (I love terminals.) I got the terminal up and running, next I needed to get the RGB LED hooked up to the breadboard and then connect the breadboard to the GPIO pins of the Raspberry Pi.

With this picture, I got the general idea of how to set up the wires in the breadboard and connect them to the Pi:

I must admit, it took me way too long to figure out that I had a Raspberry Pi 1, not a Raspberry Pi 2. Heh. Once I discovered that, I could effectively attach my jumper wires to the appropriate GPIO pins on the Pi, using this diagram:

gpio-pinout

Raspberry Pi I GPIO Chart

The code I used required me to attach my cathode (the longest pin) to pin 6, GROUND. The RED pin I attached to GPIO 12, GREEN I attached to GPIO 16, and BLUE to GPIO 18. Here’s a picture of it all set up (from two different angles).

Once I connected the wires right, I could start finding code to get this LED to work. After searching for code that worked with a Raspi 1, I stumbled upon this website by a guy named Henry Leach. Boy, was I glad to find his post. He showed his calculations about resistors and picking the right values to get the brightest colors, and then nicely shared his code that cycled through a variety of colors with his LED.

I don’t know anything about Python (yet), but I went with it because I wanted to get this thing working. I typed in all the code (which was painstaking, because I use a dvorak keyboard layout, but it was in US on the Pi. That took a while…) into the terminal text editor, nano. To get there, I opened a terminal and executed nano rgb.py

Once I finished typing that all out, I assumed IDLE was a Python Shell, so in a terminal I executed idle . From my experience with a Forth terminal, I knew if you wanted the code to be used in that session you had to use include filename.fth to use your code within the shell. I assumed import did the same thing, and viola, it worked! I had some syntax errors but once I fixed those and ran the program, I got a wonderful result:

I think the lights were a bit shaky at certain colors because I only had 1k Ohm resistors, so once I get my package of 30 different types of resistors today in the mail I’m going to try this project again to see if it makes a difference.

Now my goal is to replicate this in C code, as I’m going to learn it. After that, I’m going to attempt to get the LED to change colors and respond based on the waveforms of music that is playing, and eventually put this tech in the laminar water fountain I’m building with my friend.

I’ll put a post up about the fountain soon, we just bought the first installment of the supplies and materials, and once we start building it I’ll put up a tutorial type post.

Before I wrap up this post, in other news, I received a mandolin from my Nana as an early birthday present and I couldn’t be more excited!

I’ve been teaching myself some scales, and I’m working on the Irish Washerwoman melody picking. I’m thinking of naming it Henry. What do you all think? 🙂

Cheers!