Click here to Skip to main content
14,386,394 members

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

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

Introduction

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.

History

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

License

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

Share

About the Author

wqaxs36
France France
No Biography provided

Comments and Discussions

 
QuestionFYI - download files seem to be missing Pin
raddevus11-Jul-18 10:41
mvaraddevus11-Jul-18 10:41 
There is no file download link but I do see the files seem to be connected to the article, but I can't easily download them.
EDIT
Didn't notice that header item was the download. Blush | :O

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.

Tip/Trick
Posted 10 Jul 2018

Stats

8.9K views
253 downloads
5 bookmarked