programming pen usb interface

12,683

Circuit Image

The project involves a trigger programming solution using a built-in pushbutton. The approach taken was to integrate a small USB keyboard circuit into the pen's interface. A proposed method for the pushbutton to trigger a programming command included adding a microcontroller to the pen's interface, which would connect to a PC via a USB to serial converter. This microcontroller would send data to the PC each time the button is pressed. However, this method would necessitate a script on the PC to verify incoming data from the pen. The objective was to create a universal interface capable of programming any microcontroller without requiring scripts or drivers. The solution implemented was to incorporate a USB keyboard interface into the pen. This design would send an "arrow up" keystroke followed by an "enter" command, allowing a single programming command (e.g., "make flash") to be executed by pressing the pen's button after typing it once in a terminal window. Due to size constraints for the programming adapter, the available space was limited. V-USB, a software USB driver for Atmel AVR chips, was utilized. The website provided numerous example projects, including a self-calibrating ATTiny45 USB keyboard interface. The ATTiny45, an 8-pin chip, fit well within the available space on the pen's interface. The self-calibrating code eliminated the need for an external crystal, which is typically required for frequency precision in USB applications. This project served as an excellent foundation, as much of the work had already been accomplished. The schematic illustrates the assembled circuit. Given the size constraints and personal preference, only surface-mount devices (SMD) were used. A custom PCB was not created; instead, the assembly was conducted on protoboard, utilizing PTFE coated 30 AWG wire for interconnections. The components selected were relatively large (0603 resistors and capacitors, SOD-323 diodes, SOIC chip), making soldering manageable. However, soldering the micro USB connector proved challenging due to its tiny pin dimensions (0.25 mm wide, 0.25 mm long, and 1.3 mm apart), which required precision work under a stereo microscope. After an arduous one and a half hours, the connections to the USB connector were completed and secured with epoxy to prevent disconnection. The final assembly is compact and well-organized. The firmware developed is primarily based on the EasyLogger code from the V-USB website, with modifications made to remove ADC-related functions and to generate the appropriate keystrokes upon button activation. An improved oscillator calibration routine, sourced from the Code and Life blog, was also integrated. Additionally, the USB configuration was adjusted to ensure proper identification when plugged into a Linux system, as evidenced by the log output indicating the device's presence and specifications.

The circuit design leverages the capabilities of the ATTiny45 microcontroller, which operates as a USB HID (Human Interface Device) to emulate keyboard inputs. The integration of the V-USB library facilitates USB communication without the complexity of a hardware USB controller, making it suitable for compact applications. The pushbutton is connected to one of the microcontroller's GPIO (General Purpose Input/Output) pins, configured with an internal pull-up resistor to detect button presses. When the button is pressed, the microcontroller executes an interrupt service routine (ISR) that generates the necessary keystrokes. The keystroke sequence is carefully crafted to ensure compatibility with various programming environments, allowing users to send commands seamlessly.

The choice of using SMD components aligns with the project's space limitations, ensuring that the overall footprint remains minimal. The protoboard assembly method allows for flexibility in circuit modifications, while the use of high-quality PTFE coated wire enhances durability and reduces the risk of shorts. The meticulous soldering process, particularly for the micro USB connector, highlights the importance of precision in electronics assembly, especially when dealing with compact and intricate designs.

In summary, this project exemplifies an innovative approach to creating a versatile programming tool that simplifies the process of microcontroller programming through a user-friendly interface. The combination of a compact design, effective use of existing libraries, and careful attention to assembly details results in a functional and efficient device that meets the specified requirements.Trigger programming with its build-in pushbutton. The solution I came up with was to add a tiny USB keyboard circuit to the pen`s interface. One method to have the pushbutton trigger a programming command would have been to add a microchip to the pen`s interface and connect it to the PC using a USB to serial converter. The microcontroller could then sent some data to the PC every time the button is pushed. However, that would also required a script on the PC side to check whether the pen was sending data. What I wanted was a universal interface, which could be used to program any type of microcontroller, which wouldn`t require any scripts or drivers. What I came up with was to add an USB keyboard interface to the pen. In order to make the pen work no matter which command needs to be executed to program a chip, I decided it would send the arrow up keystroke followed by an enter.

That way, I can just type the programming command (e. g. "make flash") once in a terminal window and pressing the programming pen`s button afterwards will make the same command execute. I did not want to increase the size of the programming adapter, so my build space was extremely limited.

I found V-USB, a software USB driver for Atmel AVR chips. That website contains a lot of links to example projects, one of which is a self-calibrating ATTiny45 USB keyboard interface. The ATTiny45 is a small 8 pin chip which just fit in the space I had available on the pen`s interface.

Due to the self-calibrating code, it did not require an external crystal, which is normally needed due to frequency precision requirements of the USB interface. Basically, that project was a perfect starting poattachments_refint and someone had already done most of the work for me.

Excellent! The circuit I put together is shown in the schematic below. Since size requirements dictated it, and I prefer it anyway, only SMD components were used. I didn`t bother with a custom PCB and build it all on protoboard, using PTFE coated 30 AWG wire for the interconnections. The components are quite large (0603 resistors and capacitors, SOD-323 diodes, SOIC chip) and soldering them did not really pose a problem.

The micro USB connector on the other hand was quite a nightmare to solder. Since I was working on protoboard, I had to make connections to the USB connector using wire. However, the connector`s pins are so tiny (0. 25 mm wide, 0. 25 mm long and 1. 3 mm apart) that even under a stereo microscope, I was barely able to see them. Thus, I spend an extremely frustrating one and a half hours soldering four wires to that connector. Once all four wires were properly connected, I covered them in epoxy to make sure they wouldn`t come lose. The end result is really compact and pretty neat, as you can see in the picture below. The firmware I wrote is heavily based on the EasyLogger code from the V-USB website. All I had to do was remove some ADC related code and rewrite a few functions to generate the appropriate keystrokes when the pushbutton is pressed.

I also added an improved oscillator calibration routine that found on the Code and Life blog. The USB configuration was slightly modified as well, so that when the pen is plugged in this shows up in my linux logfiles: [anthony@desktop ~] $ dmesg | tail usb 8-2: new low speed USB device number 81 using uhci_hcd usb 8-2: New USB device found, idVendor=4242, idProduct=e131 usb 8-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 8-2: Product: Programming Pen usb 8-2: usb 8-2: configuration #1 chosen from 1 choice input: Programming Pen as /devices/pci0000:00/0000:00:1d. 2/usb8/8-2/8-2:1. 0/input/input49 generic-usb 0003:424 🔗 External reference