From the category archives:

Gadgets/Hack

In this post you’ll learn how to make a working Bluetooth weight sensor + fast real-time graphical display with about 200 lines of Python code. You can code any Nintendo Wii-like video game for Ubuntu/Linux and the Nintendo Balance Board very easily. Here’s a video demonstration:

This post assumes that you can already communicate with a Wiimote on Linux. See my earlier post if you haven’t done that.

You’ll need Subversion and autoconf installed if you haven’t already installed it. I think the official/full list of packages to install is

sudo apt-get install autoconf autogen automake gcc bluetooth libbluetooth2-dev libgtk2.0-dev pkg-config python2.5-dev flex bison subversion

You must also install the development package for BlueZ, which is the official Linux Bluetooth protocol stack:

sudo apt-get install libbluetooth-dev

Make a directory to hold your code:

mkdir ~/wiibalance
cd ~/wiibalance

Check out the CWiid (get it? CWiid? Seaweed?) library using Subversion:

svn co http://abstrakraft.org/cwiid/svn/

When I checked CWiid out, it was up to version 183.

Compile the library, e.g.

cd ~/wiibalance/svn/trunk
autoconf
./configure --libdir=/usr/lib (according to this page, you need the libdir parameter on Ubuntu)
make
sudo make install

Now apply the patch to CWiid to add the Balance board. Go to http://abstrakraft.org/cwiid/ticket/63, click on balance.diff, then at the bottom of the resulting page, click on “Original Format” to download the diff as a raw text file. Do the same to download the “weighdemo.py” file. Now apply the balance.diff patch:

patch --dry-run -b -p0 < balance.diff (this command tests that everything would apply without errors)
patch -b -p0 < balance.diff

Finally, compile the code and install it:

make
sudo make install

Then you can play with the weighdemo.py script. You’ll want to change the line “sys.path.insert(0, ‘/home/tbble/code/cwiid/svn/cwiid/python/build/lib.linux-x86
_64-2.5/’)” to point to the right place on your system, e.g. /home/youraccountname/wiibalance/svn/trunk/python/build/lib.linux-i686-2.5/ . And you may need to disable the “if wiimote.state['ext_type'] != cwiid.EXT_BALANCE” if statement. I also added a few lines to print out the values and calibration numbers for the four sensors. Here’s what I get when I run my program:

$ ./weighdemo.py
Put Wiimote in discoverable mode now (press 1+2)…
Type q to quit, or anything else to report your weight

right_top 2249 [2293, 4004, 5725]
right_bottom 1467 [1449, 3155, 4874]
left_top 12471 [12476, 14238, 16015]
left_bottom 6822 [6848, 8581, 10325]
-0.58kg
Type q to quit, or anything else to report your weight

right_top 3618 [2293, 4004, 5725]
right_bottom 3983 [1449, 3155, 4874]
left_top 14208 [12476, 14238, 16015]
left_bottom 9621 [6848, 8581, 10325]
82.18kg

In this run, the first example is weighing with nothing on the scale. The second example is with me standing on the scale.

Here’s what you need to know. First, absorb this info from the Wikipedia entry:

Although the Japanese packaging states that it is designed to support people weighing up to 136 kilograms (300 pounds) and the “Western” Balance Board up to 150 kg (330 pounds), they are actually the same board. The packaging differs due to laws in Japan and other nations regarding weights and measures. While the board only displays weight readings up to what is printed on the packaging, the actual physical structure of the board can withstand much greater force equivalent to around 300 kg (660 pounds).

Okay, so the Wii Balance Board is certified for 300 pounds (136 kg) in Japan and 330 pounds (150 kg) in the U.S. The Wii Balance Board has four sensors, so each sensor is certified for up to 136 kg / 4 = 34 kg per sensor in Japan or 150 kg / 4 = 37.5kg per sensor in the United States. Now that you’ve been schooled on that, the following Wii Balance Board calibration information from WiiBrew will make more sense.

Each sensor returns 2 bytes of data and also has six bytes of calibration data. Think of it as a 16 bit number and three calibration numbers, that are also 16 bits apiece. The three calibration numbers correspond to the sensor reading for 0 kg, 17 kg, and 34 kg (those numbers should look familiar if you look at the previous paragraph). So if sensor #1 gives a value of 5725 and the 34 kg number is also 5725, then that sensor is reporting exactly 34 kg of weight on it.

The WiiBrew page says “Calculating the weight on each sensor simply involves interpolating between the two calibration values your reading falls between (or using the higher two values if your reading exceeds the highest calibration value), and the total weight on the board is the sum of these [four sensor] values.”

With that info, let’s go back to one of my sensor readings and convert it to actual kg. Take the reading “right_top 3618 [2293, 4004, 5725]“. The sensor value is 3618, which is between the 0 kg calibration number of 2293 and the 17 kg calibration number of 4004. So the weight on the right_top sensor is 17kg * (3618-2293)/(4004-2293) or 17kg * 0.7744 or 13.2 kg. I tend to put my weight on the back of my feet, which is why 13.2 kg is a little lower than my total weight (82 kg) divided by the four sensors, which would be 20.5 kg per sensor.

If your eyes haven’t completely glazed over, the upshot is that the Balance Board has four independent weight sensors, each calibrated to kilograms, and you can read those sensors in real-time over Bluetooth. Translating the sensor values into weight only takes four lines of Python code. From there, you can do anything you want with that data. Play a game, hook your Wii Balance Board up to Google Earth, or you can even automatically upload your weight to a Google Spreadsheet.

For example, you can run the command “sudo apt-get install python-pygame” to install pygame. Then go back to this page and download the scalesgui.py and system.ini files as you did before (click on them, then click on “Original Format” at the bottom of the resulting page). Make scalesgui.py executable with “chmod a+x scalesgui.py” and comment out the “EXT_BALANCE” if statement, then run “./scalesgui.py” and this is what you’ll see:

Scalesgui program

This is a snapshot, but the program runs just as fast as any video game. You can lean and move the circle around really fast. And in the bottom right, you can see that I weigh 81.74 kg, which is about 180 pounds.

I know this is a long post, but the upshot is that with 10-15 minutes of work, you can use a Wii Balance Board as a real-time sensor with Linux. I hope you have fun!

{ 31 comments }

A while ago I wrote about Synergy and showed a picture of my desktop as of July 2007:

My desktop in July 2007

That’s two 24″ Dell monitors (one for a Windows computer, the other for a Linux computer). I’ve had that setup for a couple years and I recently decided it was time to upgrade. So I bought a 30″ Dell UltraSharp 3008WFP monitor. Now my desktop looks like this:

My desktop in April 2009

The two left monitors are Windows XP, the right monitor is Ubuntu. From left to right, I have seven browsers open showing my blog, the Google webmaster blog, Techmeme, Friendfeed, Twitter, Google News, and the Google homepage. I love how much screen real estate this setup gives me (a little over 8.7 million pixels).

{ 79 comments }

Recently I treated myself to a solid-state drive (SSD). That’s essentially a hard-drive made out of memory chips. I bought the Intel X25-E Extreme, which uses faster single-level cell (SLC) memory chips instead of slower multi-level cell (MLC) memory chips.

I wanted to put the drive through its paces, so I decided to see how fast I could boot Ubuntu and start Firefox. It turns out that Ubuntu 9.04, code-named Jaunty Jackalope, is just a few days away, and one of the features listed is “significantly improved boot performance.” Perfect! I installed Ubuntu 8.10 from a CD and then followed the incredibly easy instructions to upgrade to the beta of 9.04.

So how fast did Ubuntu 9.04 boot with a solid-state drive? Really freaking fast. Like, “I can’t believe it’s already done” fast. Well, here, watch for yourself:

Total boot time from pressing power to Firefox loaded was about 22.5 seconds, with about 5 seconds of BIOS display on a Thinkpad. Subtracting out the Thinkpad BIOS display time, that means that Ubuntu 9.04 booted into Firefox in about 17.5 seconds. I think I’m going to have a lot of fun with this hard drive. Oh, and Ubuntu 9.04 looks really interesting too. :)

For the folks that are curious, I changed the GRUB boot loader time out from three seconds to zero, enabled automatic login to my account, then I added Firefox to default list of startup services.

Added: I collected a couple boot charts by using bootchart. As Ryan said in a comment, I ran sudo apt-get install pybootchartgui bootchart , then rebooted, then collected the image in /var/log/bootchart . If I’m reading the images correctly, it’s claiming 8.67 seconds for one boot-up and 8.69 seconds for the other boot-up.

Added: Okay, I reinstalled Ubuntu 9.04 so I could use ext4 and it shaved almost a second off the boot time! Check out this image which shows a 7.83 second boot time. :)

{ 78 comments }

Google sometimes turns off features. One such feature that I remember fondly is that at the bottom of Google’s search results, we offered nine other search engine suggestions. The idea was if you didn’t find what you were searching for on Google, you could click on the other links and easily run the same search somewhere else. Luckily, due to an April Fool’s joke about the Mentalplex, you can still see what these links looked like:

Other search engines in 2000

Many of these search engines consolidated or changed focus over time. Plus I’m guessing that every search engine in the world wanted to be on the list, which must have been really annoying for whichever Google person had to maintain that list of links. I think the list of other search engines dwindled down and eventually Google just turned the feature off.

Recently I was describing this feature to Tiffany Lane, another engineer at Google, and she had a great idea. Why not recreate this search feature on Google with modern search engines and websites? Because of the pain of maintaining an “official” list, we probably couldn’t turn this on for every user (plus not every user wants a lot of extra links added to their search results). But why not provide a completely unofficial option that people could install?

Thus was born Retro Links, which is a Greasemonkey script to add new search options to Google’s search results page. When Retro Links is installed, it looks like this:

Retro Links

Unlike the original feature, Retro Links lets you select which search engines to show from 42 different websites and search engines, then saves those preferences. It’s also very easy to add a new search engine in the JavaScript file.

Installation

Get Retro Links here: http://www.mattcutts.com/retrolinks/retrolinks.user.js

To install Retro Links you will need to be using Firefox and have Greasemonkey installed. Once Greasemonkey is running then you can click on the link above and you will be prompted to install the script. To see that it is working you can do a Google search – the links will be inserted near the bottom of the Google search results page.

Configuration

Configuring Retro Links is really simple. Suppose that you want to change the default Amazon link to search on Yelp. Just click on the [+] link to the right of the search engines and select Yelp from the drop-down box:

Changing search engines in Retro Links

When you’re happy with your search engines, click the “Save” button to save your preferences.

Questions

What if the site I want is not one of the 42 options?
You can add more sites to the options by making a simple code change. To edit the code go to Tools -> Greasemonkey -> Manage User Scripts, select Retro Links and click the Edit button. Simply add the name and url of the new site to the RL_LINK_OPTIONS array, following the examples that are already there.

How do I turn on/off the update notification?
The script checks to see if a newer version is available once per day. If an update is available a red box will appear in the bottom right corner of the page with a link to download the latest version. If you want to stop checking for updates go to Tools -> Greasemonkey -> User Script Commands and select Retro Links -> Never check for updates. To start checking again select Retro Links -> Check for updates daily.

Disclaimer

Finally, Tiffany wanted to make sure that I included this quick disclaimer: “Retro Links is not an official Google project. I chose which links to include based on my personal preferences and web surfing habits. These decisions do not represent the opinions of my employer.” Tiffany, thanks for writing this great script!

{ 30 comments }

I bought a Drobo about a year ago. Recently I got this pop-up window:

DroboCare warranty service by Drobo

Wait a second — I bought this storage device, and now want me to extend my license “to continue to receive the latest updates”? If you go to the url mentioned in the pop-up, you see that for $49 for a year’s coverage, you get

Continued access to software updates to Drobo Dashboard, Drobo Firmware and DroboShare Firmware including performance enhancements and new features.

Both the program pop-up and the web page imply that I need to pay $49 to continue to get firmware updates. That’s extremely uncool. The ironic part is that apparently Drobo changed their mind in February and they won’t make you pay for firmware updates now. It’s been a month; why does the DroboCare web page still imply that you have to pay $49/year for firmware updates? They need to fix that ASAP, because people appear to be confused by the language.

Let me tell you a little story: back in the 90s, before eBay existed, I was a poor college student who wanted to connect a CD recorder to his computer. I bought a used Adaptec SCSI card over Usenet. When the SCSI card arrived, the four floppy disks of driver software were scrambled. When I tried to get drivers from Adaptec, I learned that Adaptec charged for the drivers for that SCSI card. I never bought another Adaptec product again. The End.

So I don’t plan to buy any more Drobos in the future. Why would I buy from a company that tried to charge me for firmware updates for my consumer hardware? Sure, Drobo changed their mind after people complained, but the fact that Drobo even considered it will make me avoid them in the future.

Update: read this blog comment by Jillian Mansolf from Drobo. Evidently Drobo’s Sarbanes-Oxley auditors classified Drobo as a software company. The auditors “wanted us to recognize revenue for Drobo over the ‘life’ of the warranty (forever) if we included performance enhancements through free software updates.” DroboCare only pertains to hardware as of January, so a future version of the DroboDashboard software will remove this pop-up. Read the comment for more about this from Drobo.

{ 35 comments }