Code Monkey home page Code Monkey logo

wiiweigh's Introduction

wiiweigh

Use your Wii balance board as a scale, working with auto-reconnect on a raspberry pi 3, using bluez 5, xwiimote and some python.

about

This is essentially a mashup of existing projects in a try to get a connection and data from the Wii Balance Board without having to resync (red button) on each connection with newer bluez versions. After the non-recurring syncronization you can connect the board by a single push of its button, step on the board, wait for a stable average weight and step off, the board disconnects and turns of, ready for the next connection.

credits

main requirements

  • hid_wiimote kernel module with xwiimote and xwiimote-bindings
  • python-dbus
  • bluez 5

caveats

Adopted and tested on a Raspberry with Python 2. If Python 3 is the default, either the scripts need an update, or the installation process is slightly different.

On a test with Arch Linux and a newer Bluez stack I couldn't sucessfully disconnect the Balance Board from the PC-side. On the latest Raspbian version that's not a problem (yet).

howto

Install bluez, bluez-firmware and python-bluez. I've built xwiimote and bindings from source, because the debian xwiimote package did not harmonize with the bindings-source.

Step-by-step procedure on Raspbian (tested on a Raspberry Pi 2 with Bluetooth dongle, Raspian lite from 04/2018)

sudo apt-get update && sudo apt-get upgrade
# on raspbian already installed packages:
# sudo apt-get install build-essential bluez
sudo apt-get install python-dbus git autoconf libtool libudev-dev \
                     libncurses5-dev swig python-dev python-numpy
python -V
# should return Python 2.7.x

mkdir src && cd src
git clone https://github.com/dvdhrm/xwiimote.git
git clone https://github.com/dvdhrm/xwiimote-bindings.git
git clone https://github.com/chaosbiber/wiiweigh.git
cd xwiimote
./autogen.sh
make
sudo make install
cd ../xwiimote-bindings
./autogen.sh
make
sudo make install
cd ../wiiweigh

sudo gpasswd -a pi bluetooth # add user pi to bluetooth group
# reboot or the wiiweight script will throw an exception
# when trying to disconnect as normal user
sudo bluetoothctl
# continue with bluetooth setup below

The following procedure should only be required once, the sync survives host reboots. Just try if after the disconnect command you can connect by simply pushing the front button of the board, if not, delete the pairing and try again. The hid_wiimote module lights the blue led of the button when loaded, when it's not the led keeps blinking.

pair Wiiboard

Start bluetoothctl

power on
agent on
<press red sync button>
scan on
pair <MAC of the found wiimote, use TAB for autocompletion>
# note: we do not explicitly connect, we just pair!
connect <MAC of the wiimote>
# there seems to be a pretty short timeout, so execute this immediately after the pairing command

trust <MAC of the wiimote>
disconnect <MAC of the wiimote>
scan off
exit

(From https://wiki.archlinux.org/index.php/XWiimote) exit with exit or Ctrl+D

Manual disconnect (if needed during tests) with

echo "disconnect <MAC of the wiimote>" | bluetoothctl

This might throw warnings, but works. Alternatively remove the batteries.

usage

After pairing the wiiboard, run

python ~/src/wiiweigh/wiiweigh.py

Press wiibord power to connect, if the blue light stays lit, that means the board is connected.

{Device1.PropertyChanged} [/org/bluez/hci0/dev_<MAC of the wiimote>] Connected = 1

Stand on the board and wait for output.

67.02 +/- 0.30

The blue light will also go off and disconnect.

{Device1.PropertyChanged} [/org/bluez/hci0/dev_<MAC of the wiimote>] Connected = 0

Press power again to repeat the process.

error

If you encountered

ImportError: /usr/lib/arm-linux-gnueabihf/libxwiimote.so.2: version `LIBXWIIMOTE_3' not found (required by /usr/local/lib/python2.7/dist-packages/_xwiimote.so)

Add export LD_LIBRARY_PATH=/usr/local/lib to the last line of the .profile sudo nano .profile

Run env | grep '^LD_LIBRARY_PATH', it should output LD_LIBRARY_PATH=/usr/local/lib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.