Arduino Forum

Using Arduino => Introductory Tutorials => Topic started by: arduiko on May 18, 2018, 07:34 pm

Title: Learn how to communicate with the PC using HID Protocol on a Leonardo
Post by: arduiko on May 18, 2018, 07:34 pm
Hello,

I would like to show you a tutorial to achieve USB communication using HID protocol.

All what you need is to follow instructions below, then you will just need to do that in your sketch:

Send bytes to the PC:
Code: [Select]
HID().USBSend(Data_report, REPORT_ID + DATA_SIZE);
Receive bytes from the PC:
Code: [Select]
 
    if (HID().USBRecv(host_report, RID + HOST_SIZE))
    {
        if (host_report[0] == FUNCTION_ID)
        {
            // Do your stuff here
        }
    }

Instructions:
Download the librairies.zip then

Code: [Select]
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.
Title: Re: Learn how to communicate with the PC using HID Protocol on a Leonardo
Post by: arduiko on Dec 08, 2018, 08:52 pm
Hello,

Here's an update for Arduino 1.8.8:

https://www.codeproject.com/Tips/1251867/How-to-Communicate-with-the-PC-using-HID-Protocol (https://www.codeproject.com/Tips/1251867/How-to-Communicate-with-the-PC-using-HID-Protocol)