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.
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
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
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
(button (2) and (1) on the wiimote i meant (2) for forward driving and (1) or (b) for backwards.)
and with what can i powerup the arduino board?
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.
I will take a look at it in the near future, I promise! 🙂
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.
Take a look at the BTD class on how to initialize the dongle: https://github.com/felis/USB_Host_Shield_2.0/blob/BTD/BTD.cpp and then you can just use a modified version of the PS3 class and then just modify the part that reads the input: https://github.com/felis/USB_Host_Shield_2.0/blob/BTD/PS3BT.cpp#L367-393.
You have to read the calibration and set the mode like so: https://github.com/sudar/WiiRemote/blob/master/WiiRemote.cpp#L573-604
And then you can read the input like so: https://github.com/sudar/WiiRemote/blob/master/WiiRemote.cpp#L815-858
I haven’t got my hands on a Wiimote myself, but I will in the next couple of weeks!
Do I have to put these all into one script? Also, the last three, do i just copy the highlighted yellow sections or take the whole code? Thank you for your help.
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).
I will borrow a Wiimote from a friend tomorrow, so I should have written the finished library in only a matter of days!
Regards
Lauszus
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
Lauszus,
any updates??
Yes, I’m working on it right now 🙂 Sorry you haven’t heard from me, I have been quite busy lately.
I just added support for the Wiimote.
See the updated library at github: https://github.com/felis/USB_Host_Shield_2.0
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.
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’
It looks like that you are not running my library? Download the newest version from Github: https://github.com/felis/USB_Host_Shield_2.0 rename the library to something like “USB_Host_Shield_20” (or the Arduino IDE can’t load it) and then open up the example sketch: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/Wii/Wii.ino by going to File>Examples>USB_Host_Shield_20>Bluetooth>Wii
Once I download the library and open the sketch, do I need to Import the library I just downloaded?
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! 🙂
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?
Thanks for all your help Lauszus.
which pin do i connect the motor to and which pin do i connect the sero to?
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=0x00. 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.
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.
which pin do i connect the motor to and which pin do i connect the servo to? (to repeat polarbears question)
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?
The code is not longer maintained by the developer. I recommend using the code I wrote, which is part of the library: https://github.com/felis/USB_Host_Shield_2.0/blob/master/Wii.cpp
Check out the example as well: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/Wii/Wii.ino
I am having trouble getting both the gas and steering to work. Could someone post their final sketch so that I can compare? Thanks
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
You can’t use pin 9 or 10 as they are used by the shield. See the following page for more information: http://www.circuitsathome.com/usb-host-shield-hardware-manual.
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?
Yes, but you need to modify the shield slightly. See the following bottom of the following page: http://www.circuitsathome.com/usb-host-shield-hardware-manual.
An example can be found in the github repository: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/Bluetooth/Wii/Wii.ino.
Here is a list of some compatible dongles: https://github.com/felis/USB_Host_Shield_2.0/wiki.
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?
You need to reroute pin 9 as well. SS (slave select) is used for the SPI communication. See this page for more information: http://arduino.cc/en/Reference/SPI.
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