0

I’m having trouble setting this up on my Raspberry Pi Zero W.

I am getting the error that there is no file called 'hidg0'? When I look in dev/ I do not see one either? I am running on the latest software.

I have followed all the steps of this tutorial: https://gndtovcc.home.blog/2020/04/17/turn-your-raspberry-pi-zero-into-a-usb-keyboard-hid/comment-page-1/?unapproved=2230&moderation-hash=d27b7e989bba4b3da280bd07435d85b6#comment-2230

This is my code:

#!/usr/bin/env python3
NULL_CHAR = chr(0)
 
def write_report(report):
    try:
        with open('/dev/hidg0', 'rb+') as fd:
            fd.write(report.encode())
    except: pass
 
# Press a
write_report(NULL_CHAR*2+chr(4)+NULL_CHAR*5)
# Release keys
write_report(NULL_CHAR*8)
# Press SHIFT + a = A
write_report(chr(32)+NULL_CHAR+chr(4)+NULL_CHAR*5)
 
# Press b
write_report(NULL_CHAR*2+chr(5)+NULL_CHAR*5)
# Release keys
write_report(NULL_CHAR*8)
# Press SHIFT + b = B
write_report(chr(32)+NULL_CHAR+chr(5)+NULL_CHAR*5)
 
# Press SPACE key
write_report(NULL_CHAR*2+chr(44)+NULL_CHAR*5)
 
# Press c key
write_report(NULL_CHAR*2+chr(6)+NULL_CHAR*5)
# Press d key
write_report(NULL_CHAR*2+chr(7)+NULL_CHAR*5)
 
# Press RETURN/ENTER key
write_report(NULL_CHAR*2+chr(40)+NULL_CHAR*5)
 
# Press e key
write_report(NULL_CHAR*2+chr(8)+NULL_CHAR*5)
# Press f key
write_report(NULL_CHAR*2+chr(9)+NULL_CHAR*5)
 
# Release all keys
write_report(NULL_CHAR*8)

Does someone have any idea?

Edit:

Sorry for not giving good information for my question, will do it next time. For now, on another Pi it did work. I am going to put that SD card content in mine and test it.

2
  • please add the complete error message ... copy and paste into the question ... do not paste into comments
    – jsotola
    Mar 22, 2021 at 20:23
  • How did you see the error? except: pass would hide the error message - see stackoverflow.com/questions/21553327/… Check the files (config / modules) etc and the chmod +x are done correctly. Can you also post your /usr/bin/isticktoit_usb as code here.
    – user130616
    Mar 22, 2021 at 23:12

1 Answer 1

1

Add some error checking to your scripts. I would specifically check for libcomposite module to be present in the kernel, no other gadget drivers loaded (lsmod | grep g_ gives no output), configfs is mounted and one and only one UDC file exists in /sys/class/udc before you bind the driver.

Printing errors from your Python code would also help:

except, e:
    print('Error: '+ str(e))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.