Part 2. Reading the Scale
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 (https://github.com/skorokithakis/gr8w8upd8m8). The python script we will be using is located at https://github.com/InitialState/beerfridge/blob/master/wiiboard_test.py. 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/beerfridge.git beerfridge Cloning into 'beerfridge'... remote: Counting objects: 9, done. remote: Compressing objects: 100% (7/7), done. remote: Total 9 (delta 1), reused 6 (delta 1), pack-reused 0 Unpacking objects: 100% (9/9), done. Checking connectivity... done.
You should see four python files in the new beerfridge directory - beerfridge.py, switch_test.py, temperature_test.py, and wiiboard_test.py.
$ cd beerfridge $ ls README.md beerfridge.py switch_test.py temperature_test.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:
Discovering board... 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 Wiiboard connected ACK to data write received 84.9185297 lbs 84.8826412 lbs 84.9275927 lbs
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.
You have now successfully converted your Wii Balance Board into a Raspberry Pi connected scale. Let's get it ready to start taking measurements of our refrigerator.