We'll start with Serial Gadget, which is the 'simplest' of the USB gadgets. This one basically makes it so when you plug in the Pi Zero to your computer, it will pop up as a Serial (COM) Port - the nice thing about this technique is you can use the pi with any computer and operating system and it doesnt require special drivers or configuration.
Step 0. Download and install latest Raspberry Pi OS
We're using Bullseye Lite but plain Bullseye Raspberry Pi OS should work too!
Step 1. Edit config.txt & cmdline.txt
After burning the SD card, do not eject it from your computer! Use a text editor to open up the config.txt file that is in the SD card post-burn.
Go to the bottom and add dtoverlay=dwc2
as the last line:
Save the config.txt file as plain text and then open up cmdline.txt After rootwait (the last word on the first line) add a space and then modules-load=dwc2,g_serial
At the time of writing, this is the full cmdline.txt contents (in case you need to start over). Note it is one very long line
console=serial0,115200 console=tty1 root=PARTUUID=a0e3f869-02 rootfstype=ext4 fsck.repair=yes rootwait modules-load=dwc2,g_serial cfg80211.ieee80211_regdom=US
Log into your Pi Zero
Insert the SD into your Pi Zero, connect the console cable, power the Pi & log into via the USB console.
While booting, or later when runing sudo dmesg you can see that it bound driver g_serial
Set up logging in on Pi Zero via Serial Gadget
OK just cuz you have a Serial port doesn't mean you can log in with it yet. The Pi knows it has a Serial port but you have to tie it to a console. You can do that very easily with:
sudo systemctl enable [email protected] sudo systemctl start [email protected]
(don't forget the sudo like i did at first!)
You can then verify its running with
sudo systemctl is-active [email protected]
Thats...pretty much it. run sudo reboot to start up your Pi Zero. Plug in a USB Micro cable from your computer to the Pi Zero.
While the Zero is rebooting you can see that it loads the g_cdc module which provides "CDC USB Serial support" (CDC stands for 'communications device class')
On your computer you'll see a new Serial port is created. Check the Windows device driver:
On mac, it will be a new device called /dev/tty.usbmodemNNNN or /dev/cu.usbmodemNNNN where NNNN can be any number
Log into your Pi using Serial Port Software
OK now that your Pi is rebooted and you get that USB serial device again, you can connect to it at 115200 baud (8N1 8-bit No-parity 1-stop if you need to set that)
you can disconnect the console cable, so you dont mix up the USB console cable and the direct-console connection (since they both have COM/Serial ports)
You can also remove the power cable to the 'power USB' port, since the desktop computer will be powering the Pi thru the USB gadget port.
You may have to hit return a few times to get it to come up with the login prompt. But that's it! You're now connected to your Pi Zero directly
Text editor powered by tinymce.