Shopping Cart

Posts

RC car controlled by Wii Remote on Arduino

This is a quick post about another great project. Tomoyuki Tanaka AKA Tomo on this site, active in PS3 and Wiimote game controllers thread, AKA moyuchin on Youtube posted this little video of RC car controller made of Wiimote, Arduino Pro Mini and USB Host Shield Mini interfacing with Bluetooth dongle. Check out the video to see how speed, direction and steering controls have been implemented.

Tomoyuki also made the code available on github. The code is based on Richard Ibbotson’s popular Wiimote Bluetooth code, as well as my MAX3421E and USB Host libraries. The code is well organized and even has a brief documentation in README file. Further development is on the way – Tomo is planning to add ultrasonic sensor support, so keep an eye on this repo. Good job, Tomoyuki and thank you very much for sharing your outstanding work!

Oleg.

Related posts:

  1. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 1
  2. Bluetooth code for Arduino USB Host
  3. Interfacing MIDI devices with Arduino using USB Host Shield
  4. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3
  5. Sony PS3 Controller support added to USB Host library
  6. Controlling robotic arm with Arduino and USB mouse
  7. Arduino USB Host Mini – first prototype.
  8. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 2
  9. Using USB Bluetooth dongle on Arduino to connect to Windows PC
  10. Arduino USB host – Pre-prototyping.

41 comments to RC car controlled by Wii Remote on Arduino

  • Cubexed

    I did some work this week with my Arduino ADK and i got this far… (not much to be sincere)

    https://github.com/Cubexed/Arduino-PSRemote

    But i can’t get working the HID layer and initialize the PS Controller

  • Sorn

    I use arduino 1.0 and arduino duemilanove.The wiiRemote library that you post can’t compile and upload to arduino because Wprogram.h isn’t found. So,I search solution to this problem and I found someone change Wprogram.h to Arduino.h but it is other library.It can be OK if I do that in this library.

    Thank you

  • Emil

    Hi,

    i have to do a final project for school and i think im going to do this project. But ive got no experience with any arduino or microcontrollers… i did some research and i think that i need the arduino uno, with usb shield and with bluetooth dongle (am i right?). But my question was if its not too hard for me because ive got no experience at all. and maybe if you can help me with the codes for the arduino, because i think i’ll be ok with the hardware placing…
    (BTW i have an rc car with only rear wheels powered and the front for turning. and i want to communicate with the wiimote that (1) is forward, (2) or (B) is backwards and as in your video that the accelrometer is used for steering)

    Thank you for your reply
    Emil

  • Emil

    (button (2) and (1) on the wiimote i meant (2) for forward driving and (1) or (b) for backwards.)

  • Emil

    and with what can i powerup the arduino board?

  • KriLL3

    Has anyone had success connecting a wiimote to a host shield running a USB Host Shield 2.0 library? a bit annoying that all this stuff seems to have worked nicely at one point, but no longer works due to unmaintained code/documentation.

  • Polarbear13

    I am doing a project with an Arduino UNO, USB dongle Rocketfish 2.1, Wiimote and RC car. I am no good at programming and need to know how to write the code? I do not know how to put the different libraries together. I mean there is code for the Wii and the USB and then there is the code for the RC car to get it to work. I think I have to put them into one sketch, but not sure how to do this. Please help.

  • Polarbear13

    I added the USB host shield and the WiiRemote to my libraries. Now how do I write the program to use the Wiimote via Bluetooth for the Arduino? I am trying to contol an RC Car with the Wiimote without the computer(exept for programing the Arduino).

  • BSchaeffner

    I am interessted to have a Wiiremote library for the Host Shield V2 and Arduino 1.0, too. I have tried to convert it to Host Shield 2.0 and Arduino 1.0 but i am failed. Thank you

  • Polarbear13

    Lauszus,
    any updates??

  • I just added support for the Wiimote.
    See the updated library at github: https://github.com/felis/USB_Host_Shield_2.0

  • Polarbear13

    I was able to get my arduino communicating via bluetooth finally after I purchased a new dongle. Now I can concentrate on working with this library you sent. Is there any other updates?

    • No I don’t think so, unless I get my hands on a Classic Controller, but I have implemented support for the Nunchuck and the Motion Plus extension, so I think most people will be satisfied.
      But I got some few improvements regarding the BTD library so it doesn’t wait until it has connected to the Wiimote I also have some few other improvements for the Wii library as well, but they won’t change anything regarding how it’s used by the Arduino IDE.

  • Polarbear13

    I am getting this error, any way I can correct this?

    In file included from C:\Users\fs100220\Desktop\arduino-1.0.1-windows\arduimo-1.0.1\libraries\WiiRemot_on_Arduino_2/WiiRemote.h:20,
    from GETITWORKING2.cpp:70:
    C:\Users\fs100220\Desktop\arduino-1.0.1-windows\arduino-1.0.1\libraries\WiiRemote_on_Arduino_2/Max3421e.h:12: error: expected constructor, destructor, or type conversion before ‘class’

  • Polarbear13

    Once I download the library and open the sketch, do I need to Import the library I just downloaded?

  • Polarbear13

    I get these errors:
    ‘class WII’ has no memeber named ‘wiimoteConnected’ //that is in orange

    Wii.cpp: In function ‘void loop()’:
    Wii:58: error: ‘class WII’ has no member named ‘wiimoteConnected’
    Wii:106: error: ‘class WII’ has no member named ‘getPitch’
    Wii:108: error: ‘class WII’ has no member named ‘getRoll’
    Wii:109: error: ‘class WII’ has no member named ‘motionPlusConnected’
    Wii:111: error: ‘class WII’ has no member named ‘getYaw’
    Wii:113: error: ‘class WII’ has no member named ‘nunchuckConnected’
    Wii:115: error: ‘class WII’ has no member named ‘nunchuckPitch’
    Wii:117: error: ‘class WII’ has no member named ‘nunchuckRoll’
    Wii:121: error: ‘class WII’ has no member named ‘nunchuckConnected’
    Wii:122: error: ‘Z’ was not declared in this scope
    Wii:124: error: ‘C’ was not declared in this scope
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’
    Wii:126: error: ‘HatX’ was not declared in this scope
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’
    Wii:126: error: ‘HatX’ was not declared in this scope
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’
    Wii:126: error: ‘HatX’ was not declared in this scope
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’
    Wii:126: error: ‘class WII’ has no member named ‘getAnalogHat’

    • Okay. First visit github: https://github.com/felis/USB_Host_Shield_2.0 and download the library as a zip file (press the button labeled zip). Then uncompress the zip folder and rename the directory to “USB_Host_Shield_20″.

      Now open up the Arduino IDE and look in the menu. Then open Arduino>Setting. There you can see the location of your sketchbook. Open that folder and create a folder called “libraries” inside that directory.
      Now move the “USB_Host_Shield_20″ folder to that directory.

      Now quit the Arduino IDE and reopen it. This is very important!

      Now again open the menu, but this time open File>Examples>USB_Host_Shield_20>Bluetooth>Wii.
      It will then open up the example sketch. Compile and upload to your Arduino and away you go! :)

  • Polarbear13

    I had some other files getting in the way, I removed them and it compiled. Now for the next step, do I download this to my Arduino board and the car should work?

  • Polarbear13

    Thanks for all your help Lauszus.

  • Polarbear13

    which pin do i connect the motor to and which pin do i connect the sero to?

  • Craig

    I am new to arduino programming and arduino in general, so forgive me if my questions seem a little amateur. What is the name of the Bluetooth dongle that you used? I am having trouble getting the wiimote to simply connect with the board. Also, I keep getting an error saying avrdude: stk500_getsync(): not in sync: resp=0×00. What is your serial port and board settings? I have a feeling that most of this could be caused by having the wrong Bluetooth dongle though. Thanks.

    • Avrdude error means your Atmega chip is not programming correctly; at his point the bluetooth dongle is irrelevant. Forum at arduino.cc is a good place to learn about avrdude errors and ways to fix them.

      • Craig

        I am using an arduino uno and with that a USB Host Shield 2.0, my serial port is /dev/tty.Bluetooth-PDA-Sync and my programmer is set as the AVR ISP. Should these be set any differently?

        • You havn’t selected the right serial port. For instance mine is: /dev/tty.usbmodem411. It doesn’t matter what programmer you choose as you are using the bootloader on the Arduino.

          You should only use /dev/tty.Bluetooth-PDA-Sync if you need a SPP connection with for instance an Android phone.

  • chris

    which pin do i connect the motor to and which pin do i connect the servo to? (to repeat polarbears question)

  • Craig

    I am running the SteeringWii.pde example sketch. I can successfully get the wiimote to connect with the bluetooth dongle on the board when I run the sketch. I am having an issue that when I open the serial monitor, the wiimote looses connection, and then says “lost Bluetooth connection” over and over again. What could be causing this problem?

  • Macy

    I am having trouble getting both the gas and steering to work. Could someone post their final sketch so that I can compare? Thanks

  • Macy

    For example, this is my final sketch. Pin 9 can work for both steering and acceleration, but I can’t find another pin that works correctly, Obviously I cannot do both at the same time if only pin 9 works. Does anyone have any suggestions? Am I looking over the obvioius?

    #include “WiiRemote.h”
    #include

    int x = 1;

    Servo myservo; // create servo object to control a servo
    Servo steering; // a maximum of eight servo objects can be created

    int pos = 0; // variable to store the servo position

    int voltPin = 2;

    #define STEERING_ANGLE_MAX 165
    #define STEERING_ANGLE_MIN 15
    #define STEERING_ANGLE_CENTER 90
    #define STEERING_ANGLE_STEP 5

    WiiRemote wiiremote;

    void setup()
    {
    Serial.begin(9600);
    wiiremote.init();

    pinMode (voltPin, OUTPUT);

    digitalWrite(voltPin, 3);

    myservo.attach(9); // attaches the servo on pin 9 to the servo object
    myservo.write(90);
    steering.attach(10);
    steering.write(90);
    }

    void loop()
    {
    wiiremote.task(&myapp);
    if (!(wiiremote.getStatus() & WIIREMOTE_STATE_RUNNING)) {
    //Serial.print(“\r\nlost Bluetooth connection”);
    }

    }

    void myapp(void) {
    //if (wiiremote.buttonClicked(WIIREMOTE_TWO))

    int steering_angle = getSteeringAngle();

    }

    int getSteeringAngle(void) {
    double rad;
    double deg;

    rad = acos((double) wiiremote.Report.Accel.Y);
    deg = rad * 180.0 / PI;

    /* clipping */
    if (deg > STEERING_ANGLE_MAX) { deg = STEERING_ANGLE_MAX; }
    if (deg < STEERING_ANGLE_MIN) { deg = STEERING_ANGLE_MIN; }

    Serial.print("\r\nSteering angle = ");
    Serial.print((int) deg);

    if (wiiremote.buttonPressed(WIIREMOTE_ONE)) {

    myservo.write(155);
    //analogWrite(pwmPin,0);

    } if (wiiremote.buttonPressed(WIIREMOTE_TWO)) {

    myservo.write(10);
    //analogWrite(pwmPin,150);

    } if (wiiremote.buttonPressed(WIIREMOTE_LEFT)) {

    steering.write(10);

    } if (wiiremote.buttonPressed(WIIREMOTE_RIGHT)) {

    steering.write(155);

    } if (wiiremote.buttonPressed(WIIREMOTE_A)) {
    steering.write(90);

    } if (wiiremote.buttonPressed(WIIREMOTE_B)) {
    myservo.write(90);
    }

    return (int) deg;
    }

    //vim: sts=2 sw=2 ts=2 et cin

  • Paul Richards

    I have a usb host shield 1.0. Is this compatible with the 2.0 library on github?
    I am using a rocket fish dongle, and it says the Wiimote Bluetooth library started, but nothing happens when I press the 1 and 2 buttons.
    Is the usb host shield 1.0 still supported? Do you have a library for with a wiimote example?
    Do you have links to compatible usb dongles?

  • Macy

    Back to your comment, I had changed the MAX_SS to a 7 and then pin 10 worked. However, now the bluetooth doesnt want to work. What exactly is MAX_SS that it would affect my bluetooth now?

  • atthawit

    Hello sir

    Im interested in your car and i also do similar project with surveillance car but i dont know where i should start from.. So i want to know about arduino stuff that you used in this project it may help me buy the stuff..regard

Leave a Reply

  

  

  



You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">