As the data pins of the micro USB port are not connected to the SoC's USB PHY you cannot use this port for data (in either host or slave mode).
It should be possible however to use the USB Type A port on the Model A in slave mode.
Some further details;
The Model B uses a SMSC LAN9512 USB 2.0 Hub and 10/100 Ethernet Controller IC to provide multiple ...
Rasberry PI A/A+/B/B+ models have OTG mode disabled by variety of reasons:
USB port occupied with USB hub (ethernet),
missing OTG 5th pin (grounded), or
data pins are not connected (power port).
You’d need Raspberry PI Zero for OTG or so called Gadget Mode. Data USB port can be used for OTG and “power”. As of time of this writing Serial and Ethernet were ...
Even though the USB port of the RPi is technically an On-the-go (OTG) chip that should support both a reduced set of host and client functionality (and could therefore play the role of an USB slave such as an HID) the B/B+ type of the RPi does not support the device mode. That is related to the included USB hub and the fact that the ethernet is tunneled ...
Yes, you can use a Model A as a USB slave device:
Although it's quite limited to just usage as a mass storage device ( SD card)
- no GPIO access, display or even ARM CPU usage.
I don't know if this helps but it reduces one possible source of error. Doing what the developers from systemd suggest is using a Unit file. Here is a very generic one for your problem. Create a new unit file with:
rpi ~$ sudo systemctl edit --force --full hid-keyboard.service
In the empty editor insert these statements, save them and quit the editor:
I tried switching cables, and it worked. It turns out the cable that I was using was powering the pi correctly, but I guess something was wrong with it that prevented the pi to be seen as a HID device. I changed the cable and it worked like a charm!
Time to provide an updated answer.
On the B, B+, 2B, 3B and 3B+ USB device mode is not possible because the USB controller on the SoC is connected to a USB Hub with Ethernet chip, not directly to a port.
On the A, A+ and 3A+ device mode is possible but the port must be forced into device mode (IIRC this is done through a device tree overlay), since there is ...
A lot of work has been done since the time the question was asked. Using some Rasberry Pi models as a USB peripheral device (e.g. mass storage, serial, ethernet, keyboard, mouse) is now possible. See this gist and this guide.