This is the third part of a series of articles written to describe development of interface between Arduino and popular game controllers using USB Host Shield. Previous parts:
Revision 0.4 – 13th January 2010
Part 3. Develop the Bluetooth USB and HCI interface used in the support of the Wiimote and PS3 game controller, and also some utilities needed to analyse and configure these devices.
1. USB Interface
As before, we first look at the descriptors for the USB dongle using the USB_Desc sketch. The result is:
Start Device descriptor: Descriptor Length: 12 Descriptor type: 01 USB version: 0110 Device class: E0 Device Subclass: 01 Device Protocol: 01 Max.packet size: 10 Vendor ID: 0A12 Product ID: 0001 Revision ID: 0134 Mfg.string index: 00 Prod.string index: 00 Serial number index: 00 Number of conf.: 01 Configuration descriptor: Total length: 006C Num.intf: 02 Conf.value: 01 Conf.string: 00 Attr.: 80 Max.pwr: 32 Interface descriptor: Intf.number: 00 Alt.: 00 Endpoints: 03 Intf. Class: E0 Intf. Subclass: 01 Intf. Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 81 Attr.: 03 Max.pkt size: 0010 Polling interval: 01 Endpoint descriptor: Endpoint address: 82 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Endpoint descriptor: Endpoint address: 02 Attr.: 02 Max.pkt size: 0040 Polling interval: 00 Interface descriptor: Intf.number: 01 Alt.: 00 Endpoints: 02 Intf. Class: E0 Intf. Subclass: 01 Intf. Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 83 Attr.: 01 Max.pkt size: 0000 Polling interval: 01 Endpoint descriptor: Endpoint address: 03 Attr.: 01 Max.pkt size: 0000 Polling interval: 01 Interface descriptor: Intf.number: 01 Alt.: 01 Endpoints: 02 Intf. Class: E0 Intf. Subclass: 01 Intf. Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 83 Attr.: 01 Max.pkt size: 0009 Polling interval: 01 Endpoint descriptor: Endpoint address: 03 Attr.: 01 Max.pkt size: 0009 Polling interval: 01 Interface descriptor: Intf.number: 01 Alt.: 02 Endpoints: 02 Intf. Class: E0 Intf. Subclass: 01 Intf. Protocol: 01 Intf.string: 00 Endpoint descriptor: Endpoint address: 83 Attr.: 01 Max.pkt size: 0011 Polling interval: 01 Endpoint descriptor: Endpoint address: 03 Attr.: 01 Max.pkt size: 0011 Polling interval: 01
The device descriptor is straight forward, but the configuration descriptor shows two interfaces and the second interface has alternate settings. The usage of the different endpoints is described here: Bluetooth Endpoint Usage
The second interface (interface one) is used for isochronous bandwidth related to carrying voice channels and we do not use this for Bluetooth HID, so they will be ignored.
We have four endpoints to consider:
The control endpoint (endpoint 0): This is used to send control messages and HCI commands.
The interrupt endpoint (endpoint 0x81): Where HCI events are received from the USB dongle.
The input endpoint (endpoint 0x 82): The bulk endpoint where ACL reports are received from the connected Bluetooth device.
The output endpoint (endpoint 0x02): The bulk endpoint where ACL reports are sent to the connected Bluetooth device.
These four endpoints discovered are registered as pipes to the USB Host library.
/* Initialize data structures for endpoints of device 1*/ ep_record[ CONTROL_PIPE ] = *( Usb.getDevTableEntry( 0,0 )); //copy endpoint 0 parameters ep_record[ EVENT_PIPE ].epAddr = 0x01; // Bluetooth event endpoint ep_record[ EVENT_PIPE ].Attr = EP_INTERRUPT; ep_record[ EVENT_PIPE ].MaxPktSize = INT_MAXPKTSIZE; ep_record[ EVENT_PIPE ].Interval = EP_POLL; ep_record[ EVENT_PIPE ].sndToggle = bmSNDTOG0; ep_record[ EVENT_PIPE ].rcvToggle = bmRCVTOG0; ep_record[ DATAIN_PIPE ].epAddr = 0x02; // Bluetooth data endpoint ep_record[ DATAIN_PIPE ].Attr = EP_BULK; ep_record[ DATAIN_PIPE ].MaxPktSize = BULK_MAXPKTSIZE; ep_record[ DATAIN_PIPE ].Interval = 0; ep_record[ DATAIN_PIPE ].sndToggle = bmSNDTOG0; ep_record[ DATAIN_PIPE ].rcvToggle = bmRCVTOG0; ep_record[ DATAOUT_PIPE ].epAddr = 0x02; // Bluetooth data endpoint ep_record[ DATAOUT_PIPE ].Attr = EP_BULK; ep_record[ DATAOUT_PIPE ].MaxPktSize = BULK_MAXPKTSIZE; ep_record[ DATAOUT_PIPE ].Interval = 0; ep_record[ DATAOUT_PIPE ].sndToggle = bmSNDTOG0; ep_record[ DATAOUT_PIPE ].rcvToggle = bmRCVTOG0; Usb.setDevTableEntry( BT_ADDR, ep_record ); |
The VID and the PID of the Bluetooth dongle should be checked to ensure compatibility. The CSR is the only dongle currently supported, but others have been found compatible and may be added later.
The device is configured and the interface 0 then set. At this stage we have communication with the Bluetooth dongle and can now start to communicate over Bluetooth.
2. Listen while we talk
We are now in a position to send HCI commands to the Bluetooth dongle over the control pipe, but first need to set up a process to read the interrupt pipe regularly. The events received on the interrupt pipe may not be directly related to the commands sent, so they must be processed as they arrive. As the USB host, we control the data transfers; we do not have to buffer large amounts of data, we only pull over the pipe what we can handle at any time. Also in the spirit of our “reduced host” for both USB and Bluetooth, we do no have to process all of the 36 possible events in the Bluetooth specification; we process only the ones we need for each application and ignore the rest. Significant events are communicated to the higher level routines through a set of flags.
We also commence reading the ACL input endpoint in case ACL events are ready there too. These are ignored until connection is made, but are read in case they block HCI events.
At this stage we handle only these HCI events:
#define EV_COMMAND_COMPLETE 0x0e #define EV_COMMAND_STATUS 0x0f #define EV_CONNECT_COMPLETE 0x03 #define EV_DISCONNECT_COMPLETE 0x05 #define EV_NUM_COMPLETE_PKT 0x13 #define EV_INQUIRY_COMPLETE 0x01 #define EV_INQUIRY_RESULT 0x02 #define EV_REMOTE_NAME_COMPLETE 0x07 #define EV_INCOMING_CONNECT 0x04 #define EV_ROLE_CHANGED 0x12 |
And we use these flags:
/* HCI event flags*/ #define HCI_FLAG_CMD_COMPLETE 0x01 #define HCI_FLAG_CMD_STATUS 0x02 #define HCI_FLAG_CONN_COMPLETE 0x04 #define HCI_FLAG_DISCONN_COMPLETE 0x08 #define HCI_FLAG_CONNECT_OK 0x10 #define HCI_FLAG_INQUIRY_COMPLETE 0x20 #define HCI_FLAG_REMOTE_NAME_COMPLETE 0x40 #define HCI_FLAG_INCOMING_REQUEST 0x80 //Macros for event flag tests #define hci_cmd_complete (hci_event_flag & HCI_FLAG_CMD_COMPLETE) #define hci_cmd_status (hci_event_flag & HCI_FLAG_CMD_STATUS) #define hci_connect_complete (hci_event_flag & HCI_FLAG_CONN_COMPLETE) #define hci_disconnect_complete (hci_event_flag & HCI_FLAG_DISCONN_COMPLETE) #define hci_connect_ok (hci_event_flag & HCI_FLAG_CONNECT_OK) #define hci_inquiry_complete (hci_event_flag & HCI_FLAG_INQUIRY_COMPLETE) #define hci_remote_name_complete (hci_event_flag & HCI_FLAG_REMOTE_NAME_COMPLETE) #define hci_incoming_connect_request (hci_event_flag & HCI_FLAG_INCOMING_REQUEST) |
3. Sending HCI Commands
To send HCI commands such as HCI reset we send a class specific output via the control pipe
// used in control endpoint header for HCI Commands #define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE #define HCI_COMMAND_REQ 0 void hci_reset(void) { hci_event_flag = 0; // clear all the flags buf[0] = 0x03; buf[1] = 0x0c; buf[2] = 0x00; HCI_Command(3 , buf); return; } //perform HCI Command byte HCI_Command( unsigned int nbytes, char* dataptr ) { hci_command_packets--; hci_event_flag &= ~HCI_FLAG_CMD_COMPLETE; return( Usb.ctrlReq( BT_ADDR, ep_record[ CONTROL_PIPE ].epAddr, bmREQ_HCI_OUT, HCI_COMMAND_REQ, 0x00, 0x00 ,0, nbytes, dataptr )); } |
4. Bluetooth HCI Utility
Our first sketch to access the Bluetooth dongle will be a utility to gather data from the Bluetooth dongle itself and also to make Bluetooth inquires and connections. The sketch is structured as a state machine to maintain non blocking behavior and so enable the event task to run regularly. The blueutils sketch is loaded into the Arduino, and a CSR bluetooth dongle connected to the USB shield. Running the sketch returns the following over the serial port:
freeMemory() reports: 1513 CSR Initialized HCI Reset complete ACL Data Packet Length: 672 SCO Data Packet Length: 48 Total ACL Data Packets: 4 Total SCO Data Packets: 1 HCI Version: 3 HCI Revision: 3164 LMP Version: 3 Manufacturer Id: 10 LMP Subversion: 3164 Local Name: Local Bluetooth Address: 00158316C075 Search for devices Search complete Devices Found : 0 Wait for Incoming Connect Request
This confirms we are talking to the dongle and gives useful information especially the bluetooth address hardcoded into the dongle.
5. Connecting Wiimote Game Controller
The connection process is different for the Wiimote and the PS3, so we will look at these in turn.
The wiimote has two methods of connection know as soft connect and hard connect. We look at the soft connect mode here. In soft connect mode a connection is made from the Arduino to the Wiimote, and to enable this the Bluetooth address of the wiimote must be discovered.
The blueutils sketch is run again, and when the message comes on the serial port of “Search for devices”, the “1” and “2” buttons on the Wiimote are pressed simultaneously. The search will take about 10 seconds and at the end return something similar to:
freeMemory() reports: 1513 CSR Initialized HCI Reset complete ACL Data Packet Length: 672 SCO Data Packet Length: 48 Total ACL Data Packets: 4 Total SCO Data Packets: 1 HCI Version: 3 HCI Revision: 3164 LMP Version: 3 Manufacturer Id: 10 LMP Subversion: 3164 Local Name: Local Bluetooth Address: 00158316C075 Search for devices Search complete Devices Found : 1 Found BDADDR: 0022AA8A06A3 Class: 042500 Mode: 1 Offset: 69C9 Remote Name: 0 Nintendo RVL-CNT-01 Connected to device
Here the Arduino has found the Wiimote and used the discovered Bluetooth Address to make a connection to it.
6. Connecting PS3 Game Controller
The PS3 Game Controller connection process is the other way round. The PS3 controller make the connection to the Arduino. The PS3 controller does not respond to requests for inquiry or connection.
To initate the connection the PS3 controller needs to know the Bluetooth Address of the Arduino. MotioninJoy can be used to set a USB dongle address into the PS3 contoller or alternatively sixpair.c under linux. These read the USB dongle bluetooth address and set this into the PS3 controller.
Since we know the Arduino Bluetooth address from the utility above “Local Bluetooth Address: 00158316C075” and we have ability using PS3LCD or the PS3 library to set the host Bluetooth Address, we can also use that method.
When the PS3 is programmed with the correct USB dongle Bluetooth address, the following is dsplayed when the “PS” buuton on the PS3 Game Controler is pressed at the “Wait for Incoming Connect Request” prompt.
freeMemory() reports: 1513 CSR Initialized HCI Reset complete ACL Data Packet Length: 672 SCO Data Packet Length: 48 Total ACL Data Packets: 4 Total SCO Data Packets: 1 HCI Version: 3 HCI Revision: 3164 LMP Version: 3 Manufacturer Id: 10 LMP Subversion: 3164 Local Name: Local Bluetooth Address: 00158316C075 Search for devices Search complete Devices Found : 0 Wait for Incoming Connect Request Connected to device
Absolutely fantastic articles! When will parts 4 and 5 be avaiable? Great work! 🙂
Hi. I’m in my school’s robotics club and we’re following these guides to try and sync up a PS3 controller to an arduino board to control our robot. We have got the PS3LCD sketch to compile (finally) and now have absolutely no idea where to connect the pins? Is there a clear picture of how to connect it all up? We really need to know just what pins to plug into where from where and all that.
Any help would be incredibly appreciated. 🙂
Thanks so much and keep up the good work.
Sam.
Hi there,
Thanks for this amazing tutorial on interfacing the Wiimote with the Arduino.
I’m running into a snag with the blueutils sketch. I run the USB_desc sketch and obtain a device description for my CSR bluetooth dongle (the package isn’t quite the same as yours, but it is CSR, and has the same VID and PID as yours). However, when I load the blueutils sketch onto my arduino, I see this much on the Serial Monitor, and the program seems to get stuck:
freeMemory() reports: 1513
CSR Initialized
It will sit there indefinitely, and the HCI reset portion of the code doesn’t seem to be executed at all. Any thoughts on why this might be happening? Your help would be GREATLY appreciated!
Thanks again!
Hello,
I was trying to access the Bluetooth dongle using the blueutils sketch. Then, myy serial monitor gave me the following:
freeMemory() reports: 1513
CSR Initialized
No response to HCI Reset
I can’t figure out why it can’t respond to the HCI reset?
Hoping if anybody can help. Thank you!
Hi Jong,
Which shield are you using ? Circuits@home or Sparkfun ?
Which Arduino model ?
What is the power arrangement ?
What dongle ? Maybe you can send me a dump of the output from usb_desc sketch for your dongle ?
Richard
Hey, i found a couple of minor errors i feel i should point out. First, there are a couple of plus signs (++) at the beginning that shouldn’t be there. Second, Most of the important code in loop() is commented out. Third, in the HCI code on this page in HCI_Command there is a “amp;” which should probably be just “&”. Just minor stuff.
Thanks a lot for these articles. They are really helpful, i hope parts 4 and 5 come out soon.
Hi, I am learning basics of robotics, sensors, USB, Bluetooth, controllers etc.
These articles helped me a lot. I got hold of arduino board and usb host shield from sparkfun.
With some modifications to example code i was able to use wii remote to control my rover 🙂
Now I am exploring, how i can use wii nunchuk extension.
Thanks for these articles.
Hello! When I try to compile USB_Desc sketch I got errors, any one can help? Thanks x 10000!!!
Here is the log:
error: expected ‘,’ or ‘…’ before ‘str’ In function ‘byte getdevdescr(byte)’:
In function ‘byte getconfdescr(byte, byte)’:
In function ‘void printconfdescr(char*)’:
In function ‘void printintfdescr(char*)’:
In function ‘void printepdescr(char*)’:
In function ‘void printunkdescr(char*)’:
Cobbie
I’ve been looking all over for a way to remotely turn my Wii on and off using an Arduino. This has to be the closest I’ve found thus far. Have you been able to send a power command to the Wii using what you’ve done so far?
Rick
Hello,
I have tried to connect WiiRemote to USB Host Shield (SFE sku DEV-09628). So far I’ve just used Blueutils.pde. I got “Connected to device” message on serial monitor as described at section 5 in this article.
But sometime I can’t see the message. “Remote Name: 0 Nintendo RVL-CNT-01” message is the last one on serial in this case.
I’m trying to find what’s going on HCI events, but I don’t figure out yet. Please give me suggestion to get “Connected to device” message.
Tomo,
The blue leds on the wiimote need to be flashing during both discovery and the connection phases. You may need to press the buttons twice to keep them flashing.
Thank you very much for your quick response, Richard.
But I still don’t get “Connected to device” message mostly always. I’m sure blue leds are flushing. I measured duration: (1) HCI_Inquiry period is about 1394msec on my shield, (2) WiiRemote keeps flushing about 20sec. So I think press 1+2 buttons once after “Search for devices” is enough to find host each other.
From log, hci_state is in HCI_CONNECT_OUT_STATE but hci_connect_complete is 0x0.
I checked HCI events after hci_connect() execution, then found the followings:
event type = 0x05, status = 0xD // connection rejected
event type = 0x0F, status = 0x0 // command in pending
I need to figure out why I got connection rejected.
Please help me.
Just following up for my comment above.
When I got “Connected to device”, HCI events occurred as follows:
0x05 (Disconnection Complete)
0x0F (Command Status, 1 or several times)
0x03 (Connection Complete)
But when I don’t get “Connected to device” 0x03, HCI event keeps 0x0F and “rcode” is 0x4. This means USB Host has NAK in USB::dispatchPkt().
Why my Bluetooth USB dongle (I purchased it from SparkFun) sometimes doesn’t issue Connection Complete event?
Rick,
I don’t have a Wii, I just use Wiimote. So I didn’t try any communication to Wii.
While maybe not impossible it is likely more difficult to communicate with Wii, than Wiimote. As a slave, there are more messages from the Wii to respond to.
Some of this interaction is often made difficult or secure to deter 3rd party devices.
You may be better to make a hardware hack to a Wiimote from the Arduino.
Hi,
Thank you for posting these codes!!
I just tried using the blueutil sketch with the new sparkfun shield and it works alright.
However when I am trying wiiblue to get accerometor data, the serial output stops after CSR Initialized.
I checked the code and noticed that blueutil’s HCL_task function is different from wiiblue’s HCL task function….why is that?
Any help is appreciated!
Hi David,
I guess you might use incorrect Wiimote BD_Address. The wiiblue uses fixed BD_Address defined by the following:
/* Bluetooth Address of Wiimote */
unsigned char Wiimote_bdaddr[6] = { 0x00, 0x22, 0xaa, 0x8a, 0x06, 0xa3};
But the Blueutils uses HCI_INQUIRY to discover controllers so that you can see the address of your Wiimote.
You can choose:
1) get your Wiimote BD address by Blueutils then set the address into wiiblue.
2) write HCI_INQUIRY command into wiiblue.
Hope this helps,
Tomo
Thanks Tomo!!
I got it working after entering the correct DB address of my Wiimote.
I am trying to understand the wiiblue code as I wish to extract IR sensor datas. However I have small-none knowledge in HCI&L2CAP….
I am trying to find out at which part of the code was the wiimote report(type 0x37) masked out to be button’s data only…?
Also, is the IR Sensor enabled by the setup used in the code?
Another bad news I found out is that to see the intensty of the IR camera we would need to request the report type 0x3e/0x3f…however the report form is interleaved lol….
The full HID report data is present in the data buffer, you just have to pick out what you want.
Likewise for interleaved reports, just check the report number and pull out the data as needed.
Biggest challenge for camera was the setting of the memory and register values. I did get camera working, but not very robust code. Concerned about sharing in this state, cos I don’t want to scramble memory in folks Wiimotes !
Thanks for the info, I think I know how to pick out the data I want in buf, as well as writing report to enable the IRcamera, I am trying to figure out at how to write to the memory and register values to configure the camera though….without configuring the camera, the output I get in the report are all 0xFFs.
Thanks, any info is appreciated!
Hello. My sketch based on wiiblue.pde does not run what I expected. In the “myapp()”, my code is doing:
void setup()
{
servo.attach(2);
}
void myapp(void)
{
int angle = get_servo_angle(); // from Wiimote Accel
int pulse = map(angle, 0, 180, 1300, 1800);
servo.writeMicroseconds(pulse);
delay(15);
Serial.println(pulse);
}
When I disconnect servo signal cable from D2 (I also tried D3, D4, D5 and D6), my sketch runs good as I expected (I mean I can see pulse value on the Serial Monitor). But when I connect the cable to D2, display speed on the Serial Monitor is getting very slow and Wiimote is disconnected after a while.
Your help would be greatly appreciated.
Hello again.
I tried to use external 5V for the servo instead of Arduino’s onboard 5V coming from USB, then my sketch works.
I guess 5V on Arduino from USB does not has enough current for servo. Is my guess correct?
Your help would be greatly appreciated.
hy
i have the same problem as david had. Blueutils works, but wiiblue stops at CSR Initialised.
I changed the Bluetooth address from Wiimote in wiiblue as said by tomo.
overall i just changed the PID,VID an Bluetooth address from Wiimote in the sketch.
is there anything else to change??
i have no cst bluetooth dongl, but the descripters were the same as in the example from oleg(exept PID,VID)
Hey olaf
I am using the shield for communicating with the wiimote and a modified version of wiiblue.pde everything is working fine but there is one thing I can’t fix that happens in the original aswel as in the modified version. But after a while the wii accelerometer readings have a huge delay, in the beginning everything is fast and good but after some time the readings start to slow down Big time. Is there something you know that could cause this delay? Personally I think some kind of buffer that is full.
Please help because it is vital for the project and I don’t have the knowledge to fix it.
hy.. problem not solved yet.
I tryed to write the L2CAP funktions into the Blueutils sketch because hci connection worked.
L2CAP connection seems to be initialised, but i only get a “Unmanaged Event:D” on Serial monitor;
what could that mean?
The Problem might just be the dongl, becaus hardware should be the same as olegs. I just couldnt find a CSR dongl.
but i really don´t what exactly could be the problem.
Any advice what i should do next?
Thanks..
Hello.
“Unmanaged Event:D” means that QoS Setup Complete Event, which is used to indicate the completion of the process of the Link Manager setting up QoS with the remote controller. What is the status on this event? You can check the status for buf[2]. But as you may know, wiiblue.pde does nothing on the event.
Sorry but I have no idea for you so far… Could you check HCI and L2CAP event on your wiiblue sketch to see what type of event is in event pipe?
Hy many thanks for answering,
could you explain, how i can check the pipes?
(..i do not have much experience with that programming language.)
I tried to check the programm status over the serial-console,
I tried Serial.println(“hci_event_flag”) and Hterm gives out: 0x31 0x31 0x38
l2cap_event_status seems to be 0x3F
Sorry for confusing…
I mean that you can write the following example codes
Serial.print("USB event pipe = ");
Serial.println(buf[0]);
right after
rcode = Usb.inTransfer(BT_ADDR, ...);
in HCI_event_task() and l2cap_event_task() functions.
I just want to make sure why your code does nothing on HCI and/or L2CAP event.
Also I can share my WiiRemote library based on (and almost the same as) Oleg’s wiiblue.pde but I added a few codes for me. Does anyone have good web site to share my code?
hy, thanks again
i read the pipe as you saind, the output is horrible to read in hterm, but thats what i could find out:
1)the blueutils.pde witch L2CAP methods added:
after “connected to device” there is only 0x02 and 0x13 in the pipes and the tasks seem to work correctly until->. In L2CAP_task case L2CAP_CONTROL_CONFIGURING_STATE: there is
HCI=0x13,L2CAP0x02,
HCI=0x02,L2CAP0x02,
HCI=0x13,L2CAP0x13,
HCI=0x13,L2CAP0x13,
HCI=0x13,L2CAP0x13,
HCI=0x13,L2CAP0x13,
HCI= Unmanaged event: D L2CAP0x02,
HCI=0x02,L2CAP0x02,
HCI=0x13,L2CAP0x02,
than the first time L2CAP_READY_STATE is set and then HCI=0x02,L2CAP0x02 in every loop.
2) in the wiiblue.pde
after CSR initialised its
HCI=0x12,L2CAP=0x12 a few times; HCI=0x03,L2CAP=0x03 two times; HCI=0x0E,L2CAP=0x05 ;
then HCI=0x0F,L2CAP=0x0F all the time
i only know http://www.file-upload.net/ for sharing files.
If you are plannign to make your code public, sourceforge.net might be interesting to you..
Hey Tomo
Have you also solved the problem of a delay getting bigger over time in your library? Because when I use wiiblue.pde and have it display the readings constantly, at first its fast as it should but after a while(10sec) their is like a second delay between the readings and displaying them. Its not the displaying that is slowing the code down because I have try’d serial displaying lcd displaying even displaying it trough another arduino using I2C but the delay keeps happening.
I can’t test the library atm but if you did could you explain where the delay came from?
Tijmen
When I verify wiiblue.pde I get this problem.
In file included from C:\arduino-0021\libraries\usb_host\Max3421e.cpp:3:
C:\arduino-0021\libraries\usb_host\/Max3421e.h:11: error: expected class-name before ‘{‘ token
I don’t solve this problem.
Help me please.
Thanks so much.
kik
Where did you get your MAX code from?
https://github.com/felis/USB_Host_Shield/blob/dev/Max3421e.h
Oleg
kik
That’s development version, try this instead -> https://github.com/felis/USB_Host_Shield
Thank you for your advice Oleg.Next probrem about Bluetooth.I have to use Bluetooth that you advise in Part1(Bluetooth dongle picture)or anyelse that has BC41B143A.Now I have another Bluetooth it tells me wrong ID.
Now I have a new problem.On seriel port. No respose to HCI Reset Data package error:4. Who have ever found this problem?
Help me please.
Thank you.
Harry,
I uploaded my codes, please try this.
Here is dump of SteeringWii.pde on my environment:
freeMemory() reports: 1404
CSR Initialized
HCI event = 0xE
HCI Reset complete
HCI event = 0xF
HCI event = 0x3
HCI event = 0xF
HCI event = 0x3
Connected to Wiimote
HCI event = 0x13
L2CAP Signaling Command = 0x3
L2CAP Signaling Command = 0x3
HCI event = 0x13
L2CAP Signaling Command = 0x5
L2CAP Signaling Command = 0x4
HCI event = 0x13
L2CAP Signaling Command = 0x3
HCI event = 0x13
L2CAP Signaling Command = 0x5
HCI event = 0x13
L2CAP Signaling Command = 0x4
HCI event = 0x13
HCI event = 0x13
HCI event = 0xD
Unmanaged Input Report: 30
HCI event = 0x13
Steering angle = 89
HCI event = 0x13
Calibration Data
X0 = 1EB
Y0 = 1EB
Z0 = 1ED
XG = 251
YG = 252
ZG = 254
Steering angle = 89
p.s. I was wrong about variable for L2CAP event. It is buf[8] rather than buf[0].
hy, thanks for answering
i checked with arduinos IDE Serial Monitor:
CSR Initialized
HCI event = 0xE
HCI Reset complete
HCI event = 0xF
HCI event = 0x3
Connected to Wiimote
HCI event = 0x13
L2CAP Signaling Command = 0x3
L2CAP Signaling Command = 0x3
HCI event = 0x13
L2CAP Signaling Command = 0x5
L2CAP Signaling Command = 0x4
HCI event = 0x13
L2CAP Signaling Command = 0x3
there it stops
by the way: is there any way to make sure, my bluetooth dongle is compatible to the programm?
Hey Tomo
Have you also solved the problem of a delay getting bigger over time in your library? Because when I use wiiblue.pde and have it display the readings constantly, at first its fast as it should but after a while(10sec) their is like a second delay between the readings and displaying them. Its not the displaying that is slowing the code down because I have try’d serial displaying lcd displaying even displaying it trough another arduino using I2C but the delay keeps happening.
I can’t test the library atm but if you did could you explain where the delay came from?
Tijmen
Hello,
Sorry I haven’t use LCD for my Wiiremote project. As you may know, Serial library is basically slow, but I don’t believe Serial delays a second.
I’m not sure where you got the delay in the wiiblue.pde. Could you clarify more detail? Also I don’t understand what you said “I can’t test the library atm”.
Yeah that i couldn’t test your lib at the moment.
But the delay is not coming from the serial print or lcd print or wire communication. But the thing is that when I move the wiimoment it takes a second or 2 (or even more) before the X and Y values change. the delay sometimes gets bigger over time it’s weird but you don’t have this problem?
But the library looks nice and clean and it works. Although I am trying to modify it a bit to put out a unprocessed reading it is very good.
I’ve never had such kind of delay printing issue on serial monitor with wiiblue.pde. Did you try to stop serial/lcd print? Do you still have the problem with no print? You can use LED, Servo or so to make sure the response.
i got Error: OSCOKIRQ failed to assert; I just tried to reset the whole thing till it works again; and suddenly the programm worked!, even accelerometer data was given out on the Serial; after 30 rows accleerometer data or so it stopped and does nothing. I made another tries, but alwasy Error: OSCOKIRQ failed to assert now…
sometimes there comes csr initialised
and packet error: FF or packet error: D
also one time it came to hci reset..
Harry
Please read the followings:
Arduino USB host – First programs
Sparkfun
Hy,
I supplied the Board with 7.5V now.. but somehow it woudldt connect to wiiMote.
Is ther a way to check the Serial Port and With external Supply at the sam time?.. so i coudl check the programm progress..
i think i it might damage my pc if i use bot USB supply and External at the same time..
thank you very much.
Yes you can do this without damaging your pc at least for the duemillanove and above (I haven’t tested earlier versions)
And I believe olaf has made a post about troubleshooting the usb host shield somewhere maybe look it up?
Who can use and success from wiiblue.pde. Please Tell me about the result of wiiblue.pde since my result is freeMemory report:583
CSR Initialized on serial port.
Then I try to edit sourcecode afterthat my result is freeMemory report:583
CSR Initialized
HCI Reset complete
Thank you so much.
I am using the library of tomo but had to change 2 things 1 was that the command for setting the BD adress
was wrong in the example but okay it is easy to fix and you micht want to disable the debug info send out by void parseAccel.
And by some miracle the delay is gone after I stripped the code down because I only need the X and Y from the acceleremoter.
Hello Oleg,
I appreciate your awesome project. Here is my RC controlled by WiiRemote: YouTube
My son loves this. I’ll add ultrasonic sensor to prevent collision and some more for my son.
I uploaded my library to github. This is based on Oleg’s wiiblue.pde.
This is very nice project. I also like your code – I’m going to make a post about it today!
Hy, just wanted to check the comments, then i saw that my post from yesterday seems to be nowhere; so probably i am posting this two times…
I tryed some programms on my board with external power supply, but there are still probremls.
Sometimes i have to disconnect power supply and load the sketch to the board again, otherwhise the programms
output stopps at the first row (SteeringWii: WiiRemote init())
Wiiblue:
..is only progressing till CRS Initialised
Steering Wii:
WiiRemote::init()
CSR Initializedreset state
reset state
reset state
HCI event = 0xEreset state
HCI Reset completeSetup packet error: FF
after reset i have to load the programm new otherwise it stops at csr initialised.
There is something i do not fully understand yet. I read the artical on this website but i could not find what i was searching for.
Which of the USB_Desc.pde descripors are important?
I only changed VID,PID yet.
What is EP_Interrupt,EP_Bulk,EP_Poll and how is it called in USB_desc output?
In the sketch these attributes are named differently..
Ones while testing i just decided to check reconnect the host shield with the board, it seems to me that afterwards the programm progressed further, but had the same effekt as reconnecting power supply..
i am going to test the hardware again.
thanks you so much for helping
Basically, all of the descriptors, which are defined in wiiblue.pde as shown below, are important.
#define BT_ADDR 1
#define CSR_VID_LO 0x12 // CSR VID
#define CSR_VID_HI 0x0a
#define CSR_PID_LO 0x01 // Bluetooth HCI Device
#define CSR_PID_HI 0x00
#define BT_CONFIGURATION 1
#define BT_INTERFACE 0 // Only use interface 0
#define BT_NUM_EP 4
#define INT_MAXPKTSIZE 16
#define BULK_MAXPKTSIZE 64
#define EP_INTERRUPT 0x03 // endpoint types
#define EP_BULK 0x02
#define EP_POLL 0x01 // interrupt poll interval
You need to check your USB device descriptor by using descriptor_parser.pde or USB_desc.pde. I like the descriptor_parser output.
As far as I know about your comment that “after reset i have to load the programm new otherwise it stops at csr initialised.”, hardware reset on Arduino (or USB Host Shield) does not work well while Serial port is used for monitoring. I didn’t dig for this symptom but I usually detach USB cable from PC on each execution when I’m using serial monitor. The hard reset, however, works good when I use arduino+usb_host_shield off from PC.
Can you post the data from the descriptor of your device so we can take a look ?
Hy Richard.
this ist the output on serialmonitor of descriptor_parser.pde
Start
Device addressed… Requesting device descriptor.
Device descriptor:
Descriptor Length: 12
USB version: 1.10
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Max.packet size: 10
Vendor ID: 0E5E
Product ID: 6622
Revision ID: 0134
Mfg.string index: 00
Prod.string index: 00
Serial number index: 00
Number of conf.: 01
Configuration number 0 //note: BT_Configuration?
Total configuration length: 108 bytes
Configuration descriptor:
Total length: 006C
Number of interfaces: 02
Configuration value: 01
Configuration string: 00
Attributes: 80
Max.power: 32 100ma
Interface descriptor:
Interface number: 00
Alternate setting: 00
Endpoints: 03
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 01 Direction: IN
Attributes: 03 Transfer type: Interrupt
Max.packet size: 0010
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 02 Direction: IN
Attributes: 02 Transfer type: Bulk
Max.packet size: 0040
Polling interval: 00 0 ms
Endpoint descriptor:
Endpoint address: 02 Direction: OUT
Attributes: 02 Transfer type: Bulk
Max.packet size: 0040
Polling interval: 00 0 ms
Interface descriptor:
Interface number: 01
Alternate setting: 00
Endpoints: 02
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 03 Direction: IN
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0000
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 03 Direction: OUT
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0000
Polling interval: 01 1 ms
Interface descriptor:
Interface number: 01
Alternate setting: 01
Endpoints: 02
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 03 Direction: IN
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0009
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 03 Direction: OUT
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0009
Polling interval: 01 1 ms
Interface descriptor:
Interface number: 01
Alternate setting: 02
Endpoints: 02
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 03 Direction: IN
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0011
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 03 Direction: OUT
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0011
Polling interval: 01 1 ms
Start
Device addressed… Requesting device descriptor.
Device descriptor:
Descriptor Length: 12
USB version: 1.10
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Max.packet size: 10
Vendor ID: 0E5E
Product ID: 6622
Revision ID: 0134
Mfg.string index: 00
Prod.string index: 00
Serial number index: 00
Number of conf.: 01
Configuration number 0
Total configuration length: 108 bytes
Configuration descriptor:
Total length: 006C
Number of interfaces: 02
Configuration value: 01
Configuration string: 00
Attributes: 80
Max.power: 32 100ma
Interface descriptor:
Interface number: 00
Alternate setting: 00
Endpoints: 03
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 01 Direction: IN
Attributes: 03 Transfer type: Interrupt
Max.packet size: 0010
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 02 Direction: IN
Attributes: 02 Transfer type: Bulk
Max.packet size: 0040
Polling interval: 00 0 ms
Endpoint descriptor:
Endpoint address: 02 Direction: OUT
Attributes: 02 Transfer type: Bulk
Max.packet size: 0040
Polling interval: 00 0 ms
Interface descriptor:
Interface number: 01
Alternate setting: 00
Endpoints: 02
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 03 Direction: IN
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0000
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 03 Direction: OUT
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0000
Polling interval: 01 1 ms
Interface descriptor:
Interface number: 01
Alternate setting: 01
Endpoints: 02
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 03 Direction: IN
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0009
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 03 Direction: OUT
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0009
Polling interval: 01 1 ms
Interface descriptor:
Interface number: 01
Alternate setting: 02
Endpoints: 02
Class: E0 Wireless Controller
Subclass: 01
Protocol: 01
Interface string: 00
Endpoint descriptor:
Endpoint address: 03 Direction: IN
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0011
Polling interval: 01 1 ms
Endpoint descriptor:
Endpoint address: 03 Direction: OUT
Attributes: 01 Transfer type: Isochronous, Sync Type: No Synchronization, Usage Type: Data
Max.packet size: 0011
Polling interval: 01 1 ms
Wiiblue.pde works now!
I just used a wrong dongle. My first one was Bluetooth 1.x, i thougt for that application i would do allright.
I bought a Bluetooth 2.0 Dongle and Wiiblue.pde worked fine…
Thank you for all the help!
I got a new WiiMoteController now, and the programe doesn’t work anymore.
Wiiblue Serial output is
freeMemory() reports: 1607
CSR Initialized
Connected to Wiimote
Unmanaged Event: 1B
Wiimote Disconnect
Connected to Wiimote
Unmanaged Event: 1B
i havent changed anything but the WiiMote controller..
I got the bluetooth adress due the Blueutils.pde (which works only from time to time).
how can i find out what Unmanaged Event: 1B means?
take a look at my finished product in which I used your usb host shield and examples.
http://letsmakerobots.com/node/26095/
This is one cool project – congratulations!
Thanks oleg I apreciate it! Hopefully more people will discover the posibility’s of arduino and the Wiiremote.
Ok…so I have the shield installed, blue tooth dongle in palce, the sketch running, and the wiimote is connected…How am I supposed to program the arduino to actually DO something with the wiimote?
I’ve been trying to get this working for over a year now, with the board revision changing and the arduino libraries being updated this is all very frustrating…
Have you seen this site already -> http://arduino.cc/ ? They talk about basics there – how to program Arduino and write sketches. The forum folks are quite helpful, too.
BTW, library revision 2.0 is not compatible with Richard’s wiimote code; you’d need to stay with the old one.
That’s where I get 90% of my information! 🙂
I’ve got the old code and I’ve got the right library, the demo sketch it uploaded and the wiimote and the arduino are talking…but thats where I’m confused. I’ve seen how you got the PS3 controller working, is there a similar library for the wiimote?
I’ve worked with my Arduino quite a bit, but I’ve never written my own library, just sketches for this and that. Is that something I may need to look into in order to get this working?
Also, will it be a problem if I’m using the newest version of the Arduino software? Should I be using 0018 for this? Currently I have been working with 0022, which comes with the newest SPI library preinstalled, which might be causing issues with the older code.
hey using the codes provided by the ps3 and wiimote part 3. im using the wii does dat mean that using the wii i can turn on and off the arduino(with host shield and dongle)
hey can someone tell me what IDE for the arduino were you using liked was it version 0022 0021 or older
0018 is probably the newest you can use
Hello, oleg. First of all congratulations and thanks for doing this tutorials. I’ve really enjoyed controlleing my arduino with the DS3. I would like to be able to control it now wireless via bluetooth. Is there any library that supports this? Are you going to make the last 2 parts of this tutorial? Thanks again.
Tutorials were written by Richard Ibbotson, I’m just hosting them. I don’t know his plans about other parts, sorry.
Hi Oleg,
Do you know if its possible to recognize a cell phone and send comands through bluetooth to the usb host shield with a bluetooth dongle? Have you tried something similar? I would like to implement some mobile processing apps if possible. thanks for any tips . kind regards, christo
I don’t have standard RFCOMM implementation for BT yet.
ohh but what protocol are you using to find other BT devices now? is it going to be available soon? I would love to try and experiment with it, but I am not sure I could develop it myself. thanks for the reply
Hello Richard,
I’ve been playing around wih your code today, thank you very much for the cool project and the attention you put into the documentation.
It did take me a bit of time to get it running though.
The code meeds Arduino18 and the old version of the spi-library, (Spi.h NOT the new SPI.h) it won’t run on anything past arduino19 as this is when this library was rewritten. An added difficulty is that the old verson of the library isn’t to be found on the arduino playground anymore.
Oleg was kind enough to mail it to me,
but it would be useful to add the info that the code was written for Arduino18 in a README on the Github.
Also, it makes sense to add the Spi-library the code uses to the download.
I’ve put it here:
http://www.repairablemachines.com/downloads/Spi_library_for_arduino18.zip
best,
Lieven Standaert, Belgium
PS: many thx to Oleg for the file
I was having problems with this library, so I’m glad that you’ve posted this. I’ve tried running blueutils.pde on Arduino18, but have had limited success. When running it, I get an error about java. It says something like “java.lang.NullPointerException at processing.app.debug.Compiler.Compile at….”
Any ideas?
I’ve gotten all of the code to run (USB_desc and blueutils) on my Arduino Uno and Sparkfun USB Host Shield. I want to be able to control servos with the Wiimote buttons (and eventually the accelerometer). Which sketch should I use and/or edit for my purposes? I’m kind of new to this whole programming thing, and I’ve not seen any guides on how to control servos with a Wiimote (the actual remote). I have seen lots of projects on the Nunchuck and the Wii to the Arduino via laptop (bluetooth). Is there a way to do it without a laptop?
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.
Hi Oleg,
Can you help me? 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.
If any one can help that would be great.
Hi !
I’m using the USB host shield in order to communicate with a PS3 remote and sometimes I get this error message : “no response to hci reset”. I noticed that in order to get this problem solved, I have to reset the card and to unplug the dongle and then replug it in the USB port and then it works again perfectly.
I want my Arduino to do this on his own, so i was thinking about cutting a usb wire in half and passing the data and Vcc wire through 3 Mosfet, using 3 output of the arduino to virtually unplug the dongle when it’s necessary. However, I don’t know how to get the information that there is “no response to hci reset”. Is there any boolean or any function that I could use ?
Exemple of what I would do :
if(“no response to hci reset”)
{
//virtually disconnect the dongle thank to the mosfet
digitalWrite(data1, low);
digitalWrite(data1, low);
digitalWrite(data1, low);
}