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.

  1. No trackbacks yet.