forgot to go to root's home

This commit is contained in:
2026-08-27 13:38:17 +00:00
parent 464ed79f95
commit 075fd124cd
+120 -119
View File
@@ -1,119 +1,120 @@
# Gadget Mode to setup a serial connection over USB # Gadget Mode to setup a serial connection over USB
Prepare Raspberry Pi OS connection over a microUSB serial cable Prepare Raspberry Pi OS connection over a microUSB serial cable
Based upon Adafruit guide: https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget: Based upon Adafruit guide: https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/serial-gadget:
The author discovered the guide was out of date, consulted the [2025 Raspberry Pi whitepaper on OTG](https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs), found additional errors, and was finally able to correct them thanks to this blog https://www.isticktoit.net/?p=1383 The author discovered the guide was out of date, consulted the [2025 Raspberry Pi whitepaper on OTG](https://pip-assets.raspberrypi.com/categories/685-app-notes-guides-whitepapers/documents/RP-009276-WP/Using-OTG-mode-on-Raspberry-Pi-SBCs), found additional errors, and was finally able to correct them thanks to this blog https://www.isticktoit.net/?p=1383
## Important : ## Important :
- **Using the Gadget Mode will make the usb port unable to connect to a mouse or keyboard!!!** You will need to disable it make them work again. - **Using the Gadget Mode will make the usb port unable to connect to a mouse or keyboard!!!** You will need to disable it make them work again.
- You will want to disable the serial console on RX/TX in `raspi-config` if you are trying to use that serial port for communicating with other devices. - You will want to disable the serial console on RX/TX in `raspi-config` if you are trying to use that serial port for communicating with other devices.
## Procedure ## Procedure
Make sure you have your USB cable plugged into the left port **USB** and not the right port marked **PWR**. Make sure you have your USB cable plugged into the left port **USB** and not the right port marked **PWR**.
1. Open a connection to the device via ssh or Raspberry Pi Connect 1. Open a connection to the device via ssh or Raspberry Pi Connect
1. Become root (the superuser) 1. Become root (the superuser)
``` ```
sudo su sudo su
``` ```
1. Enable the DWC version 2 USB peripheral device tree overlay by appending it to the end after the `[all]` category (which is at the end) 1. Enable the DWC version 2 USB peripheral device tree overlay by appending it to the end after the `[all]` category (which is at the end)
``` ```
echo "dtoverlay=dwc2" >> /boot/firmware/config.txt echo "dtoverlay=dwc2" >> /boot/firmware/config.txt
``` ```
1. We add the required module `dwc2` for loading at startup 1. We add the required module `dwc2` for loading at startup
``` ```
echo "dwc2" >> /etc/modules echo "dwc2" >> /etc/modules
``` ```
1. Check that we can load the libcomposite module 1. Check that we can load the libcomposite module
``` ```
modprobe libcomposite modprobe libcomposite
``` ```
1. Put a copy of this repository in root's home directory using git 1. Put a copy of this repository in root's home directory using git
``` ```
apt install -y git cd /root
git clone https://gitea.cs.ru.is/RU-V207/rover-pi.git apt install -y git
``` git clone https://gitea.cs.ru.is/RU-V207/rover-pi.git
1. Go to Scripts and test if the `gadget.sh` runs without errors and hopefully a Serial port appers in Device Manager or equivalent ```
``` 1. Go to Scripts and test if the `gadget.sh` runs without errors and hopefully a Serial port appers in Device Manager or equivalent
cd rover-pi/Scripts/ ```
./gadget.sh cd rover-pi/Scripts/
``` ./gadget.sh
1. Install the systemd ```
``` 1. Install the systemd
cp serial-ether-gadget.service /lib/systemd/system/. ```
``` cp serial-ether-gadget.service /lib/systemd/system/.
1. Enable the service ```
``` 1. Enable the service
systemctl enable serial-ether-gadget.service ```
``` systemctl enable serial-ether-gadget.service
1. Enable the getty (which connects a login terminal to the serial port) ```
``` 1. Enable the getty (which connects a login terminal to the serial port)
systemctl enable serial-getty@ttyGS0.service ```
``` systemctl enable serial-getty@ttyGS0.service
1. Reboot and see if the serial port appears ```
1. Reboot and see if the serial port appears
# Connecting to the serial terminal
You will need a serial terminal program (which used to be very very common) in order to communicate over your serial port # Connecting to the serial terminal
You will need a serial terminal program (which used to be very very common) in order to communicate over your serial port
## Windows
- Putty: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html ## Windows
- MobaXterm: https://mobaxterm.mobatek.net/ - Putty: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
- MobaXterm: https://mobaxterm.mobatek.net/
## Linux
If using a Linux VM, you will need to pass the Pi USB connection there. ## Linux
This is similar to the procedure for accessing an Arduino. If using a Linux VM, you will need to pass the Pi USB connection there.
1. Start the Linux VM if you haven't already This is similar to the procedure for accessing an Arduino.
1. Menu: Devices > USB 1. Start the Linux VM if you haven't already
1. Look for "Silicon Labs CP210x USB to UART Bridge" and click on it. 1. Menu: Devices > USB
1. check if port /dev/ttyUSB0 is found. The Pi will most often be accessible over this port. 1. Look for "Silicon Labs CP210x USB to UART Bridge" and click on it.
``` 1. check if port /dev/ttyUSB0 is found. The Pi will most often be accessible over this port.
ls -l /dev/ttyU* ```
``` ls -l /dev/ttyU*
1. The user must be in the dialout group to access it. Use the Linux command: `uid` -to check if you are in the group. If not in the dialout group, use: ```
``` 1. The user must be in the dialout group to access it. Use the Linux command: `uid` -to check if you are in the group. If not in the dialout group, use:
sudo usermod -a -G dialout <username> ```
``` sudo usermod -a -G dialout <username>
1. You will use the GNU `screen` application in Linux to access the Pi. You can install it with: ```
``` 1. You will use the GNU `screen` application in Linux to access the Pi. You can install it with:
sudo apt install screen ```
``` sudo apt install screen
1. You should now gain access to the Pi with: ```
``` 1. You should now gain access to the Pi with:
` sudo screen /dev/ttyUSB0 115200 ```
``` ` sudo screen /dev/ttyUSB0 115200
1. Press enter and you will be prompted to log in to the Pi with default credentials. User: pi - PW: raspberry ```
1. Press enter and you will be prompted to log in to the Pi with default credentials. User: pi - PW: raspberry
# Disabling the OTG mode to use a keyboard and mouse again
# Disabling the OTG mode to use a keyboard and mouse again
**WARNING: Untested**
1. Comment out the dwg2 line in `/boot/firmware/config.txt` using a `#` in front of the line **WARNING: Untested**
``` 1. Comment out the dwg2 line in `/boot/firmware/config.txt` using a `#` in front of the line
[all] ```
#dtoverlay=dwg2 [all]
``` #dtoverlay=dwg2
1. Comment out the dwg2 line in `/etc/modules` using a `#` in front of the line ```
``` 1. Comment out the dwg2 line in `/etc/modules` using a `#` in front of the line
#dwg2 ```
``` #dwg2
1. Disable the gadget service ```
``` 1. Disable the gadget service
systemctl disable serial-ether-gadget.service ```
``` systemctl disable serial-ether-gadget.service
1. Disable the getty ```
``` 1. Disable the getty
systemctl disable serial-getty@ttyGS0.service ```
``` systemctl disable serial-getty@ttyGS0.service
```
# Connecting over the USB ethernet to ssh into your Pi
# Connecting over the USB ethernet to ssh into your Pi
I have not tested this procedure because the serial console and normal network connection is sufficient for me --foley
I have not tested this procedure because the serial console and normal network connection is sufficient for me --foley
https://www.raspberrypi.com/news/usb-gadget-mode-in-raspberry-pi-os-ssh-over-usb/
https://www.raspberrypi.com/news/usb-gadget-mode-in-raspberry-pi-os-ssh-over-usb/
# Untested
Here are items that bear investigating but haven't been tested yet # Untested
Here are items that bear investigating but haven't been tested yet
- [Modify Imager manifest to install otg](https://github.com/raspberrypi/rpi-imager/tree/main/doc/local_json)
- [Modify Imager manifest to install otg](https://github.com/raspberrypi/rpi-imager/tree/main/doc/local_json)