Click here to Skip to main content
13,704,677 members
Click here to Skip to main content
Add your own
alternative version

Stats

4.2K views
101 downloads
3 bookmarked
Posted 10 Jul 2018
Licenced CPOL

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

, 12 Jul 2018
Rate this:
Please Sign up or sign in to vote.
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\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

License

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

Share

About the Author

irakyu
France France
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionFYI - download files seem to be missing Pin
raddevus11-Jul-18 9:41
mvpraddevus11-Jul-18 9: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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05-2016 | 2.8.180920.1 | Last Updated 12 Jul 2018
Article Copyright 2018 by irakyu
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid