Click here to Skip to main content
14,421,922 members

How to Communicate with the PC using HID Protocol on a Leonardo

Rate this:
2.88 (5 votes)
Please Sign up or sign in to vote.
2.88 (5 votes)
9 Dec 2018CPOL
Using HID protocol on an Arduino Leonardo


This tip exists because the actual Arduino firmware do not support full communication with the PC using HID, we cannot read data from the PC actually.

Using the Code

To fix that, you need to replace the files below from libraries folder:

Move librairies\HID.cpp     to {Arduino Path}\hardware\arduino\avr\libraries\HID\src
Move librairies\HID.h       to {Arduino Path}\hardware\arduino\avr\libraries\HID\src

Move librairies\USBCore.cpp to {Arduino Path}\hardware\arduino\avr\cores\arduino
Move librairies\USBCore.h   to {Arduino Path}\hardware\arduino\avr\cores\Arduino

Move librairies\CDC.cpp     to {Arduino Path}\hardware\arduino\avr\cores\Arduino
Move librairies\USBAPI.h    to {Arduino Path}\hardware\arduino\avr\cores\arduino

Move librairies\Caterina-Leonardo.hex to {Arduino Path}\hardware\arduino\avr\bootloaders\caterina

The Caterina bootloader is here to avoid long upload sketch to the board.

Then to send bytes to the PC, you need to do:

HID().USBSend(Data_report, REPORT_ID + DATA_SIZE);

And to receive bytes from the PC:

if (HID().USBRecv(Host_report, RID + HOST_SIZE))
    if (host_report[0] == FUNCTION_ID)
        // Do your stuff here

Data_report and Host_report are array of bytes.


  • 10th July, 2018: Initial version
  • 8th December, 2018: Update for Arduino 1.8.8


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

France France
No Biography provided

Comments and Discussions

QuestionFYI - download files seem to be missing Pin
raddevus11-Jul-18 10:41
communityengineerraddevus11-Jul-18 10:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 10 Jul 2018


5 bookmarked