Open Source USB Generic HID devices based on the PIC18F and Windows

Not rated 18,906

Open Source USB Generic HID devices based on the PIC18F and Windows
Open Source USB Generic HID devices based on the PIC18F and Windows

If you have experience with PIC18F microcontrollers and the USB Generic HID standard, you may have noticed the complexity involved in supporting USB on both the PIC18F and the Windows host side. Progressing beyond basic functionalities, such as reading a switch and flashing an LED, presents a significant challenge with a steep learning curve. To assist hobbyists interested in more advanced projects, a framework has been developed for creating USB devices, which encompasses both Windows host application development and PIC18F firmware. This framework includes a Visual Studio C# class library that manages the intricacies of Windows-specific SDKs and operating system requirements, a reference application that demonstrates the use of the class library and serves as a testing interface, a straightforward USB hardware reference design, and a PIC18F4550 firmware that communicates with the class library. This setup allows for rapid development and testing of USB devices and Windows host applications with minimal knowledge of the USB Generic HID protocol. The class library provides a simple interface for USB device interaction from C#, while the firmware serves as an example of the necessary software for the PIC in device design. The framework facilitates command and response exchanges between the USB device and the host, along with bi-directional bulk data transfers, enabling the development of complex data-capture applications that require swift information exchange. The latest version of the USB library and firmware incorporates several enhancements and bug fixes, including changes to the method for registering device event notifications, which is now managed by the library without needing a WndProc override in user code. The reference hardware can be easily assembled on a breadboard and is designed to match the pinout of the Microchip PIC DEM FS USB board, allowing for the purchase of a reference board if desired. The hardware features four LEDs to indicate the status of the USB device as it processes requests from the Windows host application. The board is designed to accommodate additional devices and circuitry as needed, with the only essential component being the USB port and its associated hardware. The reference hardware is configured for a bus-powered USB device, drawing power directly from the host computer, which simplifies the circuit but limits current consumption to 100mA. For devices requiring higher power for components such as relays, motors, or LED arrays, a self-powered configuration is necessary. The self-powered version of the reference board includes an LM7805 5V regulator to manage the DC input. The 5V input from the USB bus is routed to RA0 on the PIC18F4550, enabling the firmware to detect USB cable connections and disconnections, though this power-sense feature can be omitted if desired.

The framework enables developers to create sophisticated USB devices with ease, significantly reducing the complexity typically associated with USB communication. The Visual Studio C# class library abstracts the lower-level details of USB interaction, allowing developers to focus on application logic rather than protocol intricacies. The reference application serves as a practical demonstration, providing a user-friendly interface for testing and validating the USB device's functionality.

The hardware design is intentionally kept simple, allowing for easy assembly and modification. The inclusion of four status LEDs provides immediate visual feedback regarding the device's operational state, enhancing the user experience during development and debugging. The design's compatibility with existing Microchip boards offers flexibility for developers who may prefer to utilize commercial solutions or existing prototypes.

For projects requiring more power, the self-powered design offers a robust solution, accommodating higher current demands while maintaining the integrity of the USB communication. The addition of the LM7805 voltage regulator ensures stable operation, providing the necessary power management for various applications. This comprehensive approach to USB device development, encompassing both hardware and software elements, positions the framework as a valuable resource for hobbyists and professionals alike, facilitating the creation of innovative USB-enabled solutions.If you`ve dabbled with PIC18F microcontrollers and the USB Generic HID standard before (perhaps you`ve even tried my Building a PIC18F USB device project) then you will have noticed that there is a lot of complexity in supporting USB on both the PIC18F and the Windows host-side of things. Getting beyond the basic steps of reading a switch and flashing an LED (how many projects have you built to flash LEDs !) is actually quite a large task with a steep learning-curve. To make things easier on the hobbyist who wishes to delve into more exciting projects, I`ve developed a framework for producing USB devices which covers both the Windows host-side application development and the PIC18F firmware itself.

The framework consists of a Visual Studio C# class library (which handles all of the intricacy of dealing with the Windows specific SDKs and operating system requirements), a windows reference application (which demonstrates how to use the class library and acts as a testing front-end for the library), a simple USB hardware reference design and (last but not least!) a PIC18F4550 firmware which communicates with the class library. In essence this means that you can rapidly develop and test a USB device and the Windows host-application with a minimum of USB Generic HID protocol knowledge.

The class library gives you a very simple interface to the USB device from C# and the firmware serves as an example of how to create the specific software needed on the PIC for your device design. The framework includes the ability to pass commands and responses to and from the USB device as well as bi-directional bulk-transfer of data allowing you to build more complex data-capture applications which require more information to be passed quickly from host to device and vice-versa.

Version 3 of the USB library and firmware is now available (2011-10-16). I`ve made several major and minor enhancements to the library as well as some bug fixing. Here is a list of the enhancements and changes: Changed the method used for registering to receive device event notifications. This is now handled by the library and does not need a WndProc override in the user code The reference hardware is extremely simple and can be built on a breadboard if required.

I`ve made the pin-out of the hardware identical to the PIC DEM FS USB board available from Microchip to allow you to buy a reference board (if you want to!), you can also use my clone of the Microchip board - the PIC USB Development Board. If you don`t have the time/money/inclination to make a reference board here is a circuit schematic of the minimum required hardware for the reference board for both the PIC18F4550 and PIC18F2550 microcontrollers: The reference hardware provides 4 LEDs which are used to show the status of the USB device as it processes the various requests that can be sent to it from the Windows host-application.

The 4 LEDs (from left-to-right) mean: The board provides all you need to add in your own devices and circuity as you require, you can even remove the LEDs, the only part the firmware truly requires is the USB port and its associated hardware. The reference hardware shown above is for a bus-powered USB device (it takes its power directly from the host computer).

This requires the fewest parts and gives you a very simple circuit, however the current draw of the device is limited to 100mA. If you want to build devices that consume more power (to drive more hardware such as relays, motors, arrays of LEDs, etc.

) you will need to make the device self-powered. The following circuit schematic shows a simple self-powered version of the reference board. A LM7805 5V regulator is added to regulate the DC input. The 5V input from the USB bus is directed to RA0 on the PIC18F4550 which allows the firmware to detect when the USB cable is connected and disconnected. You can omit this power-sense feature, however that means that your firmwar 🔗 External reference