bnielsen1965 / otg-set-mode

A BASH script used to set the USB OTG gadget mode on a Raspberry Pi.
3 stars 0 forks source link

Different way to do it if it didn't work #1

Open Keanu-S opened 2 years ago

Keanu-S commented 2 years ago

It didn't work for me but editing config file and putting dtoverlay=dwc2 at the end then editing the cmdline file and put modules-load=dwc2,g_ether (replace g_ether with whichever thing you want to emulate)

bnielsen1965 commented 2 years ago

What OS version are you running?

Did the script make any changes to the files? And did you run the script with sudo?

Keanu-S commented 2 years ago

Using the most recent raspberry pi os on pi zero w and I input the command as written sudo ./otg-set-mode.sh g_zero

On Mon, Dec 20, 2021, 10:30 AM Bryan Nielsen @.***> wrote:

What OS version are you running?

Did the script make any changes to the files? And did you run the script with sudo?

— Reply to this email directly, view it on GitHub https://github.com/bnielsen1965/otg-set-mode/issues/1#issuecomment-998084161, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWP3HWU5FX6EFFZDMISEDETUR5K4BANCNFSM5KLOSQDA . You are receiving this because you authored the thread.Message ID: @.***>

bnielsen1965 commented 2 years ago

Can you attach a copy of your /boot/config.txt and /boot/cmdline.txt

I ran a test on a Pi Zero W with the latest Raspbian OS and everything seemed to work okay for a serial device. Was your OS install fresh or could there have been other changes to the boot settings?

The following is a run down of the steps I used to test as a serial device...

I used the 2021-10-30-raspios-bullseye-armhf-lite.img and did a fresh install on an SD card and placed the card in a Pi Zero W.

I did the first boot, configured localization, setup WiFi, enabled ssh, rebooted and removed the keyboard from the USB port.

I then used ssh over WiFi to connect to the Pi Zero and ran sudo apt update, sudo apt install git, and then cloned the otg-set-mode repo onto the Pi Zero W.

Before making any changes I made a backup copy of my /boot/config.txt and the /boot/cmdline.txt and then used the otg script to set the USB port as a serial device. I also enabled a console on the serial port.

sudo ./otg-set-mode.sh g_serial

sudo systemctl enable getty@ttyGS0.service

I rebooted again and connected a cable between the USB port on the Pi Zero and another computer. After the Pi Zero booted I used screen to connect to the serial port on the computer and I received a prompt from the Pi Zero and successfully logged in over the USB OTG serial connection.

Keanu-S commented 2 years ago

I'm pretty sure it just didn't work because I didn't clone the repo I thought it was just put in the sudo, how do I clone it to the pi?

bnielsen1965 commented 2 years ago

You will need to install the git client then run the clone command...

sudo apt install git git clone https://github.com/bnielsen1965/otg-set-mode.git

You should end up with a directory named otg-set-mode that will contain the shell script.

However, cloning the repo is not necessary, you can download the script file or even cut'n'paste the script. But, if you go that route you need to make sure the script file you end up with is executable.

chmod a+x otg-set-mode.sh

Keanu-S commented 2 years ago

It keeps saying command not found for sudo ./otg-set-mode.sh https://github.com/bnielsen1965/otg-set-mode.git

bnielsen1965 commented 2 years ago

Make sure you are in the directory after the git clone.

cd otg-set-mode

sudo ./otg-set-mode.sh g_serial

Keanu-S commented 2 years ago

Ok it worked but the last one sudo systemctl enable said too few arguments

bnielsen1965 commented 2 years ago

Quick question, is your Pi Zero W connected to WiFi and are you using ssh to connect to the Pi?

The reason I ask is because I'm not sure if you can still connect a USB keyboard once the USB comes up as an OTG device.

If you are using ssh over WiFi then you should be okay to proceed...

Reboot the Pi so it can come up with the new settings applied for the OTG device.

Then ssh into the Pi and check to see if the serial device was created.

ls /dev/tty*

You should get a listing of all tty devices and there should be a /dev/ttyGS0

If there is then try enabling console on the tty again...

sudo systemctl enable getty@ttyGS0.service

Not sure but may also need a sudo systemctl start getty@ttyGS0.service, or another reboot.

At this point if you connect a USB cable between the Pi and another computer where you can launch a terminal program like putty or screen then you should get a login prompt for the Pi over the USB serial connection.

Keanu-S commented 2 years ago

I have ttyS0 but not ttyGS0

bnielsen1965 commented 2 years ago

Hmm, is that after a reboot? Did the proper settings make it into the /boot/config.xt and /boot/cmdline.txt?