Fixing stuttering/high CPU mpd on Pogoplug

Recently got a special on pink pogoplugs, two at $12.95 each. My friend John also bought, and he clued me to the fact that these were labelled B01 on the outside, but were really E02 models as shown on the device itself.

I quickly had Debian Squeeze on the box using Jeff Doozan's script, then upgraded to Wheezy. Since I like to set up boxes as music players, I added mpd and mpc to the install.

I was listening to music in no time. However, there was a problem. My favorite classical music streaming station is KVOD from Denver, cpr.org. Of the five classical streams I had in my playlist, they were the only one to stutter every few seconds - the other stations played fine.

After hours of trying different things to fix the problem, I finally hit on a combination of factors that somebody had an answer to. I noticed that ONLY the problem stream showed high CPU in top, and also
had the stutter.

If you look in mpd.wikia.com/wiki/Tuning, you'll see references to samplerate. One suggestion was to change to:
samplerate_converter "internal"
I tried that and it immediately fixed the problem, at the cost of reduced sound quality.

There are other suggestions on the Tuning page, so check there for more detail.

ATTINY45 Angel Bell

P40

This is a mod of Jeremy Blythe's raspberry Pi solenoid alarm bell. I turned it into a kind of Christmas decoration/art thingy, prototyping on an arduino and then moved it to an Attiny45 for implementation. The sign is just an acrylic photo holder with a printed message. US visitors will recognize the reference to the inescapable seasonal movie, "It's a Wonderful Life".

The sketch is trivial. It's just the arduino Blink example with a HIGH for 80ms, then LOW. The low has a random delay of 30 seconds to 2 minutes.

Direct rsync from DeltaCopy on Windows 7 to Ubuntu

I'd been meaning to set up rsync from my music server, a Windows 7 computer, to my ubuntu backup server for quite some time. I'm more familiar (though not very) with rsync in ubuntu than the DeltaCopy Server for Windows.

So, today I finally got rsync.exe going under DeltaCopy.

Here's the process in a nutshell.

First Install DeltaCopy
        * Set up the service
        * Set up the client with no authentication


Go to a terminal/Command Line in Windows

Run rsync.exe directly from DeltaCopy installation
        cd d:\DeltaCopy   (where rsync.exe is installed)
        use the following form of the command
        rsync.exe -n -arvz /cygdrive/d/music/iTunes/Purchased/ username@192.168.0.nnn:/music/iTunes/Purchased     [Note: -n = dry run, remove to run it for real!]

where /cygdrive/d/music/iTunes/Purchased/                       =====>  source
      username@192.168.0.nnn:/music/iTunes/Purchased     =====>  target

The trailing slash after /cygdrive/d/music/iTunes/Purchased/ <==  is VERY important when you already have a directory structure set up on the target. It means DON'T create a new folder/directory.

Conversely, it you leave the trailing slash OFF, a new folder/directory WILL be created.

PiTX Raspberry Pi Power Controller

P35

Jason on his blog (http://www.boeeerb.co.uk/pitx-an-atx-style-solution-for-the-pi/) described an innovative approach to controlling the power on a raspberry Pi.

I've already corrupted the file system on my Pi by just pulling power, so this was a great idea!

Here's my first prototype based on Jason's work. This version uses a DC 2.1 barrel connector to a 5V 1A wall wart, a DPDT 5V NTE R40 relay, some tactile buttons from adafruit.com all soldered together on an adafruit perma-proto board.

The large tactile buttons are color-coded green for go/start, red for shutdown/stop. The shutdown button is hooked into GPIO 18 on the Pi, where a running python script checks for signal. On high, the script executes a shutdown.

Getting CMedia USB Sound to Work with MPD on the Raspberry Pi

This assumes that you have a working installation of mpd and mpc and you can get sound out of the analog port. Using 2012-09-18_wheezy.img, the analog sound still has loud pops when you change streaming stations in mpd, plus noticeable hiss in the background of quiet passages.

To get the CMedia USB Sound dongle (looks like this one available at Newegg) working, you need to install alsamixer (if not already installed) via the command:

sudo apt-get install alsa-utils

Once that is installed, you need to modify the appropriate section of /etc/modprobe.d/alsa-base.conf so it looks like this:

# Keep snd-usb-audio from beeing loaded as first soundcard
#options snd-usb-audio index=-2
options snd-usb-audio index=0

Setting the index to 0 allows the USB Sound dongle to be loaded first. Index=-2 prevents that.

Then, in /etc/mpd.conf, you want to change the sound section like this:

# An example of an ALSA output:
#
audio_output {
    type           "alsa"
    name         "My ALSA Device"
    device        "hw:0,0"    # optional
    format         "44100:16:2"    # optional
#  mixer_device    "default"    # optional
    mixer_control    "Speaker"    # added 2012-10-04 for USB Sound dongle
    mixer_index    "0"        # optional
}

"Speaker" is how alsa-mixer refers to the device (alsamixer partial screen show below):

 Card: C-Media USB Audio Device                       F1:  Help               │
 Chip: USB Mixer                                      F2:  System information │
 View: F3:[Playback] F4: Capture  F5: All             F6:  Select sound card  │
 Item: Speaker [dB gain: -26.69, -26.69]              Esc: Exit              

If you have problems, examine the output of mpd from /var/log/mpd/mpd.log by tail. When I was troubleshooting this, the log was helpful. Here are some sample messages which pointed me in the right direction:

Oct 14 19:46 : avahi: Service 'Music Player' successfully established.
Oct 14 19:46 : mixer: Failed to read mixer for 'My ALSA Device': no such mixer control: PCM

I tried using PCM because that is the associated with the first installed sound card. Making the changes shown for alsa-base.conf to allow the USB Sound card to start first changes the alsamixer output to Item: Speaker from Item:PCM

LCD and Pandora on raspberry pi

P32

Went to town on the raspberry pi this week while I stayed with my friend John in Eureka.

The picture shows my new Pi in a laser cut case I made at TechShop SF last week. On top is a TextStar tiny LCD showing one of 4 screens, this one the wireless USB adapter's IP address. See the post at jeremyblythe.blogspot.co.uk, "Raspberry Pi with TextStar Serial LCD Display" on how to set this up with python.

I used adafruit's nice Occidentalis v0.2 release for the main software, based on Raspbian Wheezy Debian. This has a lot of good packages already built in, including ssh. I just used my Mac Terminal program to set the Pi up over Ethernet initially.

To get pandora going, I used pianobar. The install is simple:
sudo apt-get install pianobar
Set up the config file for automatic login and you're good to go.

To get streaming radio on the Pi, I installed mpd, the Music Player Daemon. This is an easy install also:
sudo apt-get install mpd mpc
See the article at www.t3node.com/blog/streaming-audio-with-mpd-and-icecast2-on-raspberry-pi for setup.

Getting the Pi to work with the popular mpd iPhone client, MPoD, was a bit of a challenge. MPoD could see the Pi via avahi/bonjour, but not connect to it. John found out you have to have bind_to_address for "local host" commented out for MPoD to be able to connect to it.

Make a micro SIM adapter from a full-sized SIM

The rumor mill is pretty confident there will be a new iPhone announced on September 12, 2012. I knew I was eligible for an upgrade and wanted to get the new iPhone when it came out. What to do with the old iPhone? I checked gazelle.com for their prices on an unlocked iPhone 4, about $172 for good condition at the time I checked. But eBay had them going well north of $300.

So, I priced my iPhone 4, which I thought was in very good condition, at $350 Buy It Now / $250 auction reserve. BAM! Sold in 35 minutes.

Now, what do I do for a phone until I get the new iPhone? Hmn... I have an old Samsung BlackJack II locked to the AT&T network, that should work. Except for the size of the SIM - the iPhone 4 uses a micro SIM, and the BlackJack used a full-sized SIM. I had a dead, previously used AT&T standard-sized SIM from yet another phone. I decided to cut the full-sized SIM into a kind of tray adapter for the micro SIM. There are actual commercial products like this available on Amazon, but I didn't want to wait for shipping.

First, line up the contacts of the micro SIM approximately where the same contacts are on the full-sized one. Draw an outline for cutting, I used a fine point Sharpie. This doesn't have to be very precise, just an opening big enough to hold the micro SIM. Then, using a box cutter or Xacto knife, first carefully score the outline all the way around. Then slowly and carefully cut deeper into the outline. Work slowly, you don't want to break the plastic. Add Scotch tape to hold the micro SIM in place. The whole process should take about 15 minutes.

SiliconDust HD HomeRun Prime CableCard Set-Up

My current DVR solution, BeyondTV, was ageing and appears not to be the long-term focus of Snapstream, so I went shopping for a new solution that had some legs. I have the Extended Basic tier with Comcast and due to encryption of the "channels" above 30, I was only able to record about half of the content I was paying for. I could get HD local channels nicely with my twin Hauppauge 2250's, but couldn't record the likes of History Chnnel, Discovery and others.

Turns out my local Fry's had a special on the SiliconDust HD HomeRun Prime networked-attached cablecard tuner for $30 less than the current Amazon price. Newegg and Amazon reviews were favourable. The downside was dealing with Comcast to get the required cablecard and get the card activated once installed. Forums were full of postings of long waits, both in-store to pick up the card and hours spent on the phone to Comcast Tech Support to get the card activated. 

Decided to bite the bullet, figuring the possible short-term pain would be worth the long-term gain. Turns out, things went quite smoothly. Maybe not butter, but at least cake.

Visited the local Comcast store at 9:21 on a Monday morning. The walk-around greeter told me it would be about 10 minutes wait. Yeah, sure!  I had to recant my cynicism when I walked out of the store with Multistream cablecard in hand at 9:31.

The rep at the Comcast store-front told me to insert the card SLOWLY and call the number at the bottom of the invoice ASAP after install. Do both of those things, and I'm waiting on the line, when I notice the invoice says you can activate over the Internet at comcast.com/activate. OK, I can try that whiIle I'm waiting. The three-step activation has me done in about five minutes and says wait 45 minutes for activation to complete, so I ditch the phone call.

The HomeRun Prime works with Wndows Media Center under Windows 7. While I'm waiting for the activation to complete, I install the HomeRun Prime software on one of my three Windows boxes. As one of the last steps in the install, I did a channel scan expecting no channels to appear. But, no - channels start appearing in the HomeRun config tool! So, in my case it looks like activation took less than 30 minutes. Cool.The odd thing was, the web page that the HomeRun config utility takes you to (a 192.168.0.* address on your network under DHCP) indicated no channels were downloaded to the three tuners even after activation was complete and I could view channels in WMC. I refreshed a couple of times and still got the same report back, no channels.

Get to work on configuring WMC. Go to Tasks/Setup/TV and begin. PlayReady ( for DRM content) and DCA (Digital Cable Assistant) download if they are not already present in WMC. At one point, WMC tells me that my computer is unable to receive digital channels, but I keep going. Don't know what WMC was trying to tell me, but after waiting for the Program Guide to download, my spot checks showed I could view even formerly unavailable content just fine. 

The only slightly rough spots were when I set up the HomeRun on a WMC machine previously configured for the Hauppauge 2250. First, the DCA wanted a Product Activation Code and they weren't talking about the Windows OS. They meant the HomeRun product code. A little googling turned up a valid product code in the SiliconDust forums:
263DJ-2Y9YT-6X9G6-W28DB-697TF
This is for the forum entry: http://www.silicondust.com/forum/viewtopic.php?t=10080

The other problem I had was due to my previous tuner installs with the twin Hauppauge HVR-2250's. Although WMC would recognize all of the installed tuners including the HomeRun, the Program Guide information looked like it only used the 2250's which were not able to receive the encrypted/non-clear QAM channels. To fix this, I went back into the TV tuner setup and picked the manual option, then set up ONLY the HomeRun tuner.

In summary, for me this was a fairly straightforward set-up; perhaps I just got lucky this time.

Pro's:

  • can watch TV through WMC on any computer in the house with HomeRun software installed
  • fairly straightforward set-up for HomeRun
  • self-activation with Comcast actually worked and was painless (quelle surprise!)

Con's:

  • the HomeRun seems to only show SD content; the Hauppauge HVR-2250 also shows HD local channel offerings
  • a little laggy in WMC when you first start up, say a few seconds of unsynchronised lips/audio

 

UPDATE:

I was confused on the HD offerings due to different presentation styles. On the HVR-2250, local HD channels are interleaved with SD channels like so: 2 (SD), 2.1 (HD) and so on. The CableCard presents the local HD channels and other content in the 700's-800's band of channels.

 

Getting ATTINY45 to work at 8MHz with Arduino-1.0.1 and USBtinyISP

Working on a project to get an IR remote to work with an ATTINY45. The stock '45 comes with fuses set for 1Mhz.

I had a problem with the remote codes not being recognized and needed a way to see exactly what was going on. ATTINY doesn't natively support SoftwareSerial, but you can include the library for that. Problem is, the lib wants to run at 8Mhz or above. There is a way to easily change the fuses so the '45 runs at 8MHz,  using the 1.0.1 IDE and an add-on mentioned by the Hi Low Tech Group of MIT (here).

Make SURE you get a version of the ATTINY download that contains the folders variants and boards.txt and place them in the folders mentioned in the Hi Low blog above. Start arduino-1.0.1.  On my Ubuntu system, I need to run the USBtinyISP under sudo, so I navigate to the folder the arduino program lives in and type in sudo arduino-1.0.1 from the command line to start the IDE. Plug in  the USBtinyISP and set it in Tools\Programmer. Follow the instructions on the blog to "Burn Bootloader" after choosing Tools\Board\ATTINY45 (internal 8MHz clock). This normally won't show the results of the fuse burning command. To verify the fuses are being burned, before running "Burn Bootloader",  under File\Preferences, check the box for "Show verbose output during    upload".

To get the fuses and program burned onto the ATTINY45 chip, I mount the chip on a small breadboard and attach the pins to the USBtinyISP like so (from Maarten Damen's blog):

  • ATtiny Pin 2 to USBTinyISP SCK
  • ATtiny Pin 1 to USBTinyISP MISO
  • ATtiny Pin 0 to USBTinyISP MOSI
  • ATtiny RST pin to USBTinyISP RESET

and +5v to Vcc. GND to GND.

Here are pinouts for the ATTINY45 and the USBtinyISP. The pinout shown is for the ATTINY25, which is the same as the '45/'85.

 

Attiny25-pinout

Adafruit_usbtinyisp_pinout_6and10pinstd

To show where the *.hex program is located after a compile, check the box in File\Preferences\"Show verbose output during compile". On my Ubuntu system, this is located in /tmp/buildnnn.tmp/program_name.cpp.hex (where nnn = some alpha-numeric identifier). I compile from the command line like so:

user@mybox:/tmp/build3204698977405188542.tmp$ sudo avrdude -c usbtiny -p t45 -U flash:w:program-name.cpp.hex

If everything went well, you should see something like this:

sudo avrdude -c usbtiny -p t45 -U flash:w:attiny45_serial_example.cpp.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9206
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "attiny45_serial_example.cpp.hex"
avrdude: input file attiny45_serial_example.cpp.hex auto detected as Intel Hex
avrdude: writing flash (3894 bytes):

Writing | ################################################## | 100% 11.50s

avrdude: 3894 bytes of flash written
avrdude: verifying flash memory against attiny45_serial_example.cpp.hex:
avrdude: load data flash data from input file attiny45_serial_example.cpp.hex:
avrdude: input file attiny45_serial_example.cpp.hex auto detected as Intel Hex
avrdude: input file attiny45_serial_example.cpp.hex contains 3894 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 7.21s

avrdude: verifying ...
avrdude: 3894 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.