Jetson nano usb device mode. Emulate mouse or keyboard

I have read the forum and have not found an example of how to emulate a mouse. I want to use a USB connection between my computer(host mode) and the jetson nano(device mode). The program on the jetson nano must send commands via the USB to the computer and move the mouse or press the buttons.
Is there any example?

This isn’t specific to a Nano, but is covered with the USB Gadget API. This is a “framework” for emulating USB devices which have “standard” drivers.

FYI, when a device is queried by USB it can respond that it uses a more generic driver, a “standard” driver. Mouse and keyboard are a good example of this. Some devices (e.g., complicated software defined radio devices) probably need a custom driver. In some cases a device has more than one driver associated with it, e.g., just because a camera is going through USB there is no need to plug in separate cables for control of the camera versus actual video content. So it is possible a given device can have both custom and generic “standard” drivers (not really important for your case, but it illustrates that the micro-B USB port can handle multiple devices simultaneously…the port does not have to become any “one” device).

The gadget framework is not a complete driver. I mentioned above that when a device is queried it will respond with certain information. The framework makes it easy to simply fill in the details for a given generic device class, but it isn’t a full “device” on its own. It is up to you to add to that content until the emulated device provides a full response.

If you’ve ever communicated with your Nano over the network with address “”, then you’ve used a gadget interface device pretending to be a router. There is no such router/network device on the micro-B USB port, but it does pretend to be one. You’ll also find this port has a bulk storage device which is a read-only partition that has a README file in it. This too is a gadget framework with details added to make it show up as this device.

On your fully booted Nano, examine “/opt/nvidia/l4t-usb-device-mode”. This directory contains some definitions which allow the Jetson emulate the bulk storage device and the network device. Other files are simply for starting and stopping these emulated devices as a service.

In particular, examine “”. This file has comments in it for explanations of some of the details being filled in, and also a mix of the actual lines configuring the gadget framework for these two devices.

You could add your own device (an emulated mouse) to this file, and when the network and bulk storage devices start or stop, then so would your emulated mouse. Beware though that you need to study Human Interface Device (HID) gadgets, and that none of those you see are in that “standard” class. You would be adding to the end of that file without modifying the top of the file (be sure to save an unmodified original).

Note: This just creates a synthetic mouse. This would show up on the host PC upon micro-B USB plugin, e.g., there would occur something in a subdirectory of the host’s “/dev/input” directory. It would be up to you whether to use the mouse or not. Quite possibly a mouse plugin would simply be “used” automatically. However, how the mouse actually moves would be defined from the Nano.

Somewhere on your Nano you would need to add code which tells this gadget mouse how to move. Maybe you would write a program which simply passes on the output of a real mouse connected to the Nano. Perhaps the mouse would move in a certain pattern and click somewhere if it sees an object of some time in an AI video inference program. That part is up to you.

Thanks for the detailed answer. I will try to implement it

I examined the contents of this folder. I am trying to repeat the creation of my own device.

There is a problem with creating my own folder for usb gadget api. “mkdir -p /sys/kernel/config/usb_gadget/l4t”

“root@nano:/sys/kernel/config/usb_gadget# mkdir -p /sys/kernel/config/usb_gadget/g
mkdir: cannot create directory ‘/sys/kernel/config/usb_gadget/g’: Cannot allocate memory”

I get a similar error when executing a command from under another user with sudo.

There is no problem with free space:
“root@nano:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p1 57G 17G 39G 30% /
none 951M 0 951M 0% /dev
tmpfs 990M 88K 990M 1% /dev/shm
tmpfs 990M 20M 971M 2% /run
tmpfs 5,0M 4,0K 5,0M 1% /run/lock
tmpfs 990M 0 990M 0% /sys/fs/cgroup
tmpfs 198M 8,0K 198M 1% /run/user/1000”

I use jetson nano 2gb developer kit with ssh ethernet connection.

You can never create content in “/proc” or “/sys”. These are pseudo filesystems which are the results of drivers or kernel features pretending to be a file. One would have to write a driver and load it if you want this to exist and it is not already there.

If you pick a location on the hard drive/eMMC/SD, then you shouldn’t have any issue.