DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Pi Zero gadget/hid mode not working

Wed Apr 18, 2018 4:21 pm

after hours of hours looking for a propper solution for my problem, I hope I will find an answer here in the forum. If the topic isnt in the right place I'm sorry.

My problem is as follows:
I tried to set my raspberry pi zero V1.3 up as HID as shown here https://randomnerdtutorials.com/raspber ... board-hid/ or here https://gist.github.com/gbaman/50b6cca61dd1c3f88f41
I also tried setting the Pi up as ethernet cotroller -> isnt working either (windows only recognizes a serial Com -> can't reach Port with putty)
Trying to set the Pi up headless wasn't successful as you may guess.

I tried to find the problem myself, but I don't understand enough of Pi, Raspbian, Linux and those things :C I looked through all the guides, How-to's and tutorials and I saw they all use a directory my Pi doesn't find (or at least I can't find it). It's the /sys/kernel/config/usb_gadget.
I also tried to use an image from this tread: viewtopic.php?f=29&t=202498&start=25

Now I'm wondering is there something missing? If yes why and how can I fix it?

I would appreciate help very much ( :

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero gadget/hid mode not working

Wed Apr 18, 2018 6:34 pm

For HID support I've used this successfully: http://isticktoit.net/?p=1383

For the ethernet gadget, I do it like this:
Add

Code: Select all

dtoverlay=dwc2
to /boot/config.txt

Add

Code: Select all

modprobe g_ether
to /etc/rc.local after everything else but above the "exit" line. I don't make any changes to /etc/modules or /boot/cmdline.txt so back out any you have made.

By default g_ether will assign different, random MAC address each time it is loaded. You can get round this by passing the hostmac and devmac parameters when loading the module.

If you want your zero to have access to your entire LAN and the internet you'll need to look into internet connection sharing or network bridging on your PC.
Arguing with strangers on the internet since 1993.

DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Re: Pi Zero gadget/hid mode not working

Wed Apr 18, 2018 7:44 pm

I'm glad you answered this fast.
I tried the way you got your connection working, but my computer recognizes the Pi only as Serial-USB-device and I can't connect to him with Putty or find him as host with Angry IP Scanner.
I'll now try the tutorial/site you posted, but I think I can remember trying it and the tutorial also comes to the point where I got to go to the dorectory /sys/kernel/config/usb_gadget/ which doesn't exist at my Pi if i see it right. :C

thanks for helping me

I'll post my results later

Edit:
first result: Of course I can't update my Pi if I have no internetconnection provided for him. So I got to get the connection working first I guess. I'll try the rest of the tutorial now

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero gadget/hid mode not working

Wed Apr 18, 2018 10:46 pm

DirecXIV wrote:
Wed Apr 18, 2018 7:44 pm
I tried the way you got your connection working, but my computer recognizes the Pi only as Serial-USB-device and I can't connect to him with Putty or find him as host with Angry IP Scanner.
Odd. That shouldn't happen unless you're explictly loading the g_serial module. Or you have a USB to serial adaptor connected between your PC and the Pi's gpio.

Check the following:
  • Your USB cable is connected to the correct port (the inner one).
  • /boot/cmdline.txt is the default one
  • /etc/rc.local contains no call to any g_* module or libcomposite except for g_ether
  • /etc/modules has no call to any g_* module or libcomposite
  • This should be obvious but: you ave rebooted your pi after making the changes I suggested
  • You're using raspbian/raspbian lite not NOOBS or an other OS
If you have a spare SD card (or don't mind loosing what's on the one you are using) try re-flashing it with raspbian and making only the changes in my first post above.

Beyond that, you're probably going to have to post your config files: /boot/cmdline.txt, /boot/config.txt, /etc/modules, /etc/rc.local
Arguing with strangers on the internet since 1993.

DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Re: Pi Zero gadget/hid mode not working

Thu Apr 19, 2018 7:52 am

i checked what you said and:
- i used the right port
- there are no calls for other modules
- i rebooted
- i flashed the newest raspbian lite image and then did the changes u suggested -> didnt work
- I have only connected the Pi with a USB cable to my PC

another interesting fact: If i connect the Pi only to my Computer, so the Pi gets powered from there, my Computer checks first a not working and unknown USB-device but then installs/uses a driver so the Pi is seen as Serial-USB-device

i wrote down what is executed inside the config-files you suggested:

/etc/modules

dwc2

/boot/cmdline.txt

dwc_otg.lpm_enable=0 console=serial10,115200 console=tty root=PARTUUID=b865e443-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

/boot/config.txt

dtparam=audio=on
dtoverlay=dwc2

/etc/rc.local

_IP=$(hostname -I) || ture
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
modprobe g_ether
exit 0

since i now found the directory /sys/kernel/config/usb_gadget/ I will try the tutorial you linked another time

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero gadget/hid mode not working

Thu Apr 19, 2018 10:55 am

There has to be something in your config that's setting things up as a USB serial gadget before trying to load g_ether. Or something on the PC side.

Startiing with a fesh stretch install from 2018-03-13-raspbian-stretch-lite and making the following changes everything works as expected.
  • Code: Select all

    dtoverlay=dwc2
    added to /boot/config.txt
  • enabled ssh by creating /boot/ssh
  • changed /etc/rc.local to

    Code: Select all

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    # Print the IP address
    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
      printf "My IP address is %s\n" "$_IP"
    fi
    
    modprobe g_ether
    exit 0
    
My windows PC first detects an uknown device then correctly detects a USB ethernet device.

The zero can be reached via putty as raspberrypi.local

The windows device manager shows a "USB Ethernet/RNDIS Gadget" as expected.

The only time I see a USB serial port is when I explictly load g_serial instead of g_ether.

So the problem must be in your configuration either on your pi or your PC.

How are you connecting to your pi to make the changes?
Arguing with strangers on the internet since 1993.

fruitoftheloom
Posts: 23548
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Pi Zero gadget/hid mode not working

Thu Apr 19, 2018 11:01 am

Rather than negativity think outside the box !
RPi 4B 4GB (SSD Boot) RaspiOS64 ARM64
Asus ChromeBox 3 Celeron is my other computer...

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero gadget/hid mode not working

Thu Apr 19, 2018 11:09 am

fruitoftheloom wrote:
Thu Apr 19, 2018 11:01 am
https://blog.gbaman.info/?p=791
MIght stop the "unknown device" message but doesn't invalidate my approach above (though don't try both at the same time)
Arguing with strangers on the internet since 1993.

DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Re: Pi Zero gadget/hid mode not working

Thu Apr 19, 2018 3:33 pm

I'm connecting to the pi via hdmi and display and im making the changes via a keyboard connected to the usb mini port. I'll try the suggestions later. In between I tried the tutorial and my computer recognized the Pi as HID successfull even thought i can't test it (can't command the Pi without keyboard, can't test it without connection to PC)

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero gadget/hid mode not working

Thu Apr 19, 2018 5:33 pm

DirecXIV wrote:
Thu Apr 19, 2018 3:33 pm
I'm connecting to the pi via hdmi and display and im making the changes via a keyboard connected to the usb mini port. I'll try the suggestions later. In between I tried the tutorial and my computer recognized the Pi as HID successfull even thought i can't test it (can't command the Pi without keyboard, can't test it without connection to PC)
There's a couple of ways you can talk to the pi while in USB gadget mdre:
  1. Use a USB to 3.3v TTL serial adapter. Connect TX on the adapter to RX on the pi, RX on the adapter to TX on the pi, and ground to ground. Use a windows terminal app (e.g. putty) in serial mode to login.
  2. Using the tutorial on isticktoit you can configure both a HID gadget and an ethernet (or serial one). Both will be recognised on windows and you'll be able to connect via ssh (putty).
  3. Switch to a zeroW. Networking over the onboard wifi and bluetooth are unaffected by USB gadget mode so you can connect over those.
Option 1 won't easily let you run GIU apps but options 2 and 3 will over vnc or X11 forwarding.
Arguing with strangers on the internet since 1993.

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero gadget/hid mode not working

Thu Apr 19, 2018 5:36 pm

Arguing with strangers on the internet since 1993.

DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Re: Pi Zero gadget/hid mode not working

Fri Apr 20, 2018 2:12 pm

I proceed just as you said, but my Computer still recognizes the Pi as serial USB-device (COM 4), so it doesnt work for me i guess :C
since i don't have such an adapter (option 1) I dont want to order one (accessing the Pi via the Computer isn't necessary for my project)
i followed the Tutorial on isticktoit and my Computer recognizes a HID device, but doesn't migrate it (didnt test the connection yet because ->), the ethernet isnt seen as ethernet adapter and after installing the correct driver by hand, it doesn't work
to option 3: my Pi Zero is no W and i don't want to buy one if it isn't realy necessary
samo to option 4 :C

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Pi Zero gadget/hid mode not working

Fri Apr 20, 2018 2:50 pm

I really don't understand why your PC is seeing the pi as a USB serial device if you're not using g_serial, g_multi, g_cdc or the serial port portion of the tutorial I linked.

If the dwc2 module is loaded but not device has been configured it should be showing up as an unknown USB device. Once a gadget has been configured it will show up as the configured device.

Check the PC's config. The stuff I've linked and posted works for me (and for others) so either something you're doing is causing this or, more likely, the issue is on the PC end and that's not something I'm able to help with.

Are you sure that "COM4" is this pi and not some other device connected to your PC?

One way to rule out windows is to download, burn and boot your PC from a live linux image (e.g. https://www.raspberrypi.org/downloads/r ... i-desktop/). Once booted, open a terminal, plug in your pi and see what the ouput of

Code: Select all

lsusb
is.
Arguing with strangers on the internet since 1993.

DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Re: Pi Zero gadget/hid mode not working

Thu Apr 26, 2018 6:21 pm

Meanwhile I tried a entirely new image and all the steps you mentioned. It didn't work, same problem as bevor (at least kinda) the Computer recognizes the Pi as Serial device (yes, im entirely sure it's my Pi).

I searched through the forum and i found some other guys, who had the same problem, all with Windows 10, so it's obviously a problem with Microsoft, right?

I will try the solution with linux later, cause i need to get it working on windows for my project

thanks for the help
Last edited by DirecXIV on Fri Apr 27, 2018 12:07 pm, edited 1 time in total.

User avatar
HawaiianPi
Posts: 5886
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Pi Zero gadget/hid mode not working

Thu Apr 26, 2018 7:14 pm

Try writing my Raspbian Lite image to your micro SD card and test it in your Pi Zero.
2018-03-13-raspbian-stretch-lite-Pi0USB.zip
2018-03-13-raspbian-stretch-lite-Pi0USB.zip.sha256
  • Make no changes to the image before writing.
  • Make no changes to the SD card after writing (do not edit anything).
  • Use the Etcher image writing software to write the .zip to your SD card (don't extract the image).
  1. Install the card to your Pi Zero.
  2. Connect a normal (not OTG) micro USB cable to the USB data port (the USB port closest to the HDMI port).
  3. Do not connect anything to the USB power port of the Pi Zero.
  4. Boot (or reboot) your Windows PC.
  5. Connect the other end of the micro USB data cable from the Pi Zero to a USB port on your Windows PC.
This image has been pre-modified for USB Gadget Ethernet mode on the Pi Zero computers.
It has been tested and verified on all three models of the Pi Zero.

After Windows detects and installs a new device you should have an Ethernet/RNDIS Ethernet Gadget in device manager.
Image

If this does not work for you, then the problem is with your Windows PC (something is screwed up with your Windows install). You can try to install the driver manually. This should be the driver Windows installs (all the details match the driver installed in my Win10 system).
Other hardware - Acer USB Ethernet/RNDIS Gadget

Of course this may not help you with your original problem of getting the HID profile working. But hopefully it will give you some information that will help you troubleshoot the HID problem.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Re: Pi Zero gadget/hid mode not working

Thu Apr 26, 2018 7:32 pm

I now searched for the problem that my Pi is shown as serial device under windows 10 and voila i found a solution that works. I'm right now trying to set the Pi now up as HID/ethernet device, but so far it looks good. :D

this one worked for me, just for others having eventually the same problem:
https://www.reddit.com/r/raspberry_pi/c ... indows_10/

mattmiller
Posts: 2245
Joined: Thu Feb 05, 2015 11:25 pm

Re: Pi Zero gadget/hid mode not working

Thu Apr 26, 2018 8:46 pm

Which part of that long thread got it working for you?

DirecXIV
Posts: 8
Joined: Wed Apr 18, 2018 4:02 pm

Re: Pi Zero gadget/hid mode not working

Thu Apr 26, 2018 9:28 pm

the first and upvoted reply to download a driver and install it

Return to “Troubleshooting”