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.

Thursday, April 25, 2013

iPad app: Entrepreneurship Essentials course


ADLCRobots and Pencils, and GoForth Institute have developed an iPad app that teaches Entrepreneurship Essentials. Through the simulation of running a lemonade stand, it uses gamification principles, text slides, videos, and auto-graded quizzes to deliver the content for five one-credit CTS courses (ENT1010, 1020, 2010, 2020, and 2030).

It is fairly well designed, certainly better than most LMS-based online courses. Students will still need to be somewhat self-motivated to make it through, but the badges, notifications, and challenges should help.

From what I hear, schools that register students in this "course" can receive all of the CEU funding if they have a teacher assigned to do the "marking" and tracking, or they can receive 3/5 of the funding if they get ADLC to do all of that.

There has been some media coverage by CBC News and the Edmonton Journal. If you're interested, check out more information and an introduction video.

At any rate, I'm certainly going to recommend it to high schools that have students interested in entrepreneurship and/or interested in trying a different method for getting CTS credits. Information about registration is here.

Thursday, April 11, 2013

things I've learned about Source Filmmaker

I've been playing with Source Filmmaker a bit lately, and I wanted to document some of the things that I've learned.

The best source of information is the official SFM wiki.

There are also numerous video tutorials available on YouTube, including the official ones.

The up and down arrows take the playhead to the beginning and ending of a shot, respectively.

Audio should be in WAV format. And I recommend using a nice USB microphone for recording audio.

More models and props can be downloaded (subscribed) from the Steam Workshop. I was particularly interested in models with facial animations for lip-sync, and there are a number available there.

Attach a prop (e.g. a hat) to a character's head by locking it to the bip_head control in the character's animation set. Drag the character's bip_head control on to the hat's bip_head (or rootTransform) control, then select all of time in the Motion Editor (if it's not all green already), select the Body animation set of your prop and then under Procedural drag the Default control from left to right. You may need to adjust its position a little, especially if you used rootTransform because there was no bip_head.

Attach a prop to a character's hand by locking it to the weapon_bone under Unknown in the character's animation set. Similar to the above process.

In order to render 1080p videos, you need to start the program with the argument -sfm_resolution 1080 (either from your Steam library by right-clicking it and choosing Properties then SET LAUNCH OPTIONS... or by editing the desktop shortcut). This isn't recommended until you're ready to render, since working in 1080p makes things a little slow. Rendering 1080p videos takes a long time too, on my i7 desktop it took almost an hour and a half to render a one minute clip. If you're really adventurous you can render at 4K with -sfm_resolution 2160 but you'll need a decent computer a lot of time.

The basic process I go through to create videos (like the one below) is:
  1. launch Source Filmmaker
  2. name your session (or open an existing session)
  3. set the Framerate to 30 (although the default 24 is fine too)
  4. right-click the black part where it says "No Map Loaded!" and choose Load Map...
  5. decide where you'd like to film
    • you can move the camera around by holding down the mouse button where you'd just loaded a map (the viewport) while you use the keys WASD and ZX
  6. click the + sign right underneath Animation Set Editor to Create Animation Set for New Model
    • look in the categories player and survivors for good human models
  7. move the model to the appropriate place by selecting its name in the Animation Set Editor, the move tool  (near the bottom right of the map window) and either the Motion Editor (F3) or the Graph Editor (F4)
  8. add a camera by pressing c on the keyboard
    • or click the down arrow on the right of the active camera button (below the viewport), click Change Scene Camera, and click New Camera.
  9. click the + sign to Create Animation Set(s) for Existing Element(s) and choose camera1 so that you can animate that camera
  10. add any props and position them how you'd like
    • the same way that you added a new model in step 6
    • if you want them to move with a character, make sure you lock them to that character (e.g. their weapon_bone or bip_head)
  11. add your recorded voice clip by selecting the clip editor (F2), right clicking on Dialog (near the bottom), and choosing Add Clip to Track or Record Narration
    • when you are adding a clip to a track, any WAV files that are in the ...\steam\steamapps\common\sourcefilmmaker\game\usermod\sound file will show up
  12. to have your character move their lips along with the voice track, select the Dialog track, the character's Lower Face (and Tongue) in the Animation Set Editor, right-click in the Animation Set Editor, and choose Extract Phonemes
  13. I usually animate the camera by moving it around rather than using the fieldOfView control
So that is a very brief overview of some of the things I've done in Source Filmmaker so far. Here's an example of one I did recently: