Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6898

Troubleshooting • USB Printer Device for Rasbberry pi zero 2 w

$
0
0
Hello all,
I am attempting to make a USB device gadget that is meant to emulate a printer in device mode on a Raspberry pi zero 2 w.

The trouble I am having is in trying to create certain files in a certain directory.

I have tried multiple different ways and different configs of the Pi as far as headless using nothing on USB just to set it up.

here are the commands I am trying to accomplish:

#!/bin/bash
cd /sys/kernel/config/usb_gadget/
sudo mkdir -p printer_gadget
cd printer_gadget

# Set USB device descriptor values
sudo echo 0x20D1 > idVendor
echo 0x2013 > idProduct
echo 0x0200 > bcdUSB
echo 0x00 > bDeviceClass
echo 0x00 > bDeviceSubClass
echo 0x00 > bDeviceProtocol
echo 0x40 > bMaxPacketSize0
echo 0x0100 > bcdDevice

# Set device strings
mkdir -p strings/0x409
echo "Dascom Co.,Ltd" > strings/0x409/manufacturer
echo "TD Series Impact Printer" > strings/0x409/product
echo "TD 2600" > strings/0x409/serialnumber

# Create configuration
mkdir -p configs/c.1
echo 0 > configs/c.1/MaxPower

# **Define the Interface Descriptor (Printer Function)**
mkdir -p functions/printer.0
echo 7 > functions/printer.0/class # Printer Class (0x07)
echo 1 > functions/printer.0/subclass # Printer Subclass (0x01 - Unidirectional)
echo 2 > functions/printer.0/protocol # Printer Protocol (0x02 - Bidirectional)
echo "PCL,ESC/P,Raster" > functions/printer.0/protocol/description

# Link function to configuration
ln -s functions/printer.0 configs/c.1/

# Enable the gadget
ls /sys/class/udc > UDC

Everything works until trying to define the interface descriptor
mkdir -p functions/printer.0 works
but everything after with an echo fails with permission denied
even with using tee instead, ie:
echo 7 | sudo tee class > /dev/null
Please keep in mind I changed directory to the right place before the above

Am I just missing something or doing something in the wrong order?
With copy / pasting the commands, one by one, it works until "echo 7 | sudo tee class > /dev/null".
Most of the echo commands in what I posted are actually piped to tee.
No matter the way I try I get permission errors, nothing USB connected, all over ssh currently, tried direct but gave the same permission errors so that's when I tried headless to make sure something connected to the usb wasn't locking me out.

Thank you to anyone who can provide help.

Statistics: Posted by jephill78 — Tue Apr 01, 2025 1:16 am



Viewing all articles
Browse latest Browse all 6898

Trending Articles