Go Down

Topic: Learn how to communicate with the PC using HID Protocol on a Leonardo (Read 3401 times) previous topic - next topic



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

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.

Go Up