Sunday, January 2, 2011

Android Wii Balance Board Scale (WiiScale)

I recently published a new application to the Android market. This application is called WiiScale. The application utilizes the Wii Balance Board to sync with a supported Android device, and display the weight to the user, in short, it allows the Wii Balance Board to be used as a scale with your Android device. The purpose of this post is to show how another external Android application can integrate with the WiiScale application using Intents. I have provided a sample Android application that contains all of the functionality outlined in this that can be used as a reference or starting point if necessary. The source can be found on github.

It is actually very straightforward to create and call an Intent to request the users weight from WiiScale. The following code will do a few things. It will first call a method to check if the required intent for WiiScale is available on the users phone. If the intent is available it calls the intent, if it is not, it directs the user to the Android market to download the application.


The uri is specific uri defined by the WiiScale application for receiving intents. The unit parameter can have two values. The valid values are 'lbs' or 'kg' depending on whether your application would like the weight in pounds or kilograms. The WEIGHT_REQUEST variable is just a static Integer datatype to uniquely identify the intent when we get the result back. Note the call to 'startActivityForResult', this will allow your application to get a result back in the onActivityResult method. This method looks like the following.



This simply checks to make sure the activity result if for our WEIGHT_REQUEST from WiiScale intent call, and that it returned successfully. WiiScale returns two values from the intent. The unit of measure, either 'kg' or 'lbs' and the weight in the given unit measurement. Your application can then use this data as you please. It couldn't be simpler to integrate WiiScale into your own application. Please see the source on github for for details as well as how to check if the intent is available on your phone.

37 comments:

Unknown said...

Fantastic! I was looking for an app like this a few months ago and was disappointed to find nothing. After beginning to play with the Android SDK the thought of writing my own came into my mind. This morning a quick google search has found me this app and I no longer need to. Thanks!!

Unknown said...

@driedger hope you can find it useful. If you do end up using it I would be interested to know how you are doing so.

The Consumer said...

I'm unable to sync the balance board with this app. I'm using a HTC EVO 4g (sprint) nowhere in the app do I see any way of syncing the phone to the balance board.
if I go into the phone's bluetooth utility and do a manual search for devices, the balance board appears, but it asks for a passcode and I don't know what to enter. I've tried the standard "0000" and "1234" both to no avail. Are you aware of this issue occurring with other devices?

Unknown said...

@Consumer, the pairing of the board to the phone is done through the application, there is no need to pair it as a normal bluetooth device, as the balance board does not need a passcode. However your phone will not work with this application. Your phone uses HTC SenseUI which unfortunately HTC has used an older bluetooth stack with that does not support HID. You will either need to contact HTC about and upgrade, or if your phone is rooted you could try a ROM that supports HID such as Cyanogen, and then it should work.

Unknown said...

Hi broschb,
I'm interested in your BalanceBoard reader.
I tried writing my own but I have an un-rooted HTC Desire, therefore no BT so could not test it.
Have you posted the code anywhere for the BT communication part of the app?
My app would need to read the values from all 4 sensors of the board, not just the weight.
I'm thinking about getting on of the ZTE Blade / SanFran phones to test this out. Do you know if this phone implements the full HID BT stack?

Unknown said...

@edamreed thanks for your interest in the app. At this time I have not published my source for the bluetooth communication. I am also not sure if the other phone you mentioned includes a working HID bluetooth stack.

Unknown said...

Any tips for the BT communication between the phone and board?

I started out reading the BluetoothChatService example from the android site.

Is it just a case of polling the BluetoothSocket and working out what the data means?

Unknown said...

@edamreed, it is a little more complex than that. Unfortunately the bluetooth api as it is in 2.1, 2.2, does not support this functionality. It may change in newer releases. In order to get this working I had to use the NDK and compile a native binary against the bluetooth drivers provided in the android source.

Unknown said...

Hello,
I just tried wiiscale and it worked well. However, I had to press the red button on the board every time for sync to work. Any chance you could get a permanent pairing implemented?

Markus Wahl said...

i wanted to do this myself, with my own app, have infact tried it this whole weekend. and I did only read your comments now that I have given up (or nearly given up anyway). my phone is HTC Desire HD with Android 2.2.1. so if I understand it correctly it could work if I root my phone in order to install the cyanogenmod. thing is, i use my phone for so many things and i am quite happy with the htcsense that i am a bit hessitant to that big undertaking.

but you seem to be quite the expert. aren't there any other way around that enables me to write my own app? i'm thinking, why cant I just add HID support to the phone without replacing htc sense?

i am curious as to what you mean with the NDK thingy you wrote about. is that what you did give give your phone HID supprt, as opposed to use the cyanogen mod?

it should be obvious to you that I am a bluetooth noob...

am quite curious to the contents of your implementation.... :)

Unknown said...

@ToxicAvenger, First thanks for your interest in my application. I am somewhat of a bluetooth newb newb myself, but have picked some things up as I have hacked away at it. From my understanding the problem w/ HTC SenseUI and the bluetooth drivers has to do w/ the bluetooth implementation HTC chose to implement. This has more to do w/ them using an older Android implementation(1.6) and not upgrading to the latest due to conflicts w/ the SenseUI. The NDK is the (native development kit)http://developer.android.com/sdk/ndk/index.html, and is required to compile native code. The WiiScale application communicates over bluetooth using jndi via ndk. The SenseUI phones do not include the necessary functions at the NDK(C) level to support the required functionality. It would probably be possible to write the necessary code/libraries and include them in the application at the NDK level, but I don't have the time to investigate in that depth.

Unknown said...

Hi. Great app but I have a question. I have a nexus one. I can sync but cannot get phone to see my weight when I stand on the board. App says it has sync. I am running gingerbread official update.

Thanks

Unknown said...

@Kimiko, are you using the app from the market, or the sample app outlined in this blog post on github that uses the intent?

Also if you could send the error log it would give me more info as to your exact problem. You can get applications on the market to email a log file.

Thanks for your interest in my app!

Unknown said...

Excellent App - hoping one day Cardiotrainer would use the same facility.

One question - is the only way to connect the balance board through the red connect button in the battery bay? I can't seem to link the board to my tablet by pressing the large button (always have to flip the board and press the red button - which is kinda inconvenient as the connection isn't maintained when the app shuts.)

Unknown said...

@Yasin, yes currently the only way to sync is by pressing the red sync button on the bottom. I am currently working on getting permanent pairing working.

Asa said...

I don't seem to be able to sync with my balance board using my G2x running 2.2.2. Is there a way I can tell if the bluetooth stack isn't compatible? When I press the sync button it flashes a message on my screen that it's trying to syn with the board, but it flashes too fast to read. I had to press the button several times in a row to attempt to read the message.

Nori said...

I'm unable to launch wiiscale intents from my application. WiiScaleTest doesn't work, too. Previous version of wiiscale is OK.

calimero100582 said...

Nice app

Permanent sync will be awesome

2 ideas: automatically record weight when stable for 5 seconds, allow multiple users (record weight for the user in a 5% range, if more than one user, popup selection window)

dimitri said...

Thanks for making this app! I use it in combination with my HTC Desire running Miui, it works great.
However google health is going to stop in 2012, are you planning on adding support for another website to upload data to?
Maybe Runkeeper with it's health graph api would be a good option?

Unknown said...

@dimitri those are great ideas, and I can work on implementing them. I have already started some work on runkeeper integration. I'll take a look at the others. Let me know if you have any other ideas as well.

Wereni.com said...

Thank you very much for your kind offering Wiiscale apps. My theis is about this, so would you mind explaining for me more about how to use Android Buletooth API? Or...Is it that what I can to is just use NDK to develop it?

Wereni.com said...

Thank you very much for your kind offering Wiiscale apps. My theis is about this, so would you mind explaining for me more about how to use Android Buletooth API? Or...Is it that what I can to is just use NDK to develop it?

哈利 said...

Thank you for providing the code.
I found a bug, the above code with WiiScale version 1.4 can be used normally, but WiiScale version 1.8 click "get weight" will cause an exception.

dimitri said...

Really cool you added the Runkeeper support. However when I press the "Click to install plugins."-button, I get an error the requested item cannot be found. Can you maybe look into this?

Unknown said...

@dimitri, Can you send me the log? It works on all the devices I have tested it on. There are applications in the market that can pull/send log files.

The MK said...

Very nice app. I'm attempting a project which involves Android-Balance Board pairing, and have run into issues with bluecove. Are you using motej or did you build your own balance board library?

dimitri said...

Here you can find my device log:
https://docs.google.com/document/d/1fX-9bYLIqquYccxHbQhHWswvlwhKGdtvxXa4v4W5IQM/edit

Unknown said...

@dimitri,

I can see the call being made to request the extensions. Here it is in the log.

11-07 16:38:48.654 I/ActivityManager( 144): Starting: Intent { act=android.intent.action.VIEW dat=market://details?id=com.broschb.wiiscale.api cmp=com.android.vending/.AssetInfoActivity } from pid 17130

This tries to make a call to the android market, do you have the android market installed on your device?

dimitri said...

I do have Android Market installed. Somehow it just doesn't find the plugin. Is there some other way to get the .apk file?

Unknown said...

@dimitri,

You can find it on the market here(https://market.android.com/details?id=com.broschb.wiiscale.api) or search for wii scale extensions

David B said...

Seems to be a great app but I cannot get it to work with my rooted Moto A855. It sysnc's to the balance board but dosnt register a weight or anything else after that point. Any ideas?

Kim said...

is it just me or is there no way to delete an entry? Somehow the phone was too sensitive and accepted a couple 0lb entries.

Unknown said...

It would be great if this with sync with my Fitness Pal

hatboyzero said...

Are there any other intent actions available other than the com.broschb.action.WEIGH action - for example, if I were interested in the weight measurements from each of the four independent scales? Additionally, did you ever manage to get the permanent pairing between the balance board and the Android device working? Thanks in advance :)

Unknown said...

@hatboyzero, currently there are no other intents available, i have also not had the time recently to work on updating the pairing of the device to the board. I may be revitalizing parts of the application for a new project, if so this app will surely see some trickle down, so keep your eyes open.

Potato said...

Hi,
i really would love to use yout application but it does not sync to my board with my nexus 4 running cyanogenmod 10.1, any suggestions?
thanks so far :)

Tom said...

Do you have any plans to get this working with KitKat? Specifically.. Cyanogen 11