I’ve been using the Fractal Design R4 PC case for a number of years now. I love the design but the placement of the headphone jack leaves something to be desired. It is oriented vertically meaning that pulling on the headphone cable can easily break the port which unfortunately happened to me. Removing the front panel of the case reveals a small circuit board labeled “USB-70A AZALIA REV: A1”.

The circuit board with damaged headphone jack

Not designed with toddlers in mind

A quick search showed me that it’s not easy to find a replacement for this part so I decided to write up how it can be repaired.

The board consists of two headphone jacks and a pin header. The broken headphone jack needed to be replaced. The first step is finding the correct replacement part. Some searching reveals the CP1-3525NG-ND on Digi-Key. I always order inexpensive parts in multiples of 10 to get the price break and because it’s good to have spare parts around for future projects.

A handsome array of headphone jacks

Using a soldering iron, heat up and remove as much of the solder around the pins of the headphone jack as possible. I didn’t have much luck with soldering wick but a soldering vacuum worked well. A trick is to add a small amount of solder to the tip of the soldering iron to help quickly heat the solder in the joint.

After removing the solder, gently remove the old headphone jack.

PCB after removing the broken headphone jack

Solder the replacement headphone jack into place. Heat the pin using the iron and apply enough solder so that it flows into each via.

I ended up replacing both jacks because the replacements have a metal ring that looks more sturdy than the original.

PCB with replacement headphone jacks

Both my headphones and a microphone worked great after putting everything back together. I was initially worried that the pinout of the replacement jacks might be different than the originals but they turned out to be an exact match.

Python is the language of choice for controlling the Raspberry Pi’s GPIO pins. It seems only natural then that to interact with your Pi over the web it should run a web server able to handle Python CGI scripts. Following the steps below will get the lightweight nginx web server running on your Pi, handing Python requests off to a uwsgi helper process.

Install nginx

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx

Add a location to the /etc/nginx/sites-available/default to pass Python requests on to uwsgi. This needs to be placed inside the “server” block of the configuration, for example right after one of the existing “location” sections.

Open up your web browser and go to http://{your pi’s ip address}/hello.py
If you’re using the browser on your Pi then you could instead go to http://localhost/hello.py
If you see the message “Hello World” then everything is working.

We’re going to use the Raspberry Pi’s SPI bus to control Microchip’s MCP4151 8-bit digital potentiometer. The MCP4151 is an 8 pin SPI device that can be used to programmatically control output voltage. The GPIO pins on the pi run at 3.3 volts meaning that we can command the pot to output between 0 and 3.3 volts. However, if we instead power the pot with 5 volts then we can control a voltage between 0 and 5 volts. Note that PWM is a possible alternative to a digital pot that doesn’t require an extra chip. However, this can add noise to the signal that wasn’t acceptable for my project.

Microchip’s datasheet is recommended reading before starting this project.

Step 1: Configure SPI on the Raspberry Pi

Step 2: Wire up the components

Being a pin-limited device, the SPI input and output on the MCP4151 shares one pin. That’s not a problem in our case since we’re only interested in writing to the device.

You’ll notice that we’re powering the pot with 5 volts despite the Raspberry Pi being a 3.3 volt device. This is fine because 1) The Pi sends commands to the pot but receives nothing back. Therefore, there is no risk of overvoltage on the Pi’s pins. And 2) The pot recognizes any SPI input over 0.7 volts as a high signal. This means the 3.3 volts from the Pi is plenty to communicate with the pot.

As you can see, the power, ground and the SPI signals take up most of the pins. The actual potentiometer terminals are pins 5, 6 and 7.

Pin

Description

1

SPI chip select input

2

SPI clock input

3

SPI serial data input/output

4

Ground

5

Potentiometer terminal A

6

Potentiometer wiper terminal

7

Potentiometer terminal B

8

Positive power supply input

Step 3: Create the python script

To test out the device, we’re going to continuously loop through all the possible values for the potentiometer. This will cause the voltage at the wiper terminal grow and shrink between 0 and 5 volts. Create the following script on your Pi.

I choose to not run FTP on my server so when it comes time to upgrade WordPress, I do it manually. If, like me, you think that even the short instructions are too long, here are the even shorter instructions. These commands are done within an SSH shell on the server.

Backup your existing WordPress install and database

Download WordPress and upgrade using the below commands. Replace the directories with those specific to your system.

In the past it was a hassle to get off of my motorcycle to key in the garage door code before getting back on the cycle to pull it into the garage. Stashing a garage door opener in my jacket pocket was a little better but I still had to stop to take off my motorcycle gloves. My solution was to hack a garage door opener to activate via a switch on my handle bar. Because I do almost all of my riding in the city, I never use my passing switch so this was the one I chose to tap into. The following is a guide of how I did it and was done for a LiftMaster opener/remote. The same concepts should apply to other brands but I have not tried them.

Materials

A LiftMaster garage door remote. Make sure you get the correct remote for your opener (based on whether the learn button on your opener is red-orange or purple ). I used the remote with only one button to keep things simple.

A TO-92 (3 pin through hole) NPN transistor. I bought a pack of these from RadioShack. The specific one I used is KSP2222A but there are many equivalent part numbers that will work.

A 2.7M Ohm 1/4 watt resistor. If you can’t find this exact one, any resistor near this value should work. I bought a huge variety pack of resistors that included this one on eBay for only a few bucks.

Tools

Solder sucker or copper braid to remove the solder from the remote’s button

Something to notch the side of the remote. A dremel tool works well for this.

Step 1: Remove the Push Button Switch

If you haven’t already, don’t program your remote for your opener yet. You don’t want to accidentally be opening and closing your garage door while working on this project. Begin by opening up the case of your remote and removing the circuit board.

The remote with the case opened

You’ll see a small black and silver momentary push button switch near the bottom. Pressing down on this switch completes a circuit which activates the opener. We want to remove the switch so that we can replace it with a transistor activated by a 12V signal from the bike. Use your soldering iron and solder sucker or copper braid to remove the solder from the pins of the button.

Removing the solder from the button’s pins

After the solder is removed, the button will easily come off of the board.

Circuit board with the button removed

Step 2: Solder the transistor

Next we need to replace the button with the transistor. The transistor acts as an electronic switch. When the base of the transistor is activated by the 12 volts from the motorcycle, it will allow current to flow from the collector to the emitter. Bend up the middle lead of the transistor and insert the other two leads into the circuit board. Make sure it matches the orientation shown in the photo.

The circuit board with transistor

Then solder and trim the leads on the reverse side of the board.

The transistor leads soldered and trimmed

Step 3: Add the Resistor

Only a very small current is needed for the remote’s circuit to consider our new switch “closed.” We’re going to solder a resistor to the base of the transistor to make sure we don’t damage it when we send it 12 volts from the motorcycle. Clip the leads short on the resistor and solder it to the remaining transistor lead.

Ready to solder the resistor with a helping hand.

Step 4: Solder signal and ground wires

Cut a couple feet of red and black wire and strip the ends. Solder one end of the red wire to the end of the resistor. Solder one end of the black wire to the circuit board as shown.

The Modified LiftMaster PCB

Step 5: Modify the case

You’ll need to cut a couple notches into the garage door opener’s case where the wires will come out. I believe I used a dremel tool for this. When you’re done, thread the wires through the notches, and snap the circuit board back into its case.

The notched opener case.

With the modifications to the LiftMaster garage door opener complete, it’s ready to install on the motorcycle.

Step 6: Program and test the remote

For this step you need access to a 12 volt power source–the terminals of your motorcycle’s battery will work in a pinch. To program the remote, tap the orange or purple learn button on your opener then hold the red wire to the positive terminal on the battery and the black wire to the negative terminal for a few seconds. Your garage door light should blink when the programming is complete.

Now disconnect the remote then connect it once more. If your garage door activates, it’s working!

Step 7: Install opener on motorcycle

This is where you get to be a bit creative. I chose to tap the red signal wire into the high beam wire on my SV650, allowing me to use my passing signal to trigger the garage door opener. To do this, I made a small cut to get into the wire bundle near my steering column then used the posi-tap connector to make the connection. I then wrapped the bundle back up with electrical tape. You can either connect the ground to a ground wire on your motorcycle or to any metal part of the frame. I chose to screw it down using the screws holding down my gas tank.

Finally, you’ll need a place to stash the remote. On my SV650, I found that there was extra space underneath my gas tank in front of the airbox.

I forgot to take pictures of this step but if you think it’d be helpful let me know and I’ll post some. Have fun and enjoy your motorcycle’s new garage door opening abilities!

A while back I wrote about how to perform incremental backups via rsync to an Amazon EC2 instance. The script worked great when run manually from a Python interpreter but I always ran into issues when trying to automate the script via cron. I finally took some time to hammer out all of the automation issues and fixed some other bugs along the way. With the new fixes in place, I now have my VPS automatically backed up nightly via cron, all for about $1/month!

For the backup script including the latest updates, take a look at my Backup to AWS EBS via Rsync and Boto how-to. I’ve documented the problems encountered and how I fixed them below.

Preserve File Ownership in the Backup

I learned that the remote rsync process must run as root in order to preserve file ownership. This is accomplished by adding –rsync-path=”sudo rsync” to the rsync command. However, EC2’s Amazon Linux AMI does not allow this by default because it requires a tty (terminal) to run a sudo command. The solution was to add a line to the script that ssh’s into the EC2 instance, forces allocation of a pseudo-tty, then appends “Defaults !requiretty” to /etc/sudoers.

Maintain Proper Directory Structure in the Backup

Another issue I discovered was that my backup was getting created with directories like /home/home/username/ instead of /home/username/. The solution to this was to simply ensure that all of my rsync destinations contained a final trailing slash.

Connection Denied for SSH

This was the error I saw that was preventing me from running the script via cron. Putting the script to sleep for 60 seconds after attaching the volume fixed this.

Terminate the EC2 Instance when Finished

The original script stopped the EC2 instance rather than terminating it. The EC2 instance is only needed for the rsync after which it should be terminated in order to avoid extra fees from AWS! The backed up data will remain on the detached EBS volume even after the instance is terminated.

Update 11/2015:

Updated the script to use boto3 and waiters

Switched to use the t2.micro instance type with VPC

More detailed setup instructions

Overview

Amazon Web Services Elastic Block Storage provides cheap, reliable storage—perfect for backups. The idea is to temporarily spin up an EC2 instance, attach your EBS volume to it and upload your files. Transferring the data via rsync allows for incremental backups which is very fast and reduces costs. Once the backup is complete, the EC2 instance is terminated. The whole process can be repeated as often as needed by attaching a new EC2 instance to the same EBS volume. I backup 12 GB from my own server weekly using this method. The backup takes about 5 minutes and my monthly bill from Amazon is around $1.

You create an EBS volume in your preferred zone (location). Make sure it is large enough to store your backups.

Create Your Access Key and Key Pair

Create an Amazon EC2 key pair. You need this to connect to your EC2 instance after launching it. Download the private key and store in on your system. In my example, I have the private key stored at /home/takaitra/.ec2/takaitra-aws-key.pem
Also create an access key (access key ID and secret access key) for either your root AWS account or an IAM user that has access to create instances. Make sure to save your secret key somewhere safe as you’ll only be able to download it once after creating it. I had problems using a key that had special characters (=, +, -, /, etc) so you may want to regenerate your key if it has these in it.

The Script

The below script automates the entire backup process via Boto (A Python interface to AWS). Make sure to configure the VOLUME_ID, SUBNET and BACKUP_DIRS variables with your own values. Also update SSH_OPTS to point to the private key of your EC2 key pair.

A common requirement for a Java web application is that it be able to send e-mail in response to certain events. A couple simple examples of this requirement are a web form that sends a confirmation e-mail to the user and sending automated messages when exceptions occur. These e-mails must often incorporate dynamic content. In the web form example, content from the form submission could be included in the confirmation e-mail.

VelocityEmail extends the Email class from Commons Email to provide an elegant solution to this problem. The simplicity of Commons Email makes constructing and sending the e-mail a breeze while Velocity templates allow the content to be completely flexible and dynamic. The most important benefit of this approach is that it allows separation of the e-mail content from the project code, greatly increasing maintainability.

Download

How to Use VelocityEmail

Create HTML and/or plaintext Velocity templates for your email. By
default, you can reference any fields of your soon-to-be merged javabean
like $bean.fieldName. Place the templates in your project’s source folder or
wherever they’ll be available on the classpath.

Create an instance of VelocityEmail, passing the the template filename to
the constructor and initialize it as you would normally initialize an
HtmlEmail.