I pleased to announce that after a long and difficult development period Human Input Device AKA HID class support has been added to USB Host Shield Library r.2.0 and is available on gitHub – I suggest downloading the whole directory, since some modifications has been also made to core files to accommodate a new class. HID devices include popular devices like keyboards, mice, joysticks, game controllers, bar code scanners, RFID and magnetic card readers, digital scales and UPSes, to name a few.
I previously wrote about interfacing to HID devices here, here, and here. The code examples in these articles were written for legacy USB Host Shield library and can’t be compiled with current revision, however, the basic principles are the same – the device is periodically polled by the host and sends back data block called report containing changes in device controls (buttons, switches, jog dials etc.) since the last poll. Even though different devices have different report formats, for a certain device, report format is stored in the device in data structure called report descriptor. Therefore, it is possible to learn about device controls from the device itself by parsing its report descriptor.
There is one special case where report format is known in advance. Almost all HID keyboards and mice support so-called boot protocol intended for communication to very simple systems like PC configuration screen when computer runs from BIOS. Keyboard boot protocol report consists of 8 bytes containing state of modifier keys (CTRL, SHIFT,etc.) in the first byte, second byte being reserved, and up to 6 key scan codes in the rest of the report. Mouse boot protocol report consists of 3 bytes, first of which contains state of left, right and middle buttons and other 2 store X and Y travel since last poll.
In many cases boot protocol capabilities are more than enough for an Arduino project; for this reason, boot protocol class is the first to be released. To demonstrate operations of this class, 2 simple sketches has been developed, one for mouse, another for keyboard.
Sketches are designed for USB Host Shield 2.0 attached to compatible Arduino board. Also, it is recommended to use external power supply while working with HID devices – I’ve seen many devices which would refuse to function when Arduino receives power from its USB port only.
The operation of mouse sketch is quite simple: any mouse movement and/or button press causes a corresponding callback to be called. Below is the sketch output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 000200 dx=2 dy=0 000100 dx=1 dy=0 0002FF dx=2 dy=-1 020000 R Butt Dn dx=0 dy=0 000000 R Butt Up 020000 R Butt Dn 030000 L Butt Dn 020000 L Butt Up |
Sketch prints mouse report in hex and human-readable form. For example, lines 2 and 4 show mouse movement, lines 8 and 9 show first report when a button was pressed with no movement, the rest is just various button presses/releases.
The keyboard sketch is more advanced. It polls the keyboard, tracks key presses, converts scan codes to ASCII and also sends output report to turn keyboard LEDs on/off when CAPS LOCK, Num Lock, or Scroll Lock key is pressed. Here is the output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 00001A0000000000 DN >1A< ASCII: w 0000000000000000 UP >1A< 0000080000000000 DN >08< ASCII: e 0000000000000000 UP >08< 00000B0000000000 DN >0B< ASCII: h 00000B0700000000 DN >07< ASCII: d 00000B070A090000 DN >0A< ASCII: g DN >09< ASCII: f 0000070A09000000 UP >0B< 0000070900000000 UP >0A< 000007090B000000 DN >0B< ASCII: h 0000000000000000 UP >07< UP >09< UP >0B< 0000390000000000 DN >39< 0000390000000000 0000000000000000 UP >39< 0000390000000000 DN >39< 0000000000000000 UP >39< |
HID boot devices are quite common, inexpensive and easy to interface to Arduino using USB Host Shield. Two demo sketches should provide good example of HID boot class usage as well as serve as templates to incorporate into other projects. If you still have questions, please ask them in the comments – I will be glad to help. In coming weeks I’m going to write another article or two showing ways to use this new class. Stay tuned!
Oleg.
This is seriously Hardcore!
Hi,
i’m trying to run the Mouse Sketch but I always receive the following message:
Start
OSC did not start.
I’m using is an Arduino Mega2560 with the Sparkfun Usb Host Shield (http://www.sparkfun.com/products/9628) with your USB Host Shield Library 2.0 .
Do you know if there could be any incompatibility issue ?
Regards.
Sparkfun shield is not compatible with rev.2.0 of the code.
Same here with the Mega ADK
What exactly makes it so difficult to make this lib work on the Mega ADK ?
It’s the sparkfun Usb Host that is incompatible with rev2.0 of the code. Just stick to the old rev.
Hi Oleg, congratulations!
I’m always visiting Circuits at Home to keep myself tuned.
Every new post makes me awe on how you bring so many great things in so short time.
This one didn’t escape from that rule. Awesome!
Cheers!
I’m trying to use the USBHIDBootMouse.pde example from the GitHub repository. I have a standard Arduino UNO and a USB host shield from Circutis@Home with the following specifications:
Circuits@Home 2010
USB Host Shield
rev.2.0
07 Dec 2010
I’m able to “verify” (i.e. compile) the .pde file and upload it to the Arduino. However, I don’t see much output in the serial monitor and the little that I do see appears to be all garbled (e.g. “ú`í”). Even if the Usb.Init function is not working, I would expect it to print some sort of human readable message like “OSC did not start.”
Any clue as to what might be going wrong? I did a haphazard job of soldering the pins in place so I’m wondering if this output could be caused by bad connections (on a related note, the mouse doesn’t seem to be powered even though I’ve plugged the Arduino into an external power supply).
Thanks!
It looks like the garbled output was caused by the following line:
Serial.begin( 115200 );
The messages display correctly when I change the baud rate to 9600 (i.e. “Serial.begin( 9600 );”), but I’m sure that will probably cause other things to break.
it won’t break anything in this sketch – what do you see now?
Garbled output is most likely caused by serial speed mismatch. Set your terminal to 115200. You should expect some human readable output from the sketch even without a shield attached to Arduino.
You’re right. I had a mismatched baud rate. I’m now seeing:
Start
OSC did not start.
I’ve noticed that the mouse does not light up when I have it plugged in (as it normally would when plugged into a computer). Could this mean that the USB Host Shield has a band connection with the power pins on the Arduino? I’m wondering if I need to re-solder the headers.
typo in previous post: “band” should’ve been “bad”
I believe mouse would light up only after initialization, which is not happening due to OSC error. Check your soldering with a ohmmeter paying special attention to 2×3 header. If you can, make a good picture or two of your soldering job and send it to me.
I touched-up the solder on all of the headers and now the example works great! Thank you for your prompt responses.
HI, Ive ordered a USB host shield v2, in the hope that i can do something similar with midi via USB as shown in Colins Lab video http://blog.makezine.com/archive/2010/11/usbhacking.html
Ive reaslised thru comapring libraries that he was using the legacy earlier modem USB host card as his sketch will not compile with the new library.
Do you have any advice or docs on what needs to be modified.. im pretty new to Arduino and C, and feeling a bit out my depth at the moment with this part of my project,which needs simple midi note messages to be passed to start and switch between other parts of code.
Any help or advice greatly appreciated..
compile errors if that helps.
LPK25_Host_pde.cpp:8:73: error: Spi.h: No such file or directory
LPK25_Host_pde:75: error: ‘EP_RECORD’ does not name a type
LPK25_Host_pde.cpp: In function ‘void setup()’:
LPK25_Host_pde:91: error: ‘class MAX3421E’ has no member named ‘powerOn’
LPK25_Host_pde.cpp: In function ‘void LPK25_init()’:
LPK25_Host_pde:116: error: ‘ep_record’ was not declared in this scope
LPK25_Host_pde:116: error: ‘class USB’ has no member named ‘getDevTableEntry’
LPK25_Host_pde:130: error: ‘class USB’ has no member named ‘setDevTableEntry’
LPK25_Host_pde.cpp: In function ‘void LPK25_poll()’:
LPK25_Host_pde:174: error: ‘ep_record’ was not declared in this scope
USB Host shield r.2.0 will work with legacy library. If you just need MIDI functionality, use legacy library with Colin’s code. The structure of new library is very different from the old one, you can’t make old code compatible with new library.
oleg,
I was beating my head against this for 2-3 hours tonight and finally found this post. Now I finally have my MIDI controller being recognized based on Colin’s code.
What is the likelyhood of getting an updated version of Colin’s MIDI code to work with the r2.0 libraries? (or even the PS3 code?)
I’m still an Arduino noob, so any help would be appreciated.
I’m not planning MIDI in 2.0.
OK..
Do you mean that you’re not going to code anything MIDI specific in 2.0? Or that it won’t be possible to do MIDI in 2.0?
Assuming the former, it would still be great to see some sample code with the new v2 libraries that could be adapted to do MIDI like what Colin did with the old libraries and the PS3 sample code.
I don’t have plans to implement MIDI myself.
Oleg,
Thanks for the quick response. I read elsewhere on your site that your modified SPI lib is no longer needed with V2 card. Do i need to use your modified spi.h lib if running the older usb lib ?
If so would you mind passing me a link.. have looked and cannot seem to locate it.
Using old library and with the Spi.h removed from the sketch compiles fine so im very happy 🙂
again – many thanks for your help
joe
Here’s the link to the ltest version of the old library -> https://github.com/felis/USB_Host_Shield . SPI support is built-in, you don’t need to
#include Spi.h
in your sketch.Oleg.. Thanks got the lib, but wasn’t sure about SPI built in part – will let you know how it turns out.. cheers.joe
I found this link it may be handy to others, I hope it is ok to share it here as a post, else at least I tried. Great site and support Oleg. I have both shields !
http://arduino.cc/forum/index.php?topic=73735.0
I’m not sure where is the best place to post this:
http://dangerousprototypes.com/docs/USB_IR_Toy:_Sampling_mode
I’ve got it working with your shield.
But sometimes it misses data using acm_terminal sketch.
Up to 50 bytes in a row.
Any ideas why?
Seems the IR toy sends FF 6x when its send buffer fills up. The USB host is too slow and somehow gets behind in the middle of each message. How can I modify acm_terminal to be faster? Can I change the Uno buffer to prevent buffer overflow on the other device?
I’m going to buy one to try it myself. As far as speed, there are some delays in acm_terminal and the whole send loop which is no necessary, you can play with them.
Will do! Let me know when you get yours, and what you changed in the code…
Hi,
I just wanted to say thanks for your work. I have spent all day trying to get my arduino 2560 + usb shield + android phone to talk to each other. Alas, it was a bridge to far.
It was great to be able to download your library and sketch and successfully compile something without errors that worked first time (example mouse sketch).
Cheers.
Hi, Thanks for your work.
But when I try to do anything with the code, I get the “Poll: FF ” error or something.
For example: i change the following function to:
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
Serial.println(“L Butt Dn”);
pinMode(leftServoPin, OUTPUT);
digitalWrite(leftServoPin, HIGH);
};
The same with the Servo library. Any ideas ?
what are you trying to do?
Hi,
First of all ,hats off for your work here.
I am able to get the HID class working both for mouse and keyboard using your software.But in both of the programs a polling error “Poll:ff” comes almost at the same time.
Once the polling error appears I have to power on\off the VIN at USB shield again to get the code working again.
Can you suggest anything that could be done here.
Once I get this working I going for ADK sample code. 🙂
Cheers and Thanks:)
I’m using Arduino UNO with latest USB shield and latest version of the library. I can successfully upload most of the examples apart from
USBHID_desc where I get the following error
Binary sketch size: 30256 bytes (of a 32256 byte maximum)
avrdude: stk500_recv(): programmer is not responding
Thanks
Hello,
Thanks for your contribution, it is great, the sketch worked and outputs as it should, but I need to get the mouse to actually work on the computer, how can I do that?
Oleg, I would like to ask you how can someone connect a USB gamepad (for example Logitech double action) that does not support boot protocol. The Mike McCauley’s library is not working with USBShield v.2.
The methods are implemented in HID class code – just use them.
Hi to all I have a question .
With sketch USBHID_des I have this error when I try to upload it only with IDE ver 1.0 :
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
avrdude: stk500_cmd(): programmer is out of sync
I think’s it because Binary sketch size is just a little more than 30 K : 30256 bytes (of a 32256 byte maximum)
I use an Arduino UNO and I don’T know how I can upgrade the bootloader
with Arduino 0022 skech size is only 296932 but I have this error avrdude: stk500_recv(): programmer is not responding
Second thing with USBHIDBootKbd sketch I plug logitech keyboard K360 and test it. All is OK
Now I try to know how using this sketch to run an action . I want to turn an pan and tilt motor to left or to right with the direction key of the keyboard
I don’t think USBHID_desc will fit into UNO. It may have small enough code but it uses more RAM than Atmega 328 can provide. It should fit into Mega.
To use keypresses modify
OnKeyDown()
,OnKeyUp()
callbacks to do what you need.OK I’ll buy the Arduino MEGA
hi,
is it posible to use USB hub to get two mouse output from USB host shield?
how to modified from the example USBHIDBootMouse?
this is a single mouse
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int x,xpos,y,ypos;
class MouseRptParser : public MouseReportParser
{
protected:
virtual void OnMouseMove (MOUSEINFO *mi);
};
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
xpos = mi->dX;
ypos = mi->dY;
if (xpos>0)
{
x++;
}
else if (xpos0)
{
y++;
}
else if (ypos<0)
{
y–;
}
};
USB Usb;
USBHub Hub(&Usb);
HIDBoot Mouse(&Usb);
uint32_t next_time;
MouseRptParser Prs;
void setup()
{
Serial.begin( 115200 );
Serial.println(“Start”);
if (Usb.Init() == -1)
Serial.println(“OSC did not start.”);
delay( 200 );
next_time = millis() + 5000;
Mouse.SetReportParser(0,(HIDReportParser*)&Prs);
}
void loop()
{
Usb.Task();
Serial.print (x);
Serial.print (‘\t’);
Serial.print (y);
Serial.println();
}
but i would like to get x and y with to mouse.
The way to use several identical devices is this: you create several instances of a device then, if parses are used, set parsers for them.
Helloo Oleg,
I’m trying to connect multiple keyboards to an usb hub connected to your cool usb shield v2. It works with one keyboard over the usb hub, but if I connect 2 usb hubs and use the code stated bellow, it doesnt work right: The problem is that if you type on a keyboard the first few chars are coming trough, but then it stalls and if you get lucky another few come true.
With one keyboard it works fine.
The code I’m using is:
USB Usb;
USBHub Hub(&Usb);
HIDBoot Scan1(&Usb);
HIDBoot Scan2(&Usb);
KbdRptParser getScan1;
KbdRptParser getScan2;
I started using separate ‘KbdRptParser’ to test if that would help. It doesn’t 🙂 The code behind the KbdRptParser is the same code as in your example.
in setup I have:
Scan1.SetReportParser(0, (HIDReportParser*)&getScan1);
Scan2.SetReportParser(0, (HIDReportParser*)&getScan2);
In the run I only have:
Usb.Task();
If I start the arduino and not type anything I get:
Start
BM Init
Addr:9
BM configured
Poll:FF
Poll:F0
Poll:1
Poll:1
Poll:1
Poll:1
Poll:1
Poll:1
Poll:1
Poll:1
Poll:FF
Poll:FF
Poll:FF
Poll:FF
Poll:FF
Poll:FF
BM Init
BM Init
Addr:A
BM configured
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:1
Poll:1
Poll:FF
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Poll:FF
Poll:1
Notice the BM init on Addr: 9 first and after a while on Addr: A.
If I start typeing I get
DN >0B37330F330B370907130B09070F13070B2C625A092C620709575A57<
Off course I can’t emulate the delayed behavior here 🙂
Both keyboards are:
HU Init
Addr:A
NC:1
Cnf:1
HU configured
0000: 05 01 09 06 A1 01 05 07 19 E0 29 E7 15 00 25 01
0010: 75 01 95 08 81 02 95 01 75 08 81 01 95 05 75 01
0020: 05 08 19 01 29 05 91 02 95 01 75 03 91 01 95 06
0030: 75 08 15 00 26 7F 00 05 07 19 00 29 7F 81 00 C0
Usage Page Gen Desktop Ctrls(01)
Usage Keypad
Collection Application
Usage Page Kbrd/Keypad(07)
Usage Min(E0)
Usage Max(E7)
Logical Min(00)
Logical Max(01)
Report Size(01)
Report Count(08)
Input(00000010)
Report Count(01)
Report Size(08)
Input(00000001)
Report Count(05)
Report Size(01)
Usage Page LEDs(08)
Usage Min(01)
Usage Max(05)
Output(00000010)
Report Count(01)
Report Size(03)
Output(00000001)
Report Count(06)
Report Size(08)
Logical Min(00)
Logical Max(7F00)
Usage Page Kbrd/Keypad(07)
Usage Min(00)
Usage Max(7F)
Input(00000000)
End Collection
I hope you can help. Let me know if you need more data.
Thanks.
Kind regards,
mtjs.
This is likely a bug. I remember similar symptoms reported by other developer trying to communicate with two mice. IIRC the remedy was to keep mice on different hubs. I need to look into this but it may take a while. In the meantime, try this remedy and see if it helps.
Hello Oleg,
Thanks for your swift reply. Darn it to be it a bug :). Can you give me an abstract to where I could search or what you think is the problem? That way I can see if I can’t fix it myself.
I also have the following problem: If you use the usb shield and a ethernet shield (both are working with changing the ss pins, also putting the ss pins high in the setup):
I put the Ethernet example code in your keyboard example, reading the analog inputs and show them in a webbrowser.
If you run it, the ethernet and usb initializes correctly. If I press keys on the keyboard it works as expected. But if I surf to the page (witch just gives 5 analog readouts) it is delayed with a few seconds. If I surf to the page and keep pressing keys on the keyboard, the page loads directly without delay as expected. It is just like the SPI is blocked somewhere (and guaranteed released when you press a key).
Any thoughts on that?
Thanks for your time. I appreciate it!
Kind regards,
Mtjs.
Something must be wrong with the Poll() method.
Oleg, Bravo. Your work on this has been super-human. Thanks for everything you have done.
I do have a simple question. Where is the documentation for the ptp and USBhost libraries?
I don’t mind RTFM, but I don’t know where the documentation is. (I’m getting a “OSC did not start” on a pre-built board.)
Thanks for all you have done!
Tom
Everything USB Host Shield related is linked to this page -> https://www.circuitsathome.com/arduino_usb_host_shield_projects . There is no docs for the USB library itself though, you need to read the source.
What is wrong with your shield – you shouldn’t be getting this error?
>What is wrong with your shield – you shouldn’t be getting this error?
Fine question. It came pre-populated. I soldered on the headers, but they look good. Oh, wait a minute. Dumb error. Sorry!
Note to others with “OSC did not start”. Maybe you forgot the SPI headers. Not all shields use them, but the host shield does. Be sure you soldered on the 2×3 SPI headers (double headers three places long.) They go on the bottom, opposite of the others headers you soldered on.
Thanks, Oleg!
What I am about to say is not meant to be a criticism of Oleg’s excellent work. But I continue to be frustrated by the lack of documentation for my USB host shield board. How to fix this?
Since the developer of the board has seen fit to not publish documentation for whatever reason, where is the natural place to put a crowd-sourced set of documentation? I assume a wiki-style document would let multiple authors add bits as they are able.
As one who is new to the USB Host shield, these are the documents I wish existed now.
1. Assembly instructions / hello world testing
2. Description of files in ptp library with sample output
3. Description of files in usbhost library with sample output
4. Explanation of various errors and solutions
5. Description of standard configurations with debugging info
For small (or one man) shops, documentation is often missing, because the developer is intimately familar with his project, so all the details above seem obvious. Cryptic commands or variable names seem to need no explanation. But when the larger world gets hold of it, nobody knows anything, which is frustrating.
What is the best way to deal with this?
The reason is lack of time. There are several people participating in the development, source code has been a good doc so far.
If you want to help writing the docs, write it and send it to me – I’ll post it.
I write the following with total respect for all your hard work, Oleg.
The source code is not documentation. None of the kinds of documentation I suggested is in the source code. In fact, the source has very little documentation in the source. For example, none of the sketches even have a title line or “here is what it does” line.
Perhaps a wiki could be created somewhere, so that many people can post the documentation? Me a little, you a little, others a little? Rather than one man write the documentation and one man post it, as you suggest. Are there others out there who can contribute?
Maybe a new thread could be started on this subject?
To give you an idea, here is a page started by a user of another shield, who took documentation upon himself when none was provided:
Again, please do not take my comments as negative criticism. All the massive hours you have put into this has created an incredibly useful and unique tool, for which I am grateful.
Can i use Usb host shield rev 2.0 in the robotic arm project …. keeping the code as is ?!
what the libraries should i modify to do that ?1
The USB Host Shield 2.0 is compatible with legacy library and examples written for this library; you won’t need to modify anything.
Ok Thank you ….
but i have a problem with USB Host shield rev2.0 when upload robotic arm project code to the arduino uno with Atmega 328p on the serial monitor i get “start”
and after that nothing written on the serial monitor … and sometimes i get
“setup packet error : f”
i tried USBHidBootMouse sketch and i get “OSC did not start”
so what is wrong ?!!!!!
Which shield are you using?
USB host Shield 2.0
Do you have all headers soldered on, including 2×3 one? Can you send a good picture of your setup to mazurov at circuitsathome dot com ?
than you oleg for your fast reply … i soldered 2×3 header
now i get another infinite loop error
” setup packet error : 7 mouse poll error 7 ”
?!
Send me the picture of your setup.
http://i39.tinypic.com/qpifr7.jpg
this is an image of my setup Usb host shield rev2.0 on arduino uno with atmega 328P
As you see i soldered 2×3 header and everything is okey
now I am trying to apply arm project on rev 2.0 which is in the picture
you told me that legacy libraries compatible with rev2.0
but when i connect the mouse on usb host shield i get
” setup packet error : 7 mouse poll error 7 ”
i tried to run “USBHIDBootMouse” sketch which is in the new libraries everything is okey ….. what i should do to make arm code working ?!
note : I did not make any hardware modifications on USb host shield only solderig the 2×3 header .
The solder joint on middle left pin of 2×3 looks bad – I suggest touching it up.
You can’t mix old and new library code in a single Arduino installation. Please load the test sketch, run, and post the output -> https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/board_qc/board_qc.pde
thank you oleg … i appreciate you and i like your caring 🙂
I exchange the libraries when testing … i did not mix it.
middle left pin of 2×3 i will touch it up bu it is connected i tested it by digital multi meter
i applied the board_qc test and this is the output
Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register… Die revision 03
SPI long test. Transfers 1MB of data. Each dot is 64K……………. SPI long test passed
GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
Test failed. Value written: 00 Value read: FF
Press any key to continue…
Press any key and the test will continue. If you have device attached the test should print its device descriptor at the end.
Circuits At Home 2011
USB Host Shield Quality Control Routine
Reading REVISION register… Die revision 03
SPI long test. Transfers 1MB of data. Each dot is 64K……………. SPI long test passed
GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
Test failed. Value written: 00 Value read: FF
Press any key to continue…
GPIO test passed.
PLL test. 100 chip resets will be performed
Resetting oscillator
Reset number 0 Time to stabilize – 688 cycles
Reset number 1 Time to stabilize – 690 cycles
Reset number 2 Time to stabilize – 688 cycles
Reset number 3 Time to stabilize – 688 cycles
Reset number 4 Time to stabilize – 690 cycles
Reset number 5 Time to stabilize – 688 cycles
Reset number 6 Time to stabilize – 690 cycles
Reset number 7 Time to stabilize – 688 cycles
Reset number 8 Time to stabilize – 690 cycles
Reset number 9 Time to stabilize – 688 cycles
Reset number 10 Time to stabilize – 688 cycles
Reset number 11 Time to stabilize – 688 cycles
Reset number 12 Time to stabilize – 688 cycles
Reset number 13 Time to stabilize – 688 cycles
Reset number 14 Time to stabilize – 688 cycles
Reset number 15 Time to stabilize – 688 cycles
Reset number 16 Time to stabilize – 688 cycles
Reset number 17 Time to stabilize – 688 cycles
Reset number 18 Time to stabilize – 690 cycles
Reset number 19 Time to stabilize – 688 cycles
Reset number 20 Time to stabilize – 690 cycles
Reset number 21 Time to stabilize – 688 cycles
Reset number 22 Time to stabilize – 690 cycles
Reset number 23 Time to stabilize – 688 cycles
Reset number 24 Time to stabilize – 690 cycles
Reset number 25 Time to stabilize – 688 cycles
Reset number 26 Time to stabilize – 690 cycles
Reset number 27 Time to stabilize – 688 cycles
Reset number 28 Time to stabilize – 690 cycles
Reset number 29 Time to stabilize – 688 cycles
Reset number 30 Time to stabilize – 690 cycles
Reset number 31 Time to stabilize – 688 cycles
Reset number 32 Time to stabilize – 690 cycles
Reset number 33 Time to stabilize – 688 cycles
Reset number 34 Time to stabilize – 690 cycles
Reset number 35 Time to stabilize – 688 cycles
Reset number 36 Time to stabilize – 690 cycles
Reset number 37 Time to stabilize – 688 cycles
Reset number 38 Time to stabilize – 690 cycles
Reset number 39 Time to stabilize – 688 cycles
Reset number 40 Time to stabilize – 690 cycles
Reset number 41 Time to stabilize – 688 cycles
Reset number 42 Time to stabilize – 690 cycles
Reset number 43 Time to stabilize – 688 cycles
Reset number 44 Time to stabilize – 690 cycles
Reset number 45 Time to stabilize – 688 cycles
Reset number 46 Time to stabilize – 690 cycles
Reset number 47 Time to stabilize – 688 cycles
Reset number 48 Time to stabilize – 690 cycles
Reset number 49 Time to stabilize – 688 cycles
Reset number 50 Time to stabilize – 690 cycles
Reset number 51 Time to stabilize – 688 cycles
Reset number 52 Time to stabilize – 690 cycles
Reset number 53 Time to stabilize – 688 cycles
Reset number 54 Time to stabilize – 690 cycles
Reset number 55 Time to stabilize – 688 cycles
Reset number 56 Time to stabilize – 688 cycles
Reset number 57 Time to stabilize – 688 cycles
Reset number 58 Time to stabilize – 688 cycles
Reset number 59 Time to stabilize – 688 cycles
Reset number 60 Time to stabilize – 688 cycles
Reset number 61 Time to stabilize – 688 cycles
Reset number 62 Time to stabilize – 688 cycles
Reset number 63 Time to stabilize – 688 cycles
Reset number 64 Time to stabilize – 688 cycles
Reset number 65 Time to stabilize – 688 cycles
Reset number 66 Time to stabilize – 688 cycles
Reset number 67 Time to stabilize – 688 cycles
Reset number 68 Time to stabilize – 688 cycles
Reset number 69 Time to stabilize – 688 cycles
Reset number 70 Time to stabilize – 688 cycles
Reset number 71 Time to stabilize – 688 cycles
Reset number 72 Time to stabilize – 688 cycles
Reset number 73 Time to stabilize – 688 cycles
Reset number 74 Time to stabilize – 688 cycles
Reset number 75 Time to stabilize – 688 cycles
Reset number 76 Time to stabilize – 688 cycles
Reset number 77 Time to stabilize – 688 cycles
Reset number 78 Time to stabilize – 688 cycles
Reset number 79 Time to stabilize – 688 cycles
Reset number 80 Time to stabilize – 688 cycles
Reset number 81 Time to stabilize – 688 cycles
Reset number 82 Time to stabilize – 688 cycles
Reset number 83 Time to stabilize – 688 cycles
Reset number 84 Time to stabilize – 688 cycles
Reset number 85 Time to stabilize – 688 cycles
Reset number 86 Time to stabilize – 688 cycles
Reset number 87 Time to stabilize – 688 cycles
Reset number 88 Time to stabilize – 688 cycles
Reset number 89 Time to stabilize – 688 cycles
Reset number 90 Time to stabilize – 688 cycles
Reset number 91 Time to stabilize – 690 cycles
Reset number 92 Time to stabilize – 688 cycles
Reset number 93 Time to stabilize – 690 cycles
Reset number 94 Time to stabilize – 688 cycles
Reset number 95 Time to stabilize – 690 cycles
Reset number 96 Time to stabilize – 688 cycles
Reset number 97 Time to stabilize – 690 cycles
Reset number 98 Time to stabilize – 688 cycles
Reset number 99 Time to stabilize – 690 cycles
Reset number 100 Time to stabilize – 688 cycles
Checking USB device communication.
Device connected. Resetting
Reset complete. Waiting for the first SOF…
Getting device descriptor
Descriptor Length: 12
Descriptor type: 01
USB version: 0110
Device class: 00
Device Subclass: 00
Device Protocol: 00
Max.packet size: 08
Vendor ID: 15D9
Product ID: 0A4C
Revision ID: 0100
Mfg.string index: 00
Prod.string index: 01
Serial number index: 00
Number of conf.: 01
All tests passed. Press RESET to restart test
The board is working. Load the mouse sketch and see if it works with your mouse -> https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootMouse/USBHIDBootMouse.pde .
i loaded the mouse sketch and it worked great …. but applying arm_mouse sketch in legacy library gives me this error
” setup packet error : 7 mouse poll error 7 ”
what should i do to make it works ?!!
i think the problem is in the legacy library …
what i should modify to make arm_mouse sketch working with new libraries ?!
Do you have any other mouse to try? Also, how do you power your Arduino?
Yes i tried another mouse but i have the same error
I power Arduino from the USB cable connected to the computer
Try it with external supply – mice are sensitive. I’ll also try to replicate your problem and post what I found.
Okey Thank you Oleg …. i will try external power supply
i will stay tuned here this week and i hope that I can find the solution and if i found it i will post it here….
I am here again i know that i asked too many questions
i tried using external power but i have the same result
i tried the descriptor in legacy library but it didn’t work
but the descriptor in the new libraries work great so now i believe that the problem is in legacy library
i tried to modify arm_mouse sketch to make it working in the new libraries but i have no luck because its too complex to understand without documentation:(
can you make your modification in arm_mouse sketch in legacy library and added it to the USB Host shield 2.0 examples on github ?!!
I’ll see what I can do.
Oleg …… i hope that i am not annoying you with my questions
To enable arm_mouse running in the new libraries the descriptors and reports in the new libraries modified by you so i think this part of code in arm project that should modified … ?!
void loop()
{
byte rcode;
//delay( 10 );
set_arm( armdata.x_coord, armdata.y_coord, armdata.z_coord, armdata.gripper_angle );
servos.setposition( WRO_SERVO, armdata.wrist_rotate );
servos.setposition( GRI_SERVO, armdata.gripper_servo );
//ARM_PARK;
// circle();
Max.Task();
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {
mouse_init();
}//if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING…
if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
rcode = mouse_poll();
if( rcode ) {
Serial.print(“Mouse Poll Error: “);
Serial.println( rcode, HEX );
}//if( rcode…
}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING…
//Serial.println( armdata.gripper_servo, DEC );
}
/* Initialize mouse */
void mouse_init( void )
{
byte rcode = 0; //return code
/**/
Usb.setDevTableEntry( 1, Usb.getDevTableEntry( 0,0 ) ); //copy device 0 endpoint information to device 1
/* Configure device */
rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
if( rcode ) {
Serial.print(“Error configuring mouse. Return code : “);
Serial.println( rcode, HEX );
while(1); //stop
}//if( rcode…
Usb.setUsbTaskState( USB_STATE_RUNNING );
return;
}
/* Poll mouse using Get Report and fill arm data structure */
byte mouse_poll( void )
{
byte rcode;
char buf[ 4 ]; //mouse buffer
static uint16_t delay = 500; //delay before park
/* poll mouse */
rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );
if( rcode ) { //error
return( rcode );
}
// todo: add arm limit check
armdata.x_coord += ( buf[ 1 ] * -0.1 );
armdata.y_coord += ( buf[ 2 ] * -0.1 );
switch( buf[ 0 ] ) { //read buttons
case 0x00: //no buttons pressed
armdata.z_coord += ( buf[ 3 ] * -2 ) ;
break;
case 0x01: //button 1 pressed. Wheel sets gripper angle
armdata.gripper_servo += ( buf[ 3 ] * -20 );
/* check gripper boundaries */
if( armdata.gripper_servo 2100 ) {
armdata.gripper_servo = 2100;
}
break;
case 0x02: //button 2 pressed. Wheel sets wrist rotate
armdata.wrist_rotate += ( buf[ 3 ] * -10 );
/* check wrist rotate boundaries */
if( armdata.wrist_rotate 2400 ) {
armdata.wrist_rotate = 2400;
}
break;
case 0x04: //wheel button pressed. Wheel controls gripper
armdata.gripper_angle += ( buf[ 3 ] * -1 );
/* check gripper angle boundaries */
if( armdata.gripper_angle 90 ) {
armdata.gripper_angle = 90;
}
break;
case 0x07: //all 3 buttons pressed. Park the arm
arm_park();
break;
}//switch( buf[ 0 …
Serial.println( armdata.wrist_rotate, DEC );
}
Oleg please help me ….
i tested more than 10 different mouses but it did not work i have the same error in legacy library …
but in new library the mouse boot with no problems …. all i need is to modify arm_mouse sketch to work in the new library
please Oleg its not too difficult on you … i tried to modify but i have no luck..
please oleg modify arm_mouse sketch to work on rev2.0 library >>>>
>> source code has been a good doc so far.
> For example, none of the sketches even have a title line or “here is what it does” line.
To illustrate my point, here is a comment and code from the LadyAda site:
Finally, it's typical to include the comment header at the top of the source file as well. Let's see the whole thing:
/*
Morse.cpp - Library for flashing Morse code.
Created by David A. Mellis, November 2, 2007.
Released into the public domain.
*/
#include Arduino.h
#include Morse.h
Hello,
I am a final year student and for my project I am developing an algorithm to scan bar codes using a USB bar code reader as an input method. I recently bought a USB host shield to connect the barcode reader. I downloaded the latest libraries provided and I am using the examples to verify that I have good communication between Arduino Uno and USB shield. I constantly getting the well known errors: “OSC did not start” and “Error: OSCOKIRQ failed to assert”. I searched hundred of forums and tried many different thinks without success. Could anybody help me with that?
Thank you
Stelios
Which shield are you using?
I am using a sparkfun Usb Shield. This one http://www.coolcomponents.co.uk/catalog/host-shield-p-799.html.
Sparkfun shield is not compatible with my code.
You done s great job by creating those libraries and we all thank you for your support, but what are my options now that I have this shield? 🙂
You may want to try legacy library -> https://github.com/felis/USB_Host_Shield
It worked like a charm!! :p I can now read all the specifications of my usb removable media! Thank you so much oleg I appreciate that! 🙂 I used the descriptor-parser example! Now I have to figure out the coding 🙂
Hello Oleg
I am using DEV-09947 from sparkfun. From your previous responses I got to know that your library does not support sparkfun USB shield. But I tried legacy library; descripter_parser sketch and I am getting an error.
‘MAX3421E’ does not name a type
Kindly suggest how to get rid of this problem.
Oleg, just out of curiosity, will the library have support for mass storage devices? Is it feasible at all?
Thank you.
Support for mass storage is planned.
hi, I’ve recieved USB Host shield 2.0 last satuready. You’ve done really great job! Keyboards and mice are working well. But when it comes to my magnetic card reader, it does not work. I hooked it up to USB host shield and loaded up the USBHIDBootkbd sample sketch. and when I open a terminal, it stops working saying
Start
BM Init
Addr:1
SetProto:4
What do you think is the problem here?
It may not support boot protocol. Get configuration descriptor from it and post it here.
it seems it supports boot protocol, doesn’t iT?
Start
01
—
Device descriptor:
Descriptor Length: 12
Descriptor type: 01
USB version: 0110
Device class: 00
Device Subclass: 00
Device Protocol: 00
Max.packet size: 40
Vendor ID: 0801
Product ID: 0001
Revision ID: 0100
Mfg.string index: 01
Prod.string index: 02
Serial number index: 03
Number of conf.: 01
Configuration descriptor:
Total length: 0022
Num.intf: 01
Conf.value: 01
Conf.string: 00
Attr.: 80
Max.pwr: 32
Interface descriptor:
Intf.number: 00
Alt.: 00
Endpoints: 01
Intf. Class: 03
Intf. Subclass: 01
Intf. Protocol: 01
Intf.string: 00
Unknown descriptor:
Length: 09
Type: 21
Contents: 01010001224C000705
Endpoint descriptor:
Endpoint address: 81
Attr.: 03
Max.pkt size: 0008
Polling interval: 01
Addr:1(0.0.1)
this is correct. However, it gives you NAK on setProtocol(). Try this: power Arduino from external supply with enough power( 500ma min), try with other devices, increase NAK limit – in this order.
hi oleg,
I have an Arduino Mega ADK and already tried to communicate with a mouse or keyboard. Also I’ve got an external 12V Power Supply. I just tried to use the USBHIDBootMouse, USBHIDBootKbd and USBHID_desc. The only thing I get is:
Start
OSC did not start.
No led is flashing on the keyboard or mouse?! Any ideas? Thank you for you help and work!
Why when I press the keyboard keys check “POLL”?
Hi! I am trying to port some parts to the Maple platform. Hardware access works fine (QC passed), so the rest of the classes should be no problem, I thought. However, when using the HIDUniversal class (as in the USBHID_desc example), I get a linker error for an “undefined reference to ‘vtable for HID’“. I was not able to solve that yet. Did anyone experience the same behavior and can provide a solution or give some hints?
First: Oleg, thank you for a mountain of work that has gone into the USB host controller & related projects.
I purchased the USB Host Shield 2.0 (assembled version) and am trying to get a ‘hello world’ equivalent running. I downloaded the 2.0 github repo (the entire directory at https://github.com/felis/USB_Host_Shield_2.0) and have tried unsuccessfully to get any examples compiled.
I get similar issues on any example, which I assume relate to missing libraries. I am new to Arduino, so this is probably my own ignorance. I saw that others have solved similar issues in the thread, but I didn’t see details as to how.
For example, trying to run USBHIDBootKbd, I get the following compile errors:
USBHIDBootKbd.pde:-1: error: expected class-name before ‘{‘ token
USBHIDBootKbd.cpp: In member function ‘void KbdRptParser::PrintKey(uint8_t, uint8_t)’:
USBHIDBootKbd.pde:-1: error: ‘MODIFIERKEYS’ was not declared in this scope
USBHIDBootKbd.pde:-1: error: expected `;’ before ‘mod’
USBHIDBootKbd.pde:-1: error: ‘mod’ was not declared in this scope
USBHIDBootKbd.pde:-1: error: ‘PrintHex’ was not declared in this scope
USBHIDBootKbd.pde:-1: error: expected primary-expression before ‘>’ token
USBHIDBootKbd.cpp: In member function ‘virtual void KbdRptParser::OnKeyDown(uint8_t, uint8_t)’:
USBHIDBootKbd.pde:-1: error: ‘OemToAscii’ was not declared in this scope
USBHIDBootKbd.cpp: At global scope:
USBHIDBootKbd.pde:-1: error: ‘USB’ does not name a type
USBHIDBootKbd.pde:-1: error: expected constructor, destructor, or type conversion before ‘<' token
USBHIDBootKbd.cpp: In function 'void setup()':
USBHIDBootKbd.pde:-1: error: 'Usb' was not declared in this scope
USBHIDBootKbd.pde:-1: error: 'class Keyboard_' has no member named 'SetReportParser'
USBHIDBootKbd.pde:-1: error: 'HIDReportParser' was not declared in this scope
USBHIDBootKbd.pde:-1: error: expected primary-expression before ')' token
USBHIDBootKbd.cpp: In function 'void loop()':
USBHIDBootKbd.pde:-1: error: 'Usb' was not declared in this scope
Any tips or resources to help me solve this would be greatly appreciated. I also echo the suggestions for 'getting started w/ the USB host shield' type of resources to complement the examples, and hopefully the community around this site can get those up… and hopefully I could get to the point of contributing some help to that effort.
All these errors indicate that compiler can’t see library files. The library should be placed in a directory under %arduino%/libraries, directory name is not critical. Sometimes, gitHub won’t pack all the files into zip file, you need to check this too.
Thanks. I was able to get it to find everything (what is strange to me as a C/Arduino newbie is that a failed #include seems to fail silently). On mac, I had to create a ~/Document/Arduino/libraries/ directory. I then put in a subdirectory with all of the files in the root of your github repo.
I have a Mega ADK board and I was hoping to use the built in USB host connector but get “OSC did not start.” Is the Mega ADK board one of the boards not compatible with the library?
You need to uncomment:
#define BOARD_MEGA_ADK
In avrpins.h for the library to work with the Arduino Mega ADK.
That worked. thanks!
Thank you for your library. I am using Arduino MEGA ADK and use your original sketch from the examples/HID/USBHIDBootKbd with response when press the key but when I hook a keypad,it start normall without any response when key pressed.The serial monitor as following:
Start
BM Init(numeric keypad init)
Addr:1
BM configured
Poll:FF(I start to press the numeric keypad keys without any response)
Poll:1
Poll:1
Poll:1
Poll:FF
Poll:FF
Poll:FF
Poll:1
Poll:1
Poll:FF
Poll:FF
Poll:FF
Poll:FF
Poll:1
Poll:1
Poll:FF
Poll:1
Poll:1
Poll:1
Poll:1
Poll:1
Poll:1
BM Init(I put the keyboard in and it start to init)
Addr:1
BM configured
Poll:FF
Poll:1
Poll:1
Poll:1
Poll:1
DN >0404161607070909<
I have looked into the device descriptor from your USBHID_desc example and couldn't find differences between them.
Please help.Thanks.
Sorry to waste your time on this issue. I just found out that newest model keypad will not work with this library. The one that work should have the following words: OS:windows 98SE/Me/2000/XP/Vista printed at the back of its container.
Thanks.
I was having a hard time finding info about the MEGA ADK board and how or if this library would work as all my googling and net surfing led me back to this site and project.
Yes the Arduino MEGA ADk will work. You have to uncomment one line of code and that’s it:
#define BOARD_MEGA_ADK
which can be found in avrpins.h
If you try it without the modification, you’ll get an error “OSC did not start”.
I didn’t come up with this idea, Lauszus mentioned it 2 comments above. My intent in regurgitating it is to answer the question for the next googler so they don’t spend 8 hours searching for this tidbit of info like I did.
Oleg,
I received one of your prebuilt boards. When I run the board_qc test, I get the following:
Circuits at home2011
USB host Shield Quality Control Routine
Reading REVISION register… Die revision invalid. Value returned: FE
Unrecoverable error – test halted!
0 x 55 pattern is transmitted via SPI
Press RESET to restart test
thanks for your help
Which Arduino board are you using?
Now I am getting:
Circuits at home2011
USB host Shield Quality Control Routine
Reading REVISION register… Die revision i03
SPI long test. Transfers 1Mb of data. Each dot is 64k..SPI long test passed
GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
GPIO Test failed. Value written: 00 GPIO Value read: FF
Press any key to continue…
sorry for the trouble,
not sure what i am doing wrong
you can press any key for the test to continue. The error is related to gpio pins, you need a special fixture installed for it to pass.
Check if all contacts are good and also try to use external power supply for the UNO.
Let me know if you still have issues.
btw I am using arduino UNO
had some pin issues on UNO.
I found your trouble shooting article which was very helpful as well.
Seems all is working, I think I am good to go.
Thanks for your quick replies.
fsb
Hello Oleg,
you have done very good work with your library! Many thanks for that.
For a project I’m using the program “USBHIDBootKbd”. It works well so far. But if no key is pressed, the keyboard is polled every 5 seconds. During this time my Arduino MegaADK can not execute any command. For my project I need to poll some inputs regularly. My idea would be to reduce the “USB_XFER_TIMEOUT” in USB.h. Maybe I don’t understand the function of HID and USB completly. Do you have a better idea?
Thank you for your help.
Keyboard is polled in the background, you should have no difficulties executing other commands.
Thank you for your fast reply.
To show the behavior, I added
time=millis();
Serial.println(time);
delay(50);
in loop() of “USBHIDBootKbd” with the following result:
Start
203
253
304
354
405
455
505
556
BM Init
Addr:1
BM configured
712
5762
Poll:FF
10812
15862
20912
Poll:FF
25962
Poll:1
26012
When I disconnect the HID, Serial.println() is executed again every 50ms.
In my project, the HID won’t be changed or disconnected after the first initialization.
Is there anything I havn’t noticed?
I try to connect keyboard and mouse through one wireless receiver (Logitech K520). Mouse and keyboard works fine when tried separately with example sketches, but when i merge those to one sketch only first “declared” device works:
…
USB Usb;
HIDBoot Keyboard(&Usb);
HIDBoot Mouse(&Usb);
uint32_t next_time;
KbdRptParser Prs;
MouseRptParser Prs2;
…
Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
Mouse.SetReportParser(0,(HIDReportParser*)&Prs2);
..
So as above: only keyboard works. If I change the order of these, then mouse only works
HIDBoot Mouse(&Usb);
HIDBoot Keyboard(&Usb);
What did I understood wrong?
Sorry, I meant swapping these lines:
Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
Mouse.SetReportParser(0,(HIDReportParser*)&Prs2);