Background

The concept of Hidden HID was born after I noticed how much space was available inside the USB connector and wondered if it would be possible to hide a rubber ducky completely inside it. With the increasing miniaturization of components, it was quite easy to design a basic USB enabled microcontroller circuit that fits inside the 2.5mm available. The device is kept in place using the phototransistors, which at 1.8mm tall are large enough to act as spacer elements. Added to the 0.4mm PCB, the resulting total thickness is 2.2mm, which fits snugly but comfortably inside the USB port. 

Once inserted, it can be removed again by inserting any thin plastic tool into the port and pulling on the phototransistors. I use a plastic tweezer that I broke in half :)

Close-Up of Hidden HID PCB inside a USB hub

View of the bottom side from inside a USB connector

Circuit

Screenshot of schematic
The circuit is very simple and similar to v1. The STM32F042 provides the USB functionality and even includes an internal 48MHz crystal, helping to minimize component count. The LDO steps down the 5V USB supply to 3.3V for the STM32. Two of the four phototransistors connect to the ADC of the STM32; the other two could not be connected due to routing limitations and are used only as spacing elements.
R2 was originally 2.2k but after testing I found that 10k provided a better sensitivity.

BOOT0, 3.3V and GND connect to test points to allow switching between bootloader and application.

PCB

I kept the PCB thickness at 0.4mm as this seemed to work well in v1, being robust enough to not bend while thin enough to remain inconspicuous. 

While developing v1 I was unsure how many  spacer elements would be required for stability, so had simply included a very long pad on each side of the PCB so that I could try out different configurations myself. This decision backfired, as my limited soldering skills meant the spacers were soldered unevenly, leading to an unreliable USB connection that sometimes worked and sometimes didn't. For v2 I therefore added IPC3 footprints for the phototransistors and included them in the BOM. 

3D model of v2 PCB
I ordered the boards from PCBWay, who have been my go-to PCB supplier for over a year now. I have been consistently impressed with the quality of the boards and of the customer service, which is both friendly and extremely quick. Order processing begins almost immediately and technical queries are sorted within hours.

The small form factor and high component density made this PCB a little more technologically demanding than my previous orders from PCBWay but, as the photos demonstrate, this did not affect the quality of assembly or fabrication. 
bottom side of assembled PCB showing all components
top side of assembled PCB showing USB contacts
After ordering the PCBs, I discovered that I had made a mistake while researching the phototransistors. The particular model that I chose, 1541201NC3060 from Würth, is intended to be soldered upside down, with the lens poking through a hole in the board. I had never come across this form of assembly before and it was not clearly indicated in the datasheet, so I had assumed they were standard SMD components. PCBWay informed me quickly of the error and luckily were still able to hand-solder the transistors the way I needed them, so the design could still be completed. 

Frustratingly, I have not been able to find a good alternative phototransistor that fulfils the height requirements while allowing normal automated assembly.


Bring-up and Results

I had three goals for this revision: 1. to improve ease of programming and reprogramming. 2. to improve reliability of the USB connection and 3. to implement an on-off remote control using phototransistors. Let us address each point in turn:

1. Ease of Programming

To program the STM32, I use the 3 circular SMD pads at the front of the board. In the middle is the BOOT0 pin, on the left is GND and on the right is 3V3. To load a new program using the USB bootloader, simply connect BOOT0 to 3V3 using some magnet wire, then insert into a USB port and use the STMCubeProgrammer tool to download the hex file. To boot the program currently in flash, you need to solder BOOT0 to GND instead. This is much faster than using the STLink programmer as in v1, and lets me test the program as soon as it is dowloaded. However I do wish I had found a solution that doesn't involve soldering. Unfortunately, there does not currently exist a mechanical switch small and thin enough for this project :(

I left a good amount of space between the 3 SMD pads to leave me the option of designing a programming adapter in the future, which could bridge BOOT0 and 3V3 using very short pogo pins or similar. 
PCB with BOOT0 connected to GND using magnet wire

2. Reliability

I was pleased to discover that the USB connection is significantly more reliable than in v1, which I presume to be due to the much more level soldering of the phototransistors. I haven't had any connection problems this time

3. Remote Control

I was unsure if the remote control would work at all, as I feared the USB port may block too much of the IR from reaching the phototransistors. Luckily, this was not the case and I was able to detect IR from a distance of around 0.5-1m. While this range is not particularly impressive, it is enough to allow reliable "arming" and "disarming" of the device after insertion into the USB port. I used a single 3W IR LED for my tests - perhaps an array would help increase the range.

I also found that the phototransistors are highly directional, and just a small change in the angle of incidence can stop the light from being detected.


Software

I have written a simple test software for the Hidden HID which simply waits until an IR signal is detected, then opens a command line and echoes "hello world". This basic example is provided in my github. I am not much of a software hacker so will not be developing the software further - please feel free to use and improve it as you wish :)