Skip to content

Recent Articles

11
Mar

Using dbus on OS X Yosemite

In the ongoing effort to enhance Podtique for mere mortals, I’m building a web server within the device to aid in configuration. I’ve chosen node.js (really, locomotive) for this. But the main code is written in C++, and I needed a way for the node.js code to communicate with the C++ process.

For now, I’ve settled on dbus for this. While the actual device runs Linux, making dbus a natural choice, I prefer to do as much development as possible on OS X, and dbus also works on OS X when installed via brew. But before you do that, there are a few caveats to getting d-bus to build and run on Yosemite (probably true of the last few OS X releases) that aren’t handled by brew out-of-the box.

Setting up dbus

Be sure to remove any leftover launchd files that might’ve been installed by MacPorts. My system had symlinks pointing into /opt, but /opt did not exist.

/Library/LaunchAgents/org.freedesktop.dbus-session.plist
/Library/LaunchDaemons/org.freedesktop.dbus-system.plist
~/Library/LaunchAgents/org.freedesktop.dbus-session.plist
~/Library/LaunchDaemons/org.freedesktop.dbus-system.plist

A Google search turns up a lot of information showing both of these plist files being used, but the latest version only provides one of them, and that’s all that seems necessary.

Now install dbus:

    $ brew install d-bus

As of this writing, this installs dbus 1.8.14.

dbus requires a dæmon process to be running. Thew brew formula for dbus doesn’t set that up automatically, but has some instructions to set it up. Execute the following commands to configure the dbus dæmon to run automatically:1

    $ ln -sfv /usr/local/opt/d-bus/*.plist ~/Library/LaunchAgents
    $ launchctl load ~/Library/LaunchAgents/org.freedesktop.dbus-session.plist

If launchctl reports the following:

    /usr/local/Cellar/d-bus/1.8.14/org.freedesktop.dbus-session.plist: File exists

it means that it is already loaded and running (perhaps from a previous install). Try the following (you might need to sudo):

    $ launchctl remove org.freedesktop.dbus-session

Note: It’s important to note that the user that starts the dbus dæmon should be the same user that will own the processes that want to communicate with that dæmon.

Setting up Xcode

Setting up Xcode is relatively straightforward. Select the appropriate target, choose the “General” tab, and click the “+” under “Linked Frameworks and Libraries.” This will open a sheet. Click “Other…” and begin typing

    /usr/local/lib

Then find libdbus-1.dylib and click “Add.”

Next, click on the “Build Settings” tab and ensure that you have the following search paths added to “Header Search Paths”:

    /usr/local/include/dbus-1.0
    /usr/local/lib/dbus-1.0/include

Include dbus headers like this in your code:

    #include <dbus/dbus.h>
1Note that the launchd plist provided by dbus 1.8.14 has a key that’s no longer used (not sure when it was deprecated; a google search is little help). You can just remove the ServiceIPC and associated value from the file if you see

    com.apple.xpc.launchd[1]: (org.freedesktop.dbus-session) The ServiceIPC key is no longer respected. Please remove it.

printed in the Console.app log.

17
Feb

BurningMan Solar Power

Last year I powered my camp entirely from the sun (with the exception of our ridiculous lighting on Pipe Dream). Here’s a quick description of the system.

https://farm8.staticflickr.com/7341/15942859233_c50327e966_z.jpg

Equipment list:

Panels 3 72-cell, 230 W, leased from BRS
Charge Controller Morningstar TriStar MPPT 60
Inverter Samlex 24V 2000W Pure Sine Wave
Batteries 2 SunXtender PVX-2120L 12 V 212 Ah
Electrical Panel Midnight Solar MNE125ALT
Monitoring Pentametric PM-5000-U and PM-102-USB, and a BeagleBone Black with LCD display and custom software.
Hardware Custom-designed and built PVC rack, XRS Rails, associated mounting hardware. Also, breakers, outlets, grounding hardware, surge protection on panels.

https://farm8.staticflickr.com/7305/16375388638_84d7fb466a_z.jpg

9
Jan

Antique Radio Podcast Player

Update: I got covered by c|net’s Tomorrow Daily!

Note: If you commented on this post, I’m very sorry; A technical glitch caused me to lose all the comments. Please comment again!

One of my favorite things in the world is The Thrilling Adventure Hour (TAH), a stage production in the style of old-time radio, performed live on stage, and recorded as a podcast. I fly to LA once a month to see the live show, wherein actors stand on stage at microphones, scripts in hand, performing episodes of different story lines. The evening usually begins with an episode of “Sparks Nevada, Marshal on Mars,” and ends with an episode of “Beyond Belief.” There is a rotating story’s episode in the middle, and a couple of fake sponsor ads thrown in. They have surprise guest actors (often well-known from TV or movies), and then the entire cast and crew spend time after the show to chat with audience members. It’s funny and fun, and I wouldn’t miss it.

One of my friends (who often sees the show with me) has a father who collects old radios. This got me thinking about what it was like before television, how people gathered around their radios to listen to radio plays. What if you could listen to The Thrilling Adventure Hour on an old radio?

As it turns out, it’s very common to modify old radios to accept an auxiliary input for an MP3 player. With these modifications, whatever the MP3 player outputs is amplified through the vacuum tubes of the old radio and played on the old speaker.

But I wanted something different. I wanted to turn the tuning knob to “tune” in different podcasts. In the case of TAH, there would be “stations” for Sparks Nevada, Beyond Belief, Jefferson Reid, and so on. They have a lot of music in the show, too, so there’d be a station of TAH music. So, I built this:

Podtique: Antique Podcast Player

Video of it in action:

I call it “Podtique”, an amalgam of “podcast player” and “antique radio.” I took a 1936 Goldentone radio purchased on eBay, removed the old tube radio and speaker, and replaced them with a laser-cut wooden structure that contains a BeagleBone Black and audio components. Potentiometers attached to the knobs on the front are connected to the BBB’s analog-to-digital converters, and code on the BBB uses that to simulate tuning to different radio stations.

Adding backlight and amplifier mute control.

More photos are available.

As long as it’s powered, the BBB runs the radio simulator. The left knob contains an on-off switch and volume control. The third knob is the tuning control. The other two knobs are currently unused.

Each “station” is a playlist of MP3 files stored on the BBB. The tuning knob is attached to a five-turn potentiometer, giving fairly fine-grained tuning control to the user. As you approach the designated frequency for a station, the appropriate MP3 file is opened and begins decoding.

Whenever you’re not tuned to a station, pink noise plays. This is mixed with station content, gradually fading away as the tuning improves. The volume potentiometer is used to attenuate the resulting mixed samples. If the knob is turned all the way off, the BBB mutes the audio amplifier and turns off the dial backlight.

I used a SparkFun Proto Cape to wire in the potentiometers and add the electronics for interfacing with the audio amplifier and AdaFruit NeoPixel Ring 24. The NeoPixels introduced horrible, horrible noise into the audio, so I experimented with LC filtering until I was able to attenuate it fairly well, and added that to the Proto Cape, as well. The audio codec is an Audio Technica ATR2USB purchased at Fry’s. A SparkFun Audio Amplifier and 4″ speaker from Fry’s round out the audio components. There’s a giant R/C lithium-polymer battery pack hacked into it so I can demo this without being plugged in. A cheap DC-DC converter provides 5V from a wide input range (the amplifier needs 9-24 V). A 12 V switching wall wart adapter provides power (and its own share of noise, but nothing compared to the LEDs).

I’m working on a fully-custom BeagleBone Black Cape that will integrate audio DAC and amplifier, LED interface, power regulation, and battery charging. Hopefully this won’t have the noise issues, will be much more compact, and easier to use. If there’s any interest, I’ll manufacture and sell them. The software is available on GitHub.

The software runs on Debian and OS X. It uses libao for audio output, libmpg123 to decode MP3s, and C++11 features for threading. All that works well on Debian and inside a Cocoa app on OS X. On the BBB it uses LEDscape to control the NeoPixels (special thanks to Yona for making some changes to support a single NeoPixel string). LEDscape relies on prussdrv to handle the strict timing requirements of the NeoPixels.

Mechanically, it was necessary to duplicate the linkage between the tuning knob and the frequency indicator dial. In the original radio, this was accomplished by a pulley system. A thread wrapped once around the knob’s shaft went to a fairly large metal pulley on the indicator dial’s shaft. This was also connected to the variable tuning capacitor. The original system had a turn ratio of about 14:1.

In order to get good sensitivity with the knob, it was easier to put a five-turn potentiometer on the knob, and cut an appropriately-sized pulley for the indicator shaft. In the end, the ratio is a bit wrong, and the indicator goes past the dial at the extremes of the pot’s motion.

I learned a lot more about the Linux kernel than I ever wanted to know during this project. I’m still barely scraping by. I really do prefer OS X.