Monday, May 27, 2013

Playing a YouTube Playlist in your DigitalSignage

If you're using DigitalSignage.com you'd probably like to play some videos on the screens. You can, of course, upload them to the Resources section, but if you'd just like to loop a YouTube playlist that's fairly easy.

First you'll need to find the URL for a YouTube playlist. Click the title of the playlist, then click the Share button. The URL will be something like http://www.youtube.com/playlist?list=PL627F181E0CB37E19 and the important part is the characters after the = sign.

I'm assuming that you know how to set up screen divisions and campaigns, so grab an HTML5 component from the toolbox and drop it in place. The URL you will put in that component will look like this http://www.youtube.com/embed?listType=playlist&autoplay=1&loop=1&list=PL627F181E0CB37E19 where autoplay=1 means that it will automatically play the through the playlist, and loop=1 means that it will go back to the beginning once it finishes. Of course you will replace the characters after list= with the playlist that you want to use.

Saturday, May 18, 2013

Playing Songza on an EeePC 701

This old seven-inch laptop is still useful for a few things, I've recently connected it to my stereo system as a Songza player.

There were two things I needed to do to get this working:

Install Lubuntu
Install Adobe Flash Player from the tar.gz (which involved copying the .so file to /usr/lib/Chromium and copying the folder somewhere else)

I can write up more details if you ask in the comments.

I tried Google Chrome, but it was too resource-intensive so the audio stuttered. I wasn't able to install the Flash plugin in Midori for some reason, so I went back to Chromium and got it working there. The next step will be to connect a USB IR remote receiver with some scripts for selecting different Songza playlists, pausing, and adjusting the volume.

Wednesday, May 15, 2013

form data averages Google Apps Script

When a Google Form is submitted, it adds a row to your spreadsheet. This changes your formulas, which is a problem if you are trying to do live calculations on submitted data, so you need a script to copy in the correct formulas after each form submission.

Here's an example of how I did that. The script is set to trigger whenever a form is submitted.

function insertAverage() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  var formulas = [
   ["=AVERAGE(C3:C100)", "=AVERAGE(D3:D100)", "=AVERAGE(E3:E100)"]
   ];
  var destination = sheet.getRange("C2:E2");
  destination.setFormulas(formulas);
};

Monday, May 6, 2013

Programming with Pure Data and Open Sound Control for the Behringer X32

Pure Data is an easy graphical programming environment. It can speak the OSC (Open Sound Control) protocol, so you can write programs to communicate with Behringer X32 digital mixers using their published X32 OSC Remote Protocol. Don't worry, it's easier than it sounds.


1. Download Pure Data Extended (which includes things that we'll need).
2. Unzip and/or install it.
3. Run the program Pd-extended.
4. If you're using Windows, it will likely ask you if you want to allow it to communicate on the network. Click Allow access and input your Administrator password if necessary.


5. In the window that pops up, choose New under the File menu.

6. You now have a blank canvas to put commands, controls, and such on to.

7. Under the Put menu choose Object (or hold the Ctrl key and press 1).
8. In the newly-created object type  import mrpeach  to tell it that you need to use that package.

9.  Under the Put menu choose Message and type in it  connect x.x.x.x 10023  but replace the x values with the IP address of your X32 mixer. For testing purposes you can have it connect to localhost (the computer that you're sitting at) instead.
10. Create a  disconnect  message and a  udpsend  object as well.
11. Drag from the bottom left corner of each of those messages to the top left corner of the udpsend object in order to connect their outputs to the udpsend input.

12. Now everything is set up to communicate, but we need to actually compose some messages to send. To start let's set up a fader to control a channel level, and a button (toggle) to control the mute for that channel. Under the Put menu choose Vslider to place a vertical slider and Toggle to place your mute button.

13. Put messages for sending mute on/off and fader levels for a particular channel following the X32 OSC specifications. For example,  send /ch/01/mix/on $1  will take the input value ($1) to send the message  /ch/01/mix/on 0  to mute channel one or  /ch/01/mix/on 1  to unmute it.

14. You'll also need to put in a  packOSC  object to create the OSC messages, and connect its output to the  udpsend  object.

15. One last thing you'll need to do is change the Vslider's properties to output values from 0 to 1 as the X32 expects. Right-click the Vslider, choose Properties and change the top value to 1 instead of 127. You can also change the size and color here if you'd like.

16. Your program is now all set up. To run it, go to the Edit menu and choose Edit Mode (to turn off the edit mode) or hold the Ctrl key and press the e key. Once the program is running, click on one of your connect messages to connect to the X32, then drag the slider and click the toggle to see their effects.

Optional: If you'd like to test without connecting to the X32, create another Pure Data program by choosing New under the File menu and make it look something like the following. Remember that the Vslider range should be 0 to 1.

When your new OSC receiving program is running (not in edit mode), you should be able to click connect localhost 10023 in your original program and then see that the slider and toggle there will affect the corresponding ones in your new program.

Hopefully that's enough to get your started in writing Pure Data programs for you X32 digital mixer.

Wednesday, May 1, 2013

Lighting LEDs on the Raspberry Pi with Python

There are many tutorials available for this already, but I just wanted to collect my observations into a series of steps that I can repeat later.

For reference, I used raspberry-gpio-python, Raspberry Leaf, and How to use your Raspberry Pi like an Arduino.

I connected an LED and an inline resistor to GPIO pin 7 and ground, one side of a momentary pushbutton to ground, and the other side of the pushbutton to a 1 kOhm resistor connected to 3.3 V.

Starting from a fresh install of Raspbian, at the command line (or in LXTerminal) input the following -commands: (edit: the crossed-out commands aren't really necessary)

sudo apt-get update
sudo apt-get install python
sudo apt-get install python-dev
sudo python distribute_setup.py
sudo easy_install pip
sudo apt-get install python-rpi.gpio

sudo python


#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

# define the pins we're using
button1 = 4
LED = 7

set up the pins
GPIO.setup(button1, GPIO.IN)
GPIO.setup(LED, GPIO.OUT)

# turn on the LED
GPIO.output(LED, True)
# wait for half a second
sleep(0.5)
# turn off the LED
GPIO.output(LED, False)
# toggle the LED
GPIO.output(LED, not GPIO.input(4))

# set up some variable to read from the button
input = False
previousInput = True

# loop
while True:
 # read the button state to the variable input
 input = GPIO.input(button1)
 # make sure the button state isn't what it used to be
 if ((not previousInput) and input):
  print("button pushed")
 # copy the button state to the previousInput variable
 previousInput = input
 # wait to "debounce" the input
 sleep(0.05)

# clean things up
GPIO.cleanup()

Vectorizing a Scanned Object for CNC Cutting

If you have a physical object or paper drawing that you'd like to carve out using a CNC router or plasma cutter, here's one way to do it. We're going to use the open source drawing program Inkscape for turning scanned images into vectors that the machine can cut.

Start by scanning the object (or drawing) on a flatbed scanner. If you don't have access to a scanner, you can try taking a picture from directly above the object (or the drawing). For this example I've scanned a handheld wireless microphone.
This will be a somewhat complicated image to vectorize, it would be better if it was simply black and white (like a line drawing or most logos). The nice thing about how this scanned, though, is that the background is totally white. Don't worry if yours isn't, that's something we can deal with or fix later.

Start up Inkscape (you can download the portable version if it's not installed on your computer) and under the File menu choose Import... and find the image that you scanned earlier. It doesn't matter if you link or embed, since you'll be removing the image from Inkscape soon anyway.

Now it's time to turn that image into a vector outline. Make sure that the image is selected, and under the Path menu choose Trace Bitmap... to bring up the following window.

Experiment with changing the Brightness cutoff Threshold. I tried values of 0.4, 0.6, 0.8, and 0.9 to get the following vectors (from left to right, with the original bitmap image on the far left).

Each time you click OK it will create another vector object, which you can delete if you don't like it. In my example above there's a little white spot that shows up even at high threshold values, so that's something that I could go back to the original image and paint over, or I can break apart the vector group and delete the parts that I don't want. (Under the Path menu choose Break Apart, then delete everything you don't want).

After all of that, we end up with a fairly good outline of the object.

You can also experiment with the Simplify command under the Path menu, each time click that it will remove some points from your vector.

Depending on the resolution that you scanned at, you will probably have to resize the vector to make it the size of the actual object. Make sure the lock is engaged (to maintain the proper aspect ratio) and the units are in inches (or mm if you prefer). Typing a value in the width (W) will change the height (H) and vice versa.
So we have now vectorized the scanned image, and it's ready to be saved and then imported into your favorite CAM program to generate g-code for your machine. Or you can use the Gcodetools plugin for Inkscape.