{"id":13395,"date":"2024-11-21T01:40:17","date_gmt":"2024-11-21T06:40:17","guid":{"rendered":"http:\/\/engineersgarag-main\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/"},"modified":"2024-11-21T05:46:39","modified_gmt":"2024-11-21T10:46:39","slug":"atmega-32u4-based-generic-usb-keyboard-part-2-25","status":"publish","type":"post","link":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/","title":{"rendered":"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)"},"content":{"rendered":"<p style=\"text-align: justify;\">The Mouse and keyboard are most common computer peripherals. While the mouse is a pointing device and helps in tapping the GUI elements of the screen, the keyboard has greater role to play with handling data input as well as has the ability to navigate through GUI elements of a screen. Nowadays the keyboards interface with the computers through USB cable and use USB protocol to send data inputs to the computers. The wireless type keyboards generally use Bluetooth to send data inputs to the computers. In fact, wireless keyboards also use an external pluggable device which ultimately connects to the PC by USB Port. This project is to demonstrate the basic functioning and working of a generic USB keyboard. The 8-bit USB AVR &#8211; Atmega 32u4 is used as the device controller chip in the project. The project uses AVR based Lightweight USB Framework (LUFA) as the firmware which is modified to work for this custom keyboard.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Prototype of Arduino based DIY USB Keyboard \" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg\" alt=\"Prototype of Arduino based DIY USB Keyboard \" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig.1: Prototype of Arduino based DIY USB Keyboard\u00a0<\/em><\/p>\n<p style=\"text-align: justify;\">Usually, the Windows keyboard has 104 keys which is the de facto standard and the windows based laptops have 86-key keyboards. An Apple keyboard has 109 keys as the standard and Apple laptops have 78-key keyboard. In this project, a 4-key keyboard is built to demonstrate the making of keyboards. The LUFA firmware is used and its HID device driver class for keyboard is modified to program the project. With the use of LUFA firmware, the device driver code to implement USB protocol is not needed to be written explicitly. Modifying the firmware code to work for the project will be sufficient. The project works similar to any generic USB keyboard and has buttons for the following Inputs -:<\/p>\n<p>\u2022 Input H Alphabet to the computer<\/p>\n<p>\u2022 Input I Alphabet to the computer<\/p>\n<p>\u2022 Turn Caps lock ON or OFF<\/p>\n<p>\u2022 Left Shift Key<\/p>\n<p>The project uses tactile switches as the buttons, Atmega 32u4 as the controller chip (on board Arduino Pro Micro) and USB cable to connect to the personal computer.<\/p>\n<h4>PREREQUISITES<\/h4>\n<p style=\"text-align: justify;\">This project is based on Arduino Pro Micro which has the USB AVR &#8211; Atmega 32u4 as the sitting MCU. In order to understand this project, one must have basic knowledge of the AVR microcontrollers and the embedded C programming for AVRs. WinAVR Studio is used to write, edit and compile the project code, so closely following the project shall require familiarizing with the above stated IDE as well. Though LUFA framework takes care of implementing the USB protocol and has APIs to abstract the lower level codes, <strong>understanding USB protocol<\/strong> is recommended to understand how actually the project is working. In fact, if anyone has already worked on some other microcontroller, it will not be much pain to understand and follow this project as the project code is more or less about getting input from the GPIO pins of AVR MCU and modifying the LUFA device driver to work as generic keyboard accordingly.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Image showing alphabet 'h' typed from Arduino based generic USB keyboard\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Image-Showing-Alphabet-h-Typed-Arduino-Based-Generic-USB-Keyboard.jpg\" alt=\"Image showing alphabet 'h' typed from Arduino based generic USB keyboard\" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig. 2: Image showing alphabet &#8216;h&#8217; typed from Arduino based generic USB keyboard<\/em><\/p>\n<h4 style=\"text-align: justify;\">COMPONENTS REQUIRED<\/h4>\n<p>1. Arduino Pro Micro<\/p>\n<p>2. Breadboard<\/p>\n<p>3. Connecting wires<\/p>\n<p>4. Push buttons<\/p>\n<p>5. Micro USB cable<\/p>\n<p>6. 10K resistors<\/p>\n<p>7. 220 \u2126 resistor<\/p>\n<h4>SOFTWARE TOOLS REQUIRED<\/h4>\n<p>1. WinAVR Studio<\/p>\n<p>2. AVR Dude<\/p>\n<p>3. LUFA Firmware<\/p>\n<p><strong style=\"font-size: 12.8px; text-align: center;\">BLOCK DIAGRAM<\/strong><\/p>\n<p><img decoding=\"async\" title=\"Block Diagram of Arduino based DIY USB Keyboard \" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Block-Diagram-Arduino-Based-DIY-USB-Keyboard-.png\" alt=\"Block Diagram of Arduino based DIY USB Keyboard \" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><em>Fig. 3:\u00a0<span style=\"font-size: 12.8px;\">Block Diagram of Arduino based DIY USB Keyboard\u00a0<\/span><\/em><\/p>\n<h4>CIRCUIT CONNECTIONS<\/h4>\n<p style=\"text-align: justify;\">The project uses Arduino Pro Micro as the USB controller chip. A set of four tactile switches is connected at the port B of the Arduino. The switches are connected to pins 2, 6, 5 and 4 of the port B with functions assigned to them according to the following table -:<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Table listing Arduino pins and respective keyboard functions\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Table-Listing-Arduino-Pins-Respective-Keyboard-Functions.png\" alt=\"Table listing Arduino pins and respective keyboard functions\" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig. 4: Table listing Arduino pins and respective keyboard functions<\/em><\/p>\n<p style=\"text-align: justify;\">An LED is connected at the pin 1 of Port D via 220 \u2126 pull up resistor to get the visual hint of the status of Caps Lock Key. The tactile switches are connected between the port and ground. The pins of port B by default are connected to VCC and receive a HIGH logic.<\/p>\n<p style=\"text-align: justify;\">Pressing a tactile switch changes the status at the respective pin to LOW by short circuiting to the ground.<\/p>\n<p style=\"text-align: justify;\">The Program code for the project is burnt to the Arduino Pro Micro using AVR Dude. The Arduino board is connected to the USB port of a PC by a USB cable.<\/p>\n<h4 style=\"text-align: justify;\">HOW THE PROJECT WORKS<\/h4>\n<p style=\"text-align: justify;\">In this project, the USB protocol is implemented by the LUFA framework. For configuring the controller chip to work as USB Keyboard, the HID Class Driver of the LUFA framework will be used. The Human Interface Device (HID) class takes care of the transfers between the host device and the human controlled USB peripherals like USB Keyboard, Mouse or Joystick.<\/p>\n<p style=\"text-align: justify;\">When a USB device is attached to the host (PC), the host sends request for configuration details in the form of the control transfer. The connected device has to respond with appropriate descriptors to get configured and ready for further operations. Only after configuration, the device can communicate with the host in the form of interrupt, isochronous or bulk transfers for executing the operations for which the device has been made. In case of keyboard, after configuring with the host device, it has to communicate with the host in the form of interrupt transfers for the intended keyboard like operations. The process of identification and configuration of the device with the host is called enumeration.<\/p>\n<p style=\"text-align: justify;\">A typical keyboard has many types of keys like -:<\/p>\n<p>\u2022 Modifier Keys: They are Right Ctrl and Left Ctrl, Right Alt and Left Alt, Right Shift and Left Shift, Right GUI, and Left GUI.<\/p>\n<p>\u2022 Alphanumeric Keys: A \u2013 Z and 0 \u2013 9<\/p>\n<p>\u2022 Numeric Keys \u2013 keys present on Numeric Keypad<\/p>\n<p>\u2022 Punctuation Keys \u2013 For example, comma, semicolon, bracket key etc.<\/p>\n<p>\u2022 System Keys \u2013 For example, escape, break key<\/p>\n<p>\u2022 Function Keys \u2013 Keys present on top of the keyboard like F1, F2 etc.<\/p>\n<p>\u2022 Special Keys \u2013 For example, delete, arrow keys etc<\/p>\n<p style=\"text-align: justify;\">According to the USB protocol, keys pressed on a keyboard are identified by the key codes. This is same as the ASCII codes are used to represent characters. Like keycode representing spacebar is 41 so when spacebar is pressed, the controller chip sends the binary representation of 41 (0x29) to the host in appropriate data format to the host to indicate that spacebar has been pressed. The standard keycodes for different keys are given in the HID Usage Table provided by the USB Implementers Forum.<\/p>\n<p style=\"text-align: justify;\">As mentioned earlier, a windows keyboard has 104 keys while the number of characters that can be input through a keyboard is more than that. A lot of characters are input by pressing shift key along with another key which already represents another character. Like to input exclamation &#8220;!&#8221; character, shift key along with the key &#8220;1&#8221; has to be pressed. When key &#8220;1&#8221; is pressed weather along shift or not, the same keycode is transferred. However when it will be pressed along with the shift key, set of two keycodes, one for shift key and other for &#8220;1&#8221; key will be transferred which will then be interpreted as an exclamation &#8220;!&#8221; character. The same happens for the lower case and upper case alphabets too.<\/p>\n<p style=\"text-align: justify;\">A keyboard is HID class USB device and LUFA framework has HID class related module in the LUFA-Source-Folder \/LUFA\/Drivers\/USB\/Class\/Device folder. Other device class related module are also in the same folder. The LUFA framework has demo projects for different USB device classes in the LUFA-Source-FolderDemosDeviceClassDriver folder. For implementing the project, demo project for keyboard provided in the LUFA framework will be modified and complied. The demo project for keyboard is in the LUFA-Source-FolderDemosDeviceClassDriverKeyboard folder. The folder contains keyboard.c file which will be modified to work for our custom keyboard device.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Image showing capital 'i' typed from Arduino based generic USB keyboard\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Image-Showing-Capital-i-Typed-Arduino-Based-Generic-USB-Keyboard.jpg\" alt=\"Image showing capital 'i' typed from Arduino based generic USB keyboard\" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig. 5: Image showing capital &#8216;i&#8217; typed from Arduino based generic USB keyboard<\/em><\/p>\n<h4 style=\"text-align: justify;\"><u>How Keyboard.c identifies HID device being Keyboard<\/u><\/h4>\n<p style=\"text-align: justify;\">The keyboard.c uses Keyboard_HID_Interface interface in HID_Device_USBTask() function which is being imported from the HIDDeviceClass.c (from LUFA-Source-Folder LUFADriversUSBClassDevice) to configure the device as keyboard. The interface abstracts the low-level descriptor codes and identifies the device as keyboard through an InterfaceNumber variable.<\/p>\n<p style=\"text-align: justify;\">Keyboard Specific Report DescriptorsAny HID device has to exchange data with the host which should be structured in the form of reports. The report descriptor defines the report structure. A report descriptor contains the information needed by host to determine the data format and how the data should be processed by the host. Therefore, a report descriptor basically structures the data that needs to be exchanged with the host according to the USB protocol.<\/p>\n<p style=\"text-align: justify;\">For working like a keyboard, the device needs to send usage report and data input report descriptors specific to keyboard HID Class to the host while it itself needs to interpret data output report specific to keyboard HID Class received from the host device. The Usage Report informs the Host about the features or functionality of the USB device whereas the Data Input Report is used to transmit the data to the Host. The Data Output Report is used to receive data from the host.<\/p>\n<h4 style=\"text-align: justify;\"><u>From Where Keyboard.C gets the USAGE and Data Reports Descriptors<\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">In the LUFA framework&#8217;s demo project for Keyboard, descriptor.c file is imported in keyboard.c to send the relevant usage and data reports descriptors to the host device. The descriptor.c defines a KeyboardReport[] structure which is used in the CALLBACK_HID_Device_CreateHIDReport() function of the keyboard.c to generate keyboard specific usage and data reports descriptors. Inside descriptor.c the KeyboardReport[] structure has the values returned by HID_DESCRIPTOR_KEYBOARD () function. The HID_DESCRIPTOR_KEYBOARD() is defined in HIDClassCommon.h (located in LUFA-Source-FolderLUFADriversUSBClassCommon folder). The keyboard.c imports keyboard.h which imports usb.h. USB.h imports HIDCLass.h. In HIDClass.h is imported HIDClassDevice.h if the USB_CAN_BE_DEVICE is true for the controller chip to being a USB device, not the host. The HIDClassDevice.h imports HIDClassCommon.h where the HID device specific descriptor fields have been defined.<\/span><\/p>\n<h4 style=\"text-align: justify;\"><u><span style=\"font-size: 12.8px;\">USAGE REPORT<\/span><\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">HID_DESCRIPTOR_KEYBOARD () returns the following field values of the usage report descriptor, specific to keyboard functioning -:<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\"><img decoding=\"async\" title=\"Table listing field values of the usage report descriptor from HID_DESCRIPTOR_KEYBOARD Function\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Table-Listing-Field-Values-Usage-Report-Descriptor-HID-DESCRIPTOR-KEYBOARD-Function.jpg\" alt=\"Table listing field values of the usage report descriptor from HID_DESCRIPTOR_KEYBOARD Function\" \/><\/span><\/p>\n<p style=\"text-align: center;\"><em>Fig. 6: Table listing field values of the usage report descriptor from HID_DESCRIPTOR_KEYBOARD Function<\/em><\/p>\n<p style=\"text-align: justify;\">These fields are set to following values in HID_DESCRIPTOR_ KEYBOARD()<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Screenshot of field values of the usage report descriptor from HID_DESCRIPTOR_KEYBOARD Function\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Screenshot-Field-Values-Usage-Report-Descriptor-HID-DESCRIPTOR-KEYBOARD-Function.png\" alt=\"Screenshot of field values of the usage report descriptor from HID_DESCRIPTOR_KEYBOARD Function\" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig. 7:\u00a0Screenshot of field values of the usage report descriptor from HID_DESCRIPTOR_KEYBOARD Function<\/em><\/p>\n<p style=\"text-align: justify;\">The Usage or Feature report contains information about the features of the device. In other words, this report informs Host about the features needed in the device. For example, a Keyboard device generally contains feature information like a number of modifier keys, the number of other keys and number of LEDs used for status indication. The Host can access this report by requesting the device using GET_REPORT request. This report is transmitted using Control Transfer Type of the USB protocol.<\/p>\n<h4 style=\"text-align: justify;\"><u>DATA INPUT REPORT<\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">The Data Input Report contains the data that needs to be transmitted to the Host. It contains data related to the features selected via the Usage Report. Again in the HIDClassCommon.h a structure for data report of keyboard is defined in the following manner.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\"><img decoding=\"async\" title=\"Screenshot of Data Input Report from HIDClassCommon.h in LUFA Library\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Screenshot-Data-Input-Report-HIDClassCommon.h-LUFA-Library.png\" alt=\"Screenshot of Data Input Report from HIDClassCommon.h in LUFA Library\" \/><\/span><\/p>\n<p style=\"text-align: center;\"><em>Fig: 8:\u00a0Screenshot of Data Input Report from HIDClassCommon.h in LUFA Library<\/em><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">The data input report for keyboard consist of 8 bytes of which 6 bytes are used to represent keycodes of maximum six keys pressed together, one byte is reserved for OEM and is always set to 0 and one byte is for the modifier key. The field values specific to data report for keyboard are organised in the following manner -:<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\"><img decoding=\"async\" title=\"Table listing field values specific to data report for this keyboard\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Table-Listing-Field-Values-Specific-Data-Report-Keyboard.png\" alt=\"Table listing field values specific to data report for this keyboard\" \/><\/span><\/p>\n<p style=\"text-align: center;\"><em>Fig. 9:\u00a0Table listing field values specific to data report for this keyboard<\/em><\/p>\n<h4 style=\"text-align: justify;\"><u><span style=\"font-size: 12.8px;\">DATA OUTPUT REPORT<\/span><\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">The Data Output report contains the information related to the status of LEDs present on a keyboard. These LEDs indicate the active status of CAPSLOCK key, SCROLL key and NUMLOCK key. Through this report, the Host informs the device to switch ON\/OFF the LEDs as per respective key activity. For example, when the CapsLock is pressed, the Host will inform the device to switch ON the LED for CapsLock Key.\u00a0<\/span><span style=\"font-size: 12.8px;\">This report is 1-byte long with first 3 LSBs indicating the status of each LED. The other bits are not used. If the respective bit is set to 0, it indicates the respective key is OFF and if respective bit is set to 1, it indicates the respective key is ON.<\/span><\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Screenshot of Data Output Report from HIDClassCommon.h in LUFA Library\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Screenshot-Data-Output-Report-HIDClassCommon.h-LUFA-Library.png\" alt=\"Screenshot of Data Output Report from HIDClassCommon.h in LUFA Library\" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig. 10:\u00a0Screenshot of Data Output Report from HIDClassCommon.h in LUFA Library<\/em><\/p>\n<h4 style=\"text-align: justify;\"><u><span style=\"font-size: 12.8px;\">HOW THE DEVICE WORKS<\/span><\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">The AVR microcontroller is programmed to work with the tactile switches as keyboard buttons. The main() function, the CALLBACK_HID_Device_CreateHIDReport() function and CALLBACK_HID_Device_ProcessHIDReport() function of the keyboard.c are modified to customize the device for working with tactile switches as source for reading desired keycodes. Check out the program code to see the modifications implemented for this custom keyboard.<\/span><\/p>\n<h4 style=\"text-align: justify;\"><u><span style=\"font-size: 12.8px;\">PROGRAMMING GUIDE<\/span><\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">For building the project download the <a href=\"https:\/\/github.com\/abcminiuser\/lufa\" target=\"_blank\" rel=\"noopener noreferrer\">LUFA framework<\/a> from the github.com.\u00a0<\/span><span style=\"font-size: 12.8px;\">The demo project provided with the LUFA framework is modified to make this custom keyboard. In the extracted LUFA zip file, open Demos\/Device\/ClassDriver\/Keyboard folder. The folder has the following files and folders.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\"><img decoding=\"async\" title=\"Screenshot of LUFA Library Folder on Windows\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Screenshot-LUFA-Library-Folder-Windows.png\" alt=\"Screenshot of LUFA Library Folder on Windows\" \/><\/span><\/p>\n<p style=\"text-align: center;\"><em>Fig. 11: Screenshot of Data Output Report from HIDClassCommon.h in LUFA Library<\/em><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">Of these, Keyboard.h, Keyboard.c, and Makefile needs to be modified for this project.\u00a0<\/span><span style=\"font-size: 12.8px;\">The modified files (provided at the bottom of the article in zip format) can also be downloaded from the engineersgarage and replaced with the original files<\/span><span style=\"font-size: 12.8px;\">. Either open the files in WinAVR Studio or Notepad++ and modify original files or replace files with the already modified one. The modified or replaced Keyboard.c needs to be compiled from within the LUFA&#8217;s Source folder to get the object code.<\/span><\/p>\n<h4><u>Modifying Keyboard.h<\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">The Keyboard.h library file is imported in the Keyboard.c file and includes a set of additional libraries and defines the constants and functions for the keyboard device. These include the additional libraries for the joystick, button, and LEDs which should be commented out as the project is not using these HID features. So open Keyboard.h and make the following changes -:<\/span><\/p>\n<p style=\"text-align: justify;\">\u2022 Comment the #include library statements for Joystick.h, LEDS.h, and Buttons.h ( We are commenting these libraries as we are not using any joystick, buttons board and LED board).<\/p>\n<p style=\"text-align: justify;\">\u2022 Comment the #define statements for LEDMASK_USB_NOTREADY, LEDMASK_USB_ENUMERATING, LEDMASK_USB_READY, LEDMASK_USB_ERROR.<\/p>\n<p style=\"text-align: justify;\">Save the file with changes.<\/p>\n<h4 style=\"text-align: justify;\"><u>Modifying Keyboard.C file<\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">Again in the Keyboard.c, the code sections for Joystick, button board and LEDs need to be commented out. \u00a0So open Keyboard.c and make the following changes &#8211; :<\/span><\/p>\n<p style=\"text-align: justify; margin-left: 40px;\"><span style=\"font-size: 12.8px;\">\u2022 In the main loop, comment the LEDs_SetAllLEDs()<\/span><\/p>\n<p style=\"margin-left: 40px;\">\u2022 In SetupHardware() function, comment the Joystick_Init(), LEDs_Init(), Buttons_Init()<\/p>\n<p style=\"margin-left: 40px;\">\u2022 In EVENT_USB_Device_Connect() function, comment the LEDs_SetAllLEDs()<\/p>\n<p style=\"margin-left: 40px;\">\u2022 In EVENT_USB_Device_Disconnect() function, comment LEDs_SetAllLEDs()<\/p>\n<p style=\"margin-left: 40px;\">\u2022 In EVENT_USB_Device_ConfigurationChanged() function, comment the LEDs_SetAllLEDs()<\/p>\n<p style=\"text-align: justify;\">In Keyboard.c the main() function executes the functioning of the Keyboard. Inside the main function Port B where the tactile switches have been connected needs to be defined as input and all the pins of port B has to be raised to HIGH logic by default as the microcontroller will need to detect LOW logic for input from tactile switches. Similarly Port D where Capslock LED is connected has to be made output port and has to be raised to LOW logic by default, so add the following statements in the beginning of main() function -:<\/p>\n<div>\n<div>\u00a0 \u00a0 \u00a0 int main(void)<\/div>\n<div>{<\/div>\n<div>\u00a0 \u00a0 \u00a0 SetupHardware();<\/div>\n<div>\u00a0 \u00a0 \u00a0 DDRD = 0XFF;<\/div>\n<div>\u00a0 \u00a0 \u00a0 DDRB = 0X00;<\/div>\n<div>\u00a0 \u00a0 \u00a0 PORTB = 0XFF;<\/div>\n<div>\u00a0 \u00a0 \u00a0 PORTD = 0X00;<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 \u00a0 \/\/LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);<\/div>\n<div>\u00a0 \u00a0 \u00a0 GlobalInterruptEnable();<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 \u00a0 for (;;)<\/div>\n<div>\u00a0 \u00a0 \u00a0 {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 HID_Device_USBTask(&amp;Keyboard_HID_Interface);<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 USB_USBTask();<\/div>\n<div>\u00a0 \u00a0 \u00a0 }<\/div>\n<div>}<\/div>\n<\/div>\n<p style=\"text-align: justify;\">Inside the infinite, for loop, the HID_Device_USBTask() function is called where Keyboard_HID_Interface interface is passed as parameter. The interface identifies the device as keyboard and abstracts the low-level program code specific to keyboard HID class. The function is coming from the HIDClassDevice.c module (located in LUFA\/Drivers\/USB\/Class\/Device\/HIDClassDevice.c) and is used for general management task for a given HID class interface, required for the correct operation of the interface. It should be called in the main program loop, before the master USB management task USB_USBTask(). The \u00a0USB_USBTask() is the main USB management task. The USB driver requires this task to be executed continuously when the USB system is active (device attached in host mode, or attached to a host in device mode) in order to manage USB communications. The function is defined in USBTask.c (Located in LUFA-Source-FolderLUFADriversUSBCore folder).<\/p>\n<p style=\"text-align: justify;\">For creating Keyboard Data Input report CALLBACK_HID_Device_CreateHIDReport() needs to be modified. The default file has the function body to detect joystick movement as well.<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Screenshot of CALLBACK_HID_Device_CreateHIDReport Function in LUFA Library\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Screenshot-CALLBACK-HID-Device-CreateHIDReport-Function-LUFA-Library.png\" alt=\"Screenshot of CALLBACK_HID_Device_CreateHIDReport Function in LUFA Library\" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig. 12:\u00a0Screenshot of LUFA Library Folder on Windows<\/em><\/p>\n<p style=\"text-align: justify;\">This keyboard project is using tactile switches to get keycodes. Therefore, LOW bit at each button is detected and the corresponding keycode is sent via data input report for the keyboard. So replace the body of the function with the following code -:<\/p>\n<div>bool<\/div>\n<div>CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0uint8_t* const ReportID,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0const uint8_t ReportType,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0void* ReportData,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0uint16_t* const ReportSize)<\/div>\n<div>{<\/div>\n<div>\u00a0 \u00a0 \u00a0USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;<\/div>\n<div><\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 \u00a0uint8_t UsedKeyCodes = 0;<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 \u00a0if(!(PINB &amp; _BV(PB4))) {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0\/\/ add keycode for \u2018h\u2019 alphabet in the report<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 KeyboardReport-&gt;KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_H;<\/div>\n<div>\u00a0 \u00a0 \u00a0 }<\/div>\n<div>\u00a0 \u00a0 \u00a0 if(!(PINB&amp; _BV(PB5))) {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0\/\/ add keycode for \u2018i\u2019 alphabet in the report<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 KeyboardReport-&gt;KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_I;<\/div>\n<div>\u00a0 \u00a0 \u00a0 }<\/div>\n<div>\u00a0 \u00a0 \u00a0 if(!(PINB &amp; _BV(PB6))) {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \/\/ add keycode for Caps Lock in the report<\/div>\n<div>\u00a0 \u00a0 \u00a0 KeyboardReport-&gt;KeyCode[UsedKeyCodes++] = HID_KEYBOARD_SC_CAPS_LOCK;<\/div>\n<div>\u00a0 \u00a0 \u00a0 }<\/div>\n<div>\u00a0 \u00a0 \u00a0 if(!(PINB &amp; _BV(PB2))) {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \/\/ add keycode for modifier shift key in the report<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0KeyboardReport-&gt;Modifier = HID_KEYBOARD_MODIFIER_LEFTSHIFT;<\/div>\n<div>\u00a0 \u00a0 \u00a0 }<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 \u00a0*ReportSize = sizeof(USB_KeyboardReport_Data_t);<\/div>\n<div>\u00a0 \u00a0 \u00a0 return false;<\/div>\n<div>}<\/div>\n<p style=\"text-align: justify;\">In the body BV() function is used to map the respective bit as a byte with only the respective bit changed in the returned byte.<\/p>\n<p style=\"text-align: justify;\">The Data Output Report is handled by the CALLBACK_HID_Device_ProcessHIDReport() function. In the unedited LUFA file, this function has statements to turn the LEDs associated with modifier keys ON or OFF and has the following body -:<\/p>\n<p style=\"text-align: justify;\"><img decoding=\"async\" title=\"Screenshot of CALLBACK_HID_Device_ProcessHIDReport Function in LUFA Library\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Screenshot-CALLBACK-HID-Device-ProcessHIDReport-Function-LUFA-Library-1.png\" alt=\"Screenshot of CALLBACK_HID_Device_ProcessHIDReport Function in LUFA Library\" \/><\/p>\n<p style=\"text-align: center;\"><em>Fig. 13:\u00a0Screenshot of CALLBACK_HID_Device_CreateHIDReport Function in LUFA Library<\/em><\/p>\n<p style=\"text-align: justify;\">First, remove the statements that are not required. These statements are as follow -:<\/p>\n<p>\u2022 uint8_t \u00a0LEDMask \u00a0 = LEDS_NO_LEDS;<\/p>\n<p>\u2022 All if conditions and their statements<\/p>\n<p>\u2022 LEDs_SetAllLEDs(LEDMask)<\/p>\n<p>Now add the statements given below to the function body -:<\/p>\n<p>void<\/p>\n<div>CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const uint8_t ReportID,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const uint8_t ReportType,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const void* ReportData,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 const uint16_t ReportSize)<\/div>\n<div>{<\/div>\n<div>\u00a0 \u00a0 \u00a0uint8_t* LEDReport = (uint8_t*)ReportData;<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 \u00a0if (*LEDReport &amp; HID_KEYBOARD_LED_CAPSLOCK)<\/div>\n<div>{ \/\/ switch on the LED for Caps Lock<\/div>\n<div>\u00a0 \u00a0 \u00a0PORTD |= 0x02; \/\/ make PD1 high<\/div>\n<div>}<\/div>\n<div>else<\/div>\n<div>{ \/\/ switch off the LED<\/div>\n<div>\u00a0 \u00a0 \u00a0PORTD &amp;= 0xfd; \/\/ make PD1 low<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>}<\/div>\n<p style=\"text-align: justify;\">These statements check the status of CapsLock key as received from the host device and accordingly turns the LED connected at pin 1 of port D ON or OFF accordingly.<\/p>\n<p style=\"text-align: justify;\">Save the file and create Make file for the project.<\/p>\n<h4><u>Modifying Make File<\/u><\/h4>\n<p style=\"text-align: justify;\">In the Keyboard folder, there is a make file that needs to be edited. The file can be edited using Notepad++. The following information needs to be edited -:<\/p>\n<p style=\"text-align: justify; margin-left: 40px;\">\u2022 MCU = atmega32u4<\/p>\n<p style=\"text-align: justify; margin-left: 40px;\">\u2022 ARCH = AVR8<\/p>\n<p style=\"text-align: justify; margin-left: 40px;\">\u2022 BOARD = LEONARDO<\/p>\n<p style=\"text-align: justify; margin-left: 40px;\">\u2022 F_CPU = 16000000<\/p>\n<p style=\"text-align: justify;\">Save the file and exit. Now all the files are edited completely for the basic HID Keyboard application.<\/p>\n<h4><u>Compiling Keyboard.c<\/u><\/h4>\n<p style=\"text-align: justify;\"><span style=\"font-size: 12.8px;\">For compiling the source code, WinAVR Programmers Notepad or Arduino IDE can be used. Open the modified Keyboard.c file and compile the code.<\/span><\/p>\n<h4><u><span style=\"font-size: 12.8px;\">Burning Hex code<\/span><\/u><\/h4>\n<p style=\"text-align: justify;\">The hex file is generated on compiling the keyboard.c file. For burning the object code to microcontroller open the Command Prompt, change the current directory to the directory containing the Hex file. This can be done using command: CD &lt;address of the directory&gt;. Now reset the Arduino and instantly run the command: : avrdude -v -p atmega32u4 -c avr109 -P COM20 -b 57600 -D -Uflash:w:Keyboard.hex:i after replacing the COM Port with the recognized one.<\/p>\n<p style=\"text-align: justify;\">If the uploading process is successful, the Arduino will be shown as HID Keyboard in the Device Manager. There is no need of installing any driver in the computer as Generic HID Keyboard is used for the project implementation. Use the buttons to test the project device working as generic USB Keyboard.<\/p>\n<p style=\"text-align: justify;\">In the next project &#8211; <strong>Custom Browser Keypad<\/strong>, learn how to make a keyboard to work specially with the desktop browser.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Mouse and keyboard are most common computer peripherals. While mouse is a pointing device and helps in tapping the GUI elements of the screen, the keyboard has greater role to play with handling data input as well as has ability to navigate through GUI elements of a screen. Nowadays the keyboards interface with the computers through USB cable and use USB protocol to send data inputs to the computers. The wireless type keyboards generally use Bluetooth to send data inputs to the computers.&nbsp;In fact, wireless keyboards also use an external pluggable device which ultimately connects through the PC by USB Port. This project is to demonstrate the basic functioning and working of a generic USB keyboard. The 8-bit USB AVR &#8211; Atmega 32u4 is used as the device controller chip in the project.&nbsp;<\/p>\n","protected":false},"author":311,"featured_media":55458,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[13],"tags":[],"class_list":{"2":"type-post","8":"entry","9":"has-post-thumbnail"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.2 (Yoast SEO v25.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)<\/title>\n<meta name=\"description\" content=\"This project demonstrates the basic functioning and working of a generic USB keyboard and uses 8-bit USB AVR as device controller.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)\" \/>\n<meta property=\"og:description\" content=\"This project demonstrates the basic functioning and working of a generic USB keyboard and uses 8-bit USB AVR as device controller.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/\" \/>\n<meta property=\"og:site_name\" content=\"Engineers Garage\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/engineersgarage\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"338\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Amanpreet Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:site\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amanpreet Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/\"},\"author\":{\"name\":\"Amanpreet Singh\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/526929dd58916ffb049da3e9adae8ead\"},\"headline\":\"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)\",\"datePublished\":\"2024-11-21T06:40:17+00:00\",\"dateModified\":\"2024-11-21T10:46:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/\"},\"wordCount\":3410,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg\",\"articleSection\":[\"Electronic Projects\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/\",\"url\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/\",\"name\":\"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg\",\"datePublished\":\"2024-11-21T06:40:17+00:00\",\"dateModified\":\"2024-11-21T10:46:39+00:00\",\"description\":\"This project demonstrates the basic functioning and working of a generic USB keyboard and uses 8-bit USB AVR as device controller.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg\",\"width\":600,\"height\":338,\"caption\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.engineersgarage.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.engineersgarage.com\/#website\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"name\":\"Engineers Garage\",\"description\":\"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News\",\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.engineersgarage.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\",\"name\":\"Engineer's Garage - WTWH Media\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"width\":372,\"height\":52,\"caption\":\"Engineer's Garage - WTWH Media\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/engineersgarage\",\"https:\/\/x.com\/EngineersGarage\",\"https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/526929dd58916ffb049da3e9adae8ead\",\"name\":\"Amanpreet Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ae10b6a902c38b371923411a43a9bfe57a88c4fdcc00744c0ece299e5401ae17?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ae10b6a902c38b371923411a43a9bfe57a88c4fdcc00744c0ece299e5401ae17?s=96&r=g\",\"caption\":\"Amanpreet Singh\"},\"url\":\"https:\/\/www.engineersgarage.com\/author\/asingh\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)","description":"This project demonstrates the basic functioning and working of a generic USB keyboard and uses 8-bit USB AVR as device controller.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/","og_locale":"en_US","og_type":"article","og_title":"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)","og_description":"This project demonstrates the basic functioning and working of a generic USB keyboard and uses 8-bit USB AVR as device controller.","og_url":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/","og_site_name":"Engineers Garage","article_publisher":"https:\/\/www.facebook.com\/engineersgarage","og_image":[{"width":600,"height":338,"url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg","type":"image\/jpeg"}],"author":"Amanpreet Singh","twitter_card":"summary_large_image","twitter_creator":"@EngineersGarage","twitter_site":"@EngineersGarage","twitter_misc":{"Written by":"Amanpreet Singh","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#article","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/"},"author":{"name":"Amanpreet Singh","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/526929dd58916ffb049da3e9adae8ead"},"headline":"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)","datePublished":"2024-11-21T06:40:17+00:00","dateModified":"2024-11-21T10:46:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/"},"wordCount":3410,"commentCount":0,"publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"image":{"@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg","articleSection":["Electronic Projects"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/","url":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/","name":"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage"},"image":{"@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg","datePublished":"2024-11-21T06:40:17+00:00","dateModified":"2024-11-21T10:46:39+00:00","description":"This project demonstrates the basic functioning and working of a generic USB keyboard and uses 8-bit USB AVR as device controller.","breadcrumb":{"@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#primaryimage","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg","width":600,"height":338,"caption":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.engineersgarage.com\/atmega-32u4-based-generic-usb-keyboard-part-2-25\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.engineersgarage.com\/"},{"@type":"ListItem","position":2,"name":"Atmega 32u4 Based Generic USB Keyboard (Part 2\/25)"}]},{"@type":"WebSite","@id":"https:\/\/www.engineersgarage.com\/#website","url":"https:\/\/www.engineersgarage.com\/","name":"Engineers Garage","description":"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News","publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.engineersgarage.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.engineersgarage.com\/#organization","name":"Engineer's Garage - WTWH Media","url":"https:\/\/www.engineersgarage.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","width":372,"height":52,"caption":"Engineer's Garage - WTWH Media"},"image":{"@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/engineersgarage","https:\/\/x.com\/EngineersGarage","https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw"]},{"@type":"Person","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/526929dd58916ffb049da3e9adae8ead","name":"Amanpreet Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ae10b6a902c38b371923411a43a9bfe57a88c4fdcc00744c0ece299e5401ae17?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ae10b6a902c38b371923411a43a9bfe57a88c4fdcc00744c0ece299e5401ae17?s=96&r=g","caption":"Amanpreet Singh"},"url":"https:\/\/www.engineersgarage.com\/author\/asingh\/"}]}},"featured_image_src":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg","featured_image_src_square":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Prototype-Arduino-Based-DIY-USB-Keyboard-.jpg","author_info":{"display_name":"Amanpreet Singh","author_link":"https:\/\/www.engineersgarage.com\/author\/asingh\/"},"_links":{"self":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/13395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/users\/311"}],"replies":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/comments?post=13395"}],"version-history":[{"count":0,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/13395\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media\/55458"}],"wp:attachment":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media?parent=13395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/categories?post=13395"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/tags?post=13395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}