Home > Arduino, Bluetooth, TKJ Electronics, USB > Wiimote added to USB Host library

Wiimote added to USB Host library

This is yet again a new announcement regarding the USB Host library. I just added support for the Wiimote via Bluetooth.
Check out the source code at github: https://github.com/felis/USB_Host_Shield_2.0/blob/master/Wii.cpp and the example sketch as well.
I will work on implementing support for the Nunchuck and Wii Motion Plus extension in the near future.

Update:
The library now also supports the Nunchuck controller and the Motion Plus extensions. The newest version of the library can be found at github.

Another Update:
The library now also work with the new Wiimote where the Motion Plus extension is built-in.
Check out my commit to see what where needed in order to make the new Wiimote work as well – the main difference is that you now have to send the data using the interrupt channel.
To tell if your Wiimote is the new type, it should have a label at the bottom saying “Wii MotionPlus INSIDE”. If you are in doubt take a look at this picture.

Yet another update:
The IR camera inside the Wiimote is now also supported. The the following commit for more information.

A new update once again:
The Wii U Pro Controller is now also supported via Bluetooth.

Categories: Arduino, Bluetooth, TKJ Electronics, USB Tags:
  1. Christian Gerefalk
    August 22nd, 2012 at 19:47 | #1

    Good job, was annoyed over it working nicely in the past with pre 1.0 Arduino IDE and the author didn’t update for post 1.0, anyway I tried the example and I get this:

    Wiimote Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:02:5B:46:86:DC
    Connecting to Wiimote
    Connected to Wiimote
    Send HID Control Connection Request

    And it sits there for ages, the wiimote and dongle both blink for a while and then go dark but nothing happens beyond that, am I doing something wrong? I assumed that at some point it would reach a state where it reported back what I’m pushing etc.

  2. August 22nd, 2012 at 19:50 | #2

    @Christian Gerefalk
    Try to create the instance like so: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/Wiimote/Wiimote.ino#L11 so it does a inquiry. If that doesn’t work then try to uncomment EXTRADEBUG (https://github.com/felis/USB_Host_Shield_2.0/blob/master/Wii.cpp#L20) and send me the output.
    Also try to use a different dongle ;)

  3. Christian Gerefalk
    August 23rd, 2012 at 14:49 | #3

    I got two dongles one tiny that isn’t much larger than the USB port itself, and an old big box on a lead, both give the same result:


    Wiimote Bluetooth Library Started
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:08:F4:00:6D:ED
    Starting inquiry
    Press 1 & 2 on the Wiimote
    Wiimote found
    Create the instance like so to connect automatically:
    WII Wii(&Btd,0x00,0x18,0x00,0xF0,0x1D,0x18);
    Connecting to Wiimote
    Connected to Wiimote
    Send HID Control Connection Request

    If it matters my wiimote is a chinese copy, it works with an actual Wii and Wii emulators/gamepad utilities (glovepie etc).

    I uncommented that line, should the output have been in the serial monitor? I only get what I pasted above.

  4. August 23rd, 2012 at 22:26 | #4

    @Christian Gerefalk
    Hmm, it looks like it doesn’t respond to the connection request. Did it work with the old library?
    Try to add something like this:

    Serial.print("\r\nL2CAP_CMD_CONNECTION_RESPONSE");

    After this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/Wii.cpp#L80

    Sorry you should also uncomment this line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L20
    So it will print more debugging.

  5. Christian Gerefalk
    August 29th, 2012 at 14:12 | #5

    I never got the old library to work at all since I got a 2.0 shield and 1.0.1 IDE

    Small stick:


    Wiimote Bluetooth Library Started
    BTD Init
    Addr: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 81
    Attributes: 03
    MaxPktSize: 0010
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 82
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 01
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:02:5B:46:86:DC
    Starting inquiry
    Press 1 & 2 on the Wiimote
    Number of responses: 1
    Wiimote found
    Create the instance like so to connect automatically:
    WII Wii(&Btd,0x00,0x18,0x00,0xF0,0x1D,0x18);
    Connecting to Wiimote
    Connected to Wiimote
    Send HID Control Connection Request”

    Both the wiimote and LED on the stick flash for a while after reaching there.

    Large dongle:

    “Wiimote Bluetooth Library Started
    BTD Init
    Addr: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 81
    Attributes: 03
    MaxPktSize: 0010
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 82
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 01
    Bluetooth Dongle Initialized
    No response to HCI Reset
    HCI Reset complete
    Local Bluetooth Address: 00:08:F4:00:6D:ED
    Starting inquiry
    Press 1 & 2 on the Wiimote
    Number of responses: 1
    Wiimote found
    Create the instance like so to connect automatically:
    WII Wii(&Btd,0x00,0x18,0x00,0xF0,0x1D,0x18);
    Connecting to Wiimote
    Connected to Wiimote
    Send HID Control Connection Request”

  6. Christian Gerefalk
    August 29th, 2012 at 14:18 | #6

    Bah can’t edit.

    I did add that line btw here is my Wii.ccp in full: http://pastebin.com/hEzK1M3C and BTD.ccp in full: http://pastebin.com/XRngCHCH

    Copied yours from the links you gave but that gave me “AnalogHat not defined in this scope” errors, so these are based on the ones I downloaded from github

  7. Christian Gerefalk
    August 29th, 2012 at 14:35 | #7

    Just updated the library and tried again with the same results, I do get warnings when compiling both the new and old version of the library btw, mostly:

    “C:\Program Files (x86)\arduino-1.0.1\libraries\USB_Host_Shield_2\RFCOMM.cpp:1233: warning: only initialized variables can be placed into program memory area” a ton of those on that file and confdescparser.h etc, full log here: http://pastebin.com/xpk97ArE

  8. September 2nd, 2012 at 19:00 | #8

    @Christian Gerefalk
    It sounds like you have added the library incorrectly if you are getting compiler errors. See this page for more information: http://www.arduino.cc/en/Hacking/Libraries
    Make sure that you can select the example sketch in File>Examples>”folder name”>Bluetooth>Wii. Don’t try to copy and paste the code from github.

  9. Christian Gerefalk
    September 7th, 2012 at 16:02 | #9

    I did add it as I’ve done with all others I have working, I can open the example in the IDE, I got warnings etc turned on which isn’t the default setting in the IDE, it warns me about those, it doesn’t error out and stop.

  10. September 8th, 2012 at 17:22 | #10

    @Christian Gerefalk
    What hardware are you using?
    I will try the same to reflect your setup.

  11. Christian Gerefalk
    September 11th, 2012 at 17:22 | #11

    Recent uno and and older mega1280, bluetooth dongles: http://dx.com/p/world-s-smallest-bluetooth-2-0-edr-usb-dongle-12696?item=20 something like that, exact same “design” anyway, and a credit card sized 1cm thick ancient dongle on a lead, controller: http://dx.com/remote-and-nunchuck-controller-for-wii-blue-37855?item=6 not loading for me here atm but it’s the third on this search: http://dx.com/s/Remote+and+nunchuck+controller+for+wii+blue ($13.90 one) as said before I’ve tried both dongles and the remote on my PC (dolphin, GlovePIE) and the remote with a real wii, works fine.

  12. September 12th, 2012 at 18:58 | #12

    @Christian Gerefalk
    Your comment was caught in our spam filter, so I haven’t seen it until now.
    Okay, I still think that you are including the libraries wrong, I have several people who has confirmed that the library works great and they don’t get any errors at all.

  13. September 16th, 2012 at 19:43 | #13

    @Christian Gerefalk
    I thought a bit more about the problems you are having. Do you by any change got other version of the USB library inside the library folder? If so then remove them from there.

  14. Fisher Wei
    September 18th, 2012 at 08:18 | #14

    Hi,

    Thanks for your job first, and I got the following error message, when I pluged in a nunchuck:

    Extension connected
    Checking extension port
    Unknown Device: 00FA
    Data: FF 00 A4 20 00 00

    or a classic controller pro:

    Extension connected
    Checking extension port
    Unknown Device: 00FA
    Data: 01 00 A4 20 01 01

    what is wrong with this?

  15. September 18th, 2012 at 12:37 | #15

    @Fisher Wei
    It seems like you Nunchuck is not returning the correct signature. The right one should be 00 00 A4 20 00 00. See: https://github.com/felis/USB_Host_Shield_2.0/blob/master/Wii.cpp#L230 and http://wiibrew.org/wiki/Wiimote/Extension_Controllers.
    Is it a third party Nunchuck? It’s pretty easy to fix. Just remove “l2capinbuf[15] == 0x00 &&” from the code at the line I just sent you.
    The library doesn’t support the Classic controller as I haven’t got my hands on one yet.

  16. Fisher Wei
    September 18th, 2012 at 13:38 | #16

    @Lauszus
    Hi, I think my nunchuck is not 3rd party, and if I plug nunchuck in before powering arduino on, it will work fine. If power on and pair at first, it will report error message. I don’t know why. :)

  17. September 18th, 2012 at 14:07 | #17

    @Fisher Wei
    Okay. Sounds weird. I can plug the Nunchuck in and out of the Wiimote without any problems. Try to remove the line I told you in the earlier reply and tell me if it works then. If so I will add it to the library.

  18. Fisher Wei
    September 19th, 2012 at 10:08 | #18

    @Lauszus
    Yes, it works. I removed “l2capinbuf[15] == 0×00 &&”.
    And then, I have a new issue: I pluged motion plus in, arduino has not any responses, no “Unknown Device”, no “Motion Plus connected”. If I plugin before powering on, it also works.

  19. September 19th, 2012 at 10:48 | #19

    @Fisher Wei
    That is normal. You have to plug in the motion plus before powerup.

  20. Michael Motes
    October 24th, 2012 at 17:21 | #20

    Is there any plans to support the IR camera?

  21. October 24th, 2012 at 18:17 | #21

    @Michael Motes
    No not currently :)

  22. Rick
    November 11th, 2012 at 20:44 | #22

    Very nice!

    However, when I wanted to run the latest Wii example from git I had to comment out some DEBUG macros within the library code in order to produce a sketch that could fit on my Uno… The sketch is still around 26 kB and I was wondering if there is more debug code that takes up lots of space?

  23. November 11th, 2012 at 20:48 | #23

    @Rick
    All the debug messages can be disabled by comment out these line: https://github.com/felis/USB_Host_Shield_2.0/blob/master/BTD.cpp#L19 and https://github.com/felis/USB_Host_Shield_2.0/blob/master/Wii.cpp#L19, but I guess you have already done that?

  24. Rick
    November 11th, 2012 at 21:27 | #24

    Yup…and that left me with a binary size of roughly 26 kB (Wii example). Is this ‘normal’? Kinda limits the possibilities when using the Uno with this library. But I guess that may be a problem of the complexity of USB…

  25. November 11th, 2012 at 21:32 | #25

    @Rick
    Yes that is normal. But you have to know that the example sketch actually takes up a lot of flash as it got so many strings.
    Yes I’m afraid too, but take a look at the atmega644 (aka Sanguino: http://sanguino.cc/) at my github repository: https://github.com/Lauszus/sanguino it got the double amount of flash than the Uno and it’s also available in a DIP package.

  26. Neni
    March 8th, 2014 at 20:13 | #26

    Hi.
    Thank you very much for your work. I am using arduino ADK with one of suggested Bluetooth dongle. I am unable to make it work with WII mote it is getting stuck at “Send HID connection request” I am enclosing debug information. Any help will be appreciated.

    Wiimote Bluetooth Library Started
    BTD ConfigureDevice
    BTD Init
    Addr: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 81
    Attributes: 03
    MaxPktSize: 0010
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 82
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Bluetooth Dongle Initialized
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    Connection established
    HCI Reset complete
    Unmanaged HCI Event: 24
    Write class of device
    Local Bluetooth Address: 00:15:83:0C:BF:EB
    Starting inquiry
    Press 1 & 2 on the Wiimote
    Or press sync if you are using a Wii U Pro Controller
    Number of responses: 1
    Wiimote found
    Now just create the instance like so:
    WII Wii(&Btd);
    And then press any button on the Wiimote
    Connecting to Wiimote
    Connection established
    Connected to Wiimote
    Unmanaged HCI Event: 11
    Unmanaged HCI Event: 11
    Received Key Request
    Pairing with wiimote
    Pairing successful with Wiimote
    Send HID Control Connection Request

  27. March 9th, 2014 at 13:04 | #27

    @Neni
    Could you try another Bluetooth dongle?
    Also it look like that it aborted an ongoing connection. Please try to unplug the Bluetooth dongle and turn off the Wiimote and then try again.

  28. Neni
    March 9th, 2014 at 17:43 | #28

    Tried another dongle, received similar messages. It worked once and is not working again. Any delay issues with ADK?

    Wiimote Bluetooth Library Started
    BTD ConfigureDevice
    BTD Init
    Addr: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 81
    Attributes: 03
    MaxPktSize: 0010
    Poll Intrv: 01
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 82
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Endpoint descriptor:
    Length: 07
    Type: 05
    Address: 02
    Attributes: 02
    MaxPktSize: 0040
    Poll Intrv: 00
    Bluetooth Dongle Initialized
    Connection established
    Connection established
    Connection established
    HCI Reset complete
    Unmanaged HCI Event: 24
    Write class of device
    Local Bluetooth Address: 00:13:EF:F1:43:AC
    Starting inquiry
    Press 1 & 2 on the Wiimote
    Or press sync if you are using a Wii U Pro Controller
    Number of responses: 1
    Wiimote found
    Now just create the instance like so:
    WII Wii(&Btd);
    And then press any button on the Wiimote
    Connecting to Wiimote
    Connection established
    Connected to Wiimote
    Unmanaged HCI Event: 1D
    Received Key Request
    Pairing with wiimote
    Pairing successful with Wiimote
    Send HID Control Connection Request

  29. March 9th, 2014 at 23:31 | #29

    @Neni
    Hmm try to add:

    delay(5);

    In your loop and see if that helps.

  30. Neni
    March 10th, 2014 at 02:07 | #30

    Tried and no luck. Still same issue. Tried three dongles so far. Bluetooth SPP works fine on all three.
    Any more suggestions??

  31. March 10th, 2014 at 22:28 | #31

    @Neni
    No unfortunately no. We will start start to sell the Bluetooth dongles we use for the Balanduino in our shop, so people like you don’t have to search for a dongle that works with the library.
    I expect that we will list it this month.

  32. Neni
    March 13th, 2014 at 02:13 | #32

    Thanks. I will wait for it. I have one more problem. I tired to compile PS3BT with Arduino 1.56 Beta 2 for Mega ADK. I am getting error whenever I enable host debugging.

    Arduino: 1.5.6-r2 (Windows XP), Board: “Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)”

    c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default’:
    (.vectors+0x94): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_37′ defined in .text section in c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o

  33. March 13th, 2014 at 13:07 | #33

    @Neni
    This is a bug in avr-gcc: https://sourceware.org/bugzilla/show_bug.cgi?id=13410.

    Try to remove some of the strings stored in flash like so:

    Serial.print(F("\r\nCross"));

    Becomes:

    Serial.print("\r\nCross");

    Btw I can’t reproduce this, so I can not give you any more guidance than this. Also I know that the Arduino team is working on updating the toolchain, so this bug should get fixed when they do that.

  34. Neni
    March 14th, 2014 at 05:43 | #34

    Thank you very much. Worked by removing all strings stored in Flash.

  35. March 14th, 2014 at 13:41 | #35

    @Neni
    You are welcome :)

  36. NicoHood
    May 20th, 2014 at 14:24 | #36

    Hi again :D
    Finally got the shield but as expected i got some problems as always :D

    So first what works:
    HID Keyboard
    Wiimote with all 3 doogles (2 had some probs first but now its fine)

    What doesnt work:
    Wiiu Pro controller sync with 2 doogles (cheap 1€ china doogles). My old Bluetooth doogle thats nearly broken works. The weird thing is: all 3 work for the wiimote, but the cheap once dont for the pro controller. But they DO work on my pc with software, all 3!

    Okay so i got the controller synced with one doogle. Led is on, fine. But no button Press is recognized. I had no idea what to do, googled and noticed the controller disconnected. Pressed a key, reconnected and whoops! works O.o So i have to start the sketch, connect the controller, turn it off and on again. Any idea why that happens, and how to solve? I am using the 1.0.5 IDE and a MEGA 2560. It would be also nice to get the cheap doogles to work with the pro controller.

    A general question: How does the sync work? Is something stored in eeprom or does each shield or doogle has a specific id to sync with? I dont want to overwrite that eeprom later.

    Debug output for the working doogle:
    http://pastebin.com/u31Spwrr

    Debug output for the not working doogle:
    http://pastebin.com/sKj0rbP1

    Thx for ya help :)

  37. June 21st, 2014 at 00:44 | #37

    @NicoHood
    Unfortunately I don’t own a Pro U Controller, so I will have to wait until I can get my hands on one again.

    The sync simply work by when you pair with the controller, the Wiimote/Pro Controller will store the Bluetooth address of your dongle inside it’s EEPROM and then it will try to connect to that Bluetooth address when you press on any button, so the Arduino’s EEPROM is actually not used at all.

  38. NicoHood
    June 21st, 2014 at 00:52 | #38

    @ lauszus:
    oh, okay. I had no time to get my hands on that. I will try to seperate the wiimote and the controller if ive got time.

    I also noticed that the motion control doesnt work for a normal wiimote. The value is always the same.

    I am wondering how often you need to call the usb task, to keep the connection. Do you know that maybe? and how long does this operation take?

  39. June 21st, 2014 at 00:55 | #39

    @NicoHood
    My experience is that you need to call Usb.Task a lot more when you the Wiimote compared to for example the PS3 controller, as it looks like it will just stack up all measurements in a buffer, so it will end up being delayed, so basically you need to prevent using any delays in your code at all and instead use millis and micros and state-machine in order to keep calling Usb.Task.
    The code itself does not take very long, but I haven’t actually measured it as it depends on how many drivers you have running at the same time.

  1. No trackbacks yet.