I’m back!

I should be back over at mattcutts.com. I’m sure some bits have sloshed around in the transition from dullest.com to mattcutts.com–let me know if you see anything truly weird.

I plan to talk sometime soon about what I learned in the process of moving to a completely different domain for a month.

Use a Wii Balance Board with Linux

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
./configure --libdir=/usr/lib (according to this page, you need the libdir parameter on Ubuntu)
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:

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]
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]

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!

What you should do next week

Next week is going to be a humdinger. If you’re in the Bay Area, here’s what I think you should do:

- Attend Google I/O. If you’re a developer, trust me, I think you’ll get something out of the conference. Just check out the list of sessions, for one thing. The price is $400, but if you have a student ID the price is only $50. Need an extra incentive? I’ll be doing a site review session so you can tell your website and get a review and advice about your site. I plan to bring along several smart folks from my team to help on the panel. I really think this conference will be worth your while.

- Is $400 (or even the $50 student rate) too much to pay? Then come to WordCamp 2009 in San Francisco on Saturday, May 30, 2009. It costs $25 that includes a T-shirt and lunch. I’ll be speaking at WordCamp as well.

- Maker Faire is next weekend (May 30 & 31st). I love Maker Faire, so I’ll be there to soak up the fun. If you’re a geek in the Bay Area, you don’t want to miss Maker Faire–again, trust me on this.

Bonus recommendation: If you’re willing to look two weeks out instead of one week, SMX Advanced will be in Seattle on June 2-3, 2009. I think there’s only ~50 tickets left, so I’d sign up soon. I’ll be there and I’m really looking forward to it. Danny Sullivan will repeat our You & A session where both Danny and the audience ask me questions.

I think each of these events should kick butt in slightly different ways, so I hope you can make it to some of them. If you can make it and you see me, walk up to say hello and chat a little bit! :)

Letter to a young journalist

Don’t conclude from my previous post that I dislike journalism. All through middle and high school I woke up early to read the local newspaper each morning. I was the editor of our newspaper in high school. My mother wanted me to be a journalist. I’ve been thinking of the issues confronting journalism for a few years now.

Back in early 2007, a journalist friend in the Midwest emailed me. He saw the impact of the web, changes in the newspaper industry, and he was worried about his newspaper’s–and his own–future. He asked my opinion on all of this. With his permission, this is what I wrote to him back in 2007 with a few minor edits.

Definitely take me with a large grain of salt–I got lucky in joining Google, but I wouldn’t give my opinions any more weight than an average person’s. :) My personal hunch is that newspapers will have some issues in the years to come. If you think about the fraction of revenue that comes from classified ads, it does seem that revenue will eventually migrate online, and sites like craigslist.org are more likely to capture a big fraction of that traffic compared to individual newspapers or even newspaper syndicates. If a newspaper loses ~30% of classified ad revenue over 5-10 years, that’s really hard to adjust to without structural change.

It’s funny because my Dad basically took a job out of grad school and stayed in the same post until he retired. It seems like the odds of that happening for people like you and me are a lot lower. There’s just not as many companies that are doing things like taking care of their workers for 30 years at a time.

So the first thing I’d recommend is to grab a domain name and work on burnishing your personal reputation online. It’s definitely not the case that everyone needs a blog, but having one place that acts as a face to the world can really help. There’s room for a resume/CV, but also for some writing samples that show off your abilities.

Which takes me to how open-minded [Midwest newspaper] is. I’ve heard newspaper policies ranging from “If you blog, we’ll fire you” to “If you don’t blog, we’ll fire you.” I hope that the paper is pretty open-minded. But they shouldn’t be able to stop you from building up your reputation online in your own time, and even if there’s copyright issues with putting full articles up on your personal site, you could no doubt quote a few excerpts of choice stuff as a part of fair use.

So making the switch to a mental model where you are more like a consultant for any company that you work for, but you look for ways to improve your reputation and learn new skills as you go–that’s a good way to make sure that you’re protected if you unexpectedly end up as a free-agent.

You’ve got a good sense of humor and you’re well-spoken, so the biggest questions to me would be
- what do you love or what are you interested in?
- where do you want to be in 5-10 years?

For example, it would be interesting to know a little bit about your interests. Things like games, gadgets, politics, or technology make great subjects if you want to try some active blogging + something like AdSense to make a little bit of money on the side. But some of the larger issues are things like
- how introverted you are vs. how much you enjoy talking to people.
- what ties do you have to [Midwest city], and do you want to stay around there or are you willing to move?

I’ve noticed that networking and getting to know a few people in an industry can make a big difference. If the tech-field is interesting to you, [Midwest city] is going to be a more limited pool of opportunities compared to something like Silicon Valley/San Francisco or New York. If you like to travel and like meeting new people, it turns out that becoming an expert in a niche and then getting on a conference speaker circuit can be good. You might start out on panels about journalism or media or ethics, but that could quickly lead to consulting gigs, for example.

I do think that the tech industry will be a leading one for the next 10-20 years, and probably biotechnology will start to emerge after that. But I think the service economy will remain strong throughout. Starting to get on a conference speaking circuit is really a way to rebrand yourself as an expert on some topics. That role would let you expand and offer your services/advice in different ways.

I guess the larger issue is that working for a salary is great, but if you can find ways to participate more directly in the success of a company, that can be a faster way to make money. The whole dot com boom demonstrated that there are a lot of dumb start-ups out there, but at the same time, when you’re young is exactly the right time to take risks like that.

Re-reading your email, I guess the smallest step forward would be to find out what you can legally do online that wouldn’t conflict with your employer’s guidelines. Then I’d just try a few experiments. It doesn’t cost much to buy a domain name, so you might consider starting a blog about [Midwest city] or a news site (probably the blog is a little easier to start). Set aside $100 or so (or ask for someone to register a domain for you as a birthday present) and try a few things. Sign up for AdSense and see what sort of articles do well on places like techmeme.com or reddit.com or digg.com. In general, I’ve found that starting with a small niche and building your way up is great practice and teaches you a ton about what sort of things attract attention and good discussion.

Some of that advice has aged well, some less so. I still think that grabbing a domain and experimenting is invaluable. I believe that the entire world is being digitized–from businesses and places to people–and it’s better to be involved in that process than to stand passively and let other people define you online. I believe that participating in the upside of a company is better than only drawing a salary. And I think that most of the time, no one cares about your career ladder or skills development as much as you do. No good company opposes the development of its employees, but ultimately you have to take the initiative and drive your career in the direction you want.

By the way, the title of this post is an allusion to Letters to a Young Journalist, an excellent book by Samuel G. Freedman.

Recent piece by Sanford and Brown

(I work for Google, but this is my personal opinion.)

Last week I was on vacation down in Florida and I had a chance to tour Thomas Edison’s winter vacation home. The tour guide told us that Edison wired his house and switched on electrical lighting in 1887. Then the tour guide leaned in and quietly mentioned that it took 11 years to install lights in the rest of the town. Why so long? Because the townspeople were worried that cows would stop giving milk.

For some reason, I was reminded of that anecdote as I read a recent piece in the Washington Post. Rarely do I pause in the middle of reading an article and think to myself, “Wow, I disagree with almost everything that person is saying,” but that’s what I found myself doing. Luckily you don’t need me to marshal counterpoints. Instead, I suggest that you read what Jeff Jarvis wrote, or what Mike Masnick wrote, or what the Markos Moulitsas wrote, or what Danny Sullivan wrote. Or read Timothy Karr’s post about the authors’ undisclosed potential conflicts of interest.

I believe good journalism is critically important to a well-functioning society. I love newspapers, magazines, and the journalists that they support. But I disagree with Bruce Sanford and Bruce Brown, and reading their piece reminded me of those townspeople sitting in the dark, afraid to switch on their electric lights.