Are you tired of staring at that stupid, soulless, bearer of bad news bathroom scale every morning? Good news: The gurus at Initial State, the data analytics for the Internet of Things company, came up with a hackable, weight-tracking, text messaging bathroom scale that comes with a built-in sense of humor.
This is a fun, easy project that combines a Wii balance board, a Raspberry Pi, and an online data analytics platform to create a web-connected scale controlled by a Python script you can hack.
Project level: Beginner Approximate time to complete: 20 minutes
In this step-by-step tutorial, you will:
Here is a list of all the equipment that we will be using in this tutorial with links to where you can purchase each item.
*If you have a Raspberry Pi 1 or 2, you will need a bluetooth adapter (example: http://www.amazon.com/gp/product/B00JN5Y5E0).
Why a Wii Balance Board? It turns out that it is a really nice, durable scale that has bluetooth connectivity. This will allow us to connect it to a single-board computer (Raspberry Pi) to read your weight in a Python script and send those measurements to an online data service to do cool stuff. Plus, there is a good chance that you or someone you know already has one that is simply collecting dust.
We will need to make a couple of simple modifications to our Wii Balance Board to really make this project practical and convenient.
The Raspberry Pi 3 comes with bluetooth built on-board, all we need to communicate with the Wii Balance Board. If you have a Raspberry Pi 1 or 2, we will have to use one of our USB ports to plug in an adapter such as this inexpensive iAnder USB Bluetooth 4.0 Low Energy Adapter.
Power on your Pi (I am assuming you have already installed Raspbian and it boots up) and go to your Raspberry Pi terminal window. You can see the address of your bluetooth dongle with the
"hcitool dev" command: $ hcitool dev
Install the bluetooth modules that we will be using in our Python scripts:
$ sudo apt-get install python-bluetooth
It is time to connect our Wii Balance Board to our Raspberry Pi. We will do this by modifying a version of Stavros Korokithakis' Gr8W8Upd8M8.py script. The python script we will be using for this step is located here. You can copy the contents of this file to a file you create on your Raspberry Pi or you can clone all of the python files we will be using for this entire project. Let's do the latter. Type the following commands into a terminal on your Raspberry Pi:
$ cd ~
$ git clone https://github.com/InitialState/smart-scale.git
cloning into 'smart-scale'...
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 14 (delta 1), reused 8 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
Checking connectivity... done.
You should see two python files in the new smart-scale directory - smartscale.py and wiiboard_test.py.
$ cd smart-scale
README.md smartscale.py wiiboard_test.py
Run the wiiboard_test.py script to test communication and take weight readings from the Wii Balance Board:
$ sudo python wiiboard_test.py
You will see the following response:
Press the red sync button on the board now
Remove the battery cover underneath the Board to locate the red sync button. Make sure you press the button within a few seconds of running the script or a timeout will occur. Once successful, you will see something similar to the following:
Found Wiiboard at address 00:23:CC:2E:E1:44
Trying to connect...
Connected to Wiiboard at address 00:23:CC:2E:E1:44
ACK to data write received
The wiiboard_test.py script is taking the number of weight measurements specified on line 10 and outputting the average:
# --------- User Settings ---------
WEIGHT_SAMPLES = 500 #
You can play with this number by changing the value and re-running the script to see the variation in weight measured and time required for each measurement. Weigh yourself, weigh your dog, weigh whatever and see if the measurements make sense. To stop the script, press CTRL+C.
Nintendo assumed you would always power your Wii Balance Board with four AA batteries and included no AC power adapter. Having only battery power would be inconvenient because we cannot permanently pair our Wii Board to our Pi through bluetooth. We need to sync it, then allow it to remain sync'd w/o draining the batteries so we can simply step on the scale and weigh. Luckily, there are several third-party adapters made for the Wii Balance Board that we can use to provide constant power from a wall outlet. The Wii Fit Rechargeable Battery Pack is a perfect solution to our power problem. Replace the batteries with this battery pack, and plug the ac adapter into a wall outlet.
Having to pair the Wii Balance Board and Raspberry Pi every time we run our Python script presents another inconvenience due to the location of the sync button. The sync button is at the bottom of the Wii Board, which means we would have to flip it over every time we sync. We can fix this by making a hacky little lever using a pencil and three 3/8" felt pads as shown above. The rechargeable battery pack exposes the sync button to the underneath surface of the Board. Tape a pencil (or something similar) that spans from the sync button to the outside front of the Board. Stack three 3/8" felt pads (or something similar) on the center (ish) of the pencil to create a stationary pivot. Be careful to not expose too much of the pencil out from the Board as you don't want someone to accidentally kick it out. Flip the Board over and you can press the sync button by simply pressing down on the lever. Hacky but effective.
Depending on how you store your Wii Board, you may want to remove the rubber grip pads from the feet of the Board (the pads are simply stickers you can pry off). 3/8" felt pads can be placed on the Board's feet for easy sliding.
We want to stream our weight/data to a cloud service and have that service turn our data into a nice dashboard that we can access from our laptop or mobile device. Our data needs a destination. We will use Initial State as that destination.
Step 1: Register for Initial State Account
Go to https://app.initialstate.com/#/register/ and create a new account.
Step 2: Install the ISStreamer
Install the Initial State Python module onto your Pi:
At a command prompt (don't forget to SSH into your Pi first), run the following command:
$ cd /home/pi/
$ \curl -sSL https://get.initialstate.com/python -o - | sudo bash
Security Note: The above command has some important anatomy that the user should be aware of. 1) There is a preceding \ before curl. This is important to ensure no alias of curl gets run if one was created. This helps mitigate risk of the command doing more than intended. 2) The command is a piped command, so when running, you are piping the output of a script that is being retrieved from https://get.initialstate.com/python into the command sudo bash. This is done to simplify installation, however, it should be noted that https is important here for helping ensure no man-in-the-middle manipulation of the install script, especially since the script is being run with elevated privileges. This is a common way to simplify install and setup, but if you are a little more weary there are some slightly less convenient alternatives: you can break the command out into two steps and investigate the bash script being downloaded from the curl command yourself to insure it's fidelity OR you can follow the pip instructions, you just wont get an automatically generated example script.
When prompted to automatically get an example script, type y. This will create a test script that we can run to ensure that we can stream data to Initial State from our Pi. You will be prompted:
Where do you want to save the example? [default: ./is_example.py]:
You can either type a custom local path or hit enter to accept the default.
You will be prompted for your username and password that you just created when you registered your Initial State account. Enter both and the installation will complete.
Let's take a look at the example script that was created.
$ nano is_example.py
On line 15, you will see a line that starts with streamer = Streamer(bucket_ .... This lines creates a new data bucket named "Python Stream Example" and is associated with your account. This association happens because of the access_key="..." parameter on that same line. That long series of letters and numbers is your Initial State account access key. If you go to your Initial State account in your web browser, click on your username in the top right, then go to "my account", you will find that same access key at the bottom of the page under "Streaming Access Keys".
Every time you create a data stream, that access key will direct that data stream to your account (so don't share your key with anyone).
Run the test script to make sure we can create a data stream to your Initial State account. Run the following:
$ python is_example.py Step
Go back to your Initial State account in your web browser. A new data bucket called "Python Stream Example" should have shown up on the left in your log shelf (you may have to refresh the page). Click on this bucket and then click on the Waves icon to view the test data.
You will want to step through the Waves tutorial to familiarize yourself with how to use this data visualization tool. Next, view the data in Tiles to see this same data in dashboard form.
You are now ready to start streaming real data from your scale.
Assuming you ran the "git clone https://github.com/InitialState/smart-scale.git " command in Part 2, the final script that puts everything together is called smartscale.py in your ~/smart-scale directory. (https://github.com/InitialState/smart-scale/blob/master/smartscale.py)
A few settings need to be set in the script before you can run it. Open up smartscale.py in your favorite text editor such as nano.
$ cd ~
$ cd smart-scale
$ nano smartscale.py
Near the top of this file, there is a User Settings section.
# --------- User Settings ---------
BUCKET_NAME = ":apple: My Weight History"
BUCKET_KEY = "weight11"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
METRIC_UNITS = False
WEIGHT_SAMPLES = 500
THROWAWAY_SAMPLES = 100
WEIGHT_HISTORY = 7
Once you have specified each parameter in this section and saved your changes, you are ready to run the final script. Before we run the script, let's go through what it is going to do.
Run the script to start the magic.
$ sudo python smartscale.py
Go to your Initial State account and click on the new data bucket with the name corresponding to the BUCKET_NAME parameter (i.e. My Weight History). Click on Tiles to view your weight history dashboard. You should see three tiles the first time you view your data in Tiles - Update, Weight Date, and Weight(lb). You can customize your dashboard by resizing and moving tiles as well as changing view types and even adding tiles. This dashboard gives you the ability to see your weight history at-a-glance. It is mobile friendly and you can even share it with other people.
Let's create a SMS alert whenever the scale takes a weight measurement.
We are going to follow the Trigger notification setup process outlined at http://support.initialstate.com/knowledgebase/articles/834354-triggers-adding-a-trigger.
Your trigger is now live and will fire when the condition is met. Click done to return to the main screen.
Once setup is complete, you will get a SMS every time you weigh yourself that contains your weight, how much you weight changed since the last measurement, and a random joke / insult / compliment.
Possibilities for you to build on this project: