The Raspberry Pi is a well-liked single-board laptop utilized in many DIY initiatives. Whereas sometimes used with a monitor, keyboard, and mouse for on-site interplay, there are cases the place it’s possible you’ll must entry your Raspberry Pi from a PC or laptop computer utilizing only a USB connection.
We’ll stroll you thru the method, providing you with entry to your Raspberry Pi through a USB connection so to enter instructions and even entry its GUI desktop.
USB Gadget Mode
The important thing characteristic facilitating direct USB connection to the Raspberry Pi on Linux is named “USB gadget mode”. This characteristic is especially helpful for accessing the Raspberry Pi through SSH; as an alternative of utilizing Wi-Fi, you are able to do it by connecting your Raspberry Pi to a laptop computer through USB.
With gadget mode activated, there is no must configure a Wi-Fi community or connect peripheral units. The characteristic is obtainable for Raspberry Pi 4 and Raspberry Pi Zero fashions, nevertheless, it’s unclear whether or not it’ll work on the brand new Raspberry Pi 5.
Our in-depth evaluation of key variations between Raspberry Pi 4 and Raspberry Pi 5 goes deeper into what has modified with the brand new flagship mannequin.
Important Elements Required for the Setup
Here is an inventory of what you will want:
- Raspberry Pi 4 or Zero / Zero W / Zero 2 W
- USB-C cable (adapter wanted for micro USB port on Zero fashions)
- Laptop computer or desktop PC
- microSD card
Putting in the Working System
Begin by putting in Raspberry Pi OS in your microSD card. This has been made actually user-friendly due to the official Raspberry Pi Imager instrument, which simplifies microSD card flashing.
Set up and launch Raspberry Pi Imager in your PC. Click on Select OSthen choose Raspberry Pi OS from the listing. Click on on Select SD card and choose the storage medium the place you plan to flash the OS: your connected microSD card.
Entry superior settings by clicking the gear icon situated on the backside proper. Configure the hostname as raspberrypi.nativeallow SSH, and set the username to pi (or no matter you need) with a password of your choice.
Click on on Save. Lastly, provoke the flashing course of by clicking Write.
Setting Up Your Raspberry Pi
To allow USB gadget mode on Raspberry Pi, we’ll must make some configuration adjustments. Whereas the microSD card continues to be related to your laptop, navigate to the boot listing utilizing the file browser or command line. Inside this listing, find and edit the config.txt file by appending the next line to it:
dtoverlay=dwc2
This configures the Raspberry Pi to allow the DWC2 (DesignWare Core) module, which manages the USB (Common Serial Bus) performance. It refers back to the USB controller used within the Raspberry Pi {hardware}. The DWC2 module is vital for enabling USB gadget mode, permitting the Raspberry Pi to behave as a USB gadget, reminiscent of an Ethernet adapter, when related to a different laptop through USB.
If this file accommodates the road otg_mode=1remark it out utilizing a “#”:
The otg_mode=1 setting prompts USB gadget mode, however it's pointless when dtoverlay=dwc2 is in use. It is because dtoverlay=dwc2 already manages the USB gadget mode.
Within the cmdline.txt file, discover the rootwait command and instantly add the next line after it.
modules-load=dwc2,g_ether
This line provides two vital modules throughout boot: dwc2 and g_ether. The dwc2 module manages the DWC2 USB controller, important for USB gadget mode, whereas g_ether allows Ethernet gadget performance. Collectively, they permit the Raspberry Pi to emulate an Ethernet adapter through USB, enabling SSH entry and not using a direct community connection.
A reference snippet of the cmdline.txt file ought to appear to be this:
console=serial0,115200 console=tty1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline fsck.restore=sure rootwait modules-load=dwc2,g_ether quiet init=/usr/lib/raspi-config/init_resize.sh
Save the file and exit the textual content editor.
Further Configuration Choices for Home windows Customers
Some further changes could also be required for Home windows customers. To resolve the .native host tackle of your Raspberry Pi, it's worthwhile to set up Bonjour Print Companies for Home windows.
RNDIS Driver Set up
In case your Raspberry Pi seems solely as a COM port within the Machine Supervisor, you will want to put in the RNDIS Driver.
Community Sharing Configuration
To share your community connection from the Home windows host to the Raspberry Pi, navigate to Management PanelNetwork and InternetNetwork Connections.
Seek for USB Ethernet/RNDIS Gadget to establish the Raspberry Pi Community Adapter. Be aware of its title (you'll be able to change this if you wish to). Proper-click on the community you need to share and go to Properties. Then, go to the Sharing tab.
Choose Enable different community customers to attach via this laptop's Web connection.
Accessing the Raspberry Pi through SSH
As soon as your USB connection is established, you'll be able to entry the Pi through SSH. Open a terminal in your laptop and enter the command under:
ssh pi@raspberrypi.native
This provides you with entry to the Raspberry Pi’s command line.
Accessing the Raspberry Pi Graphical Interface with VNC
To make use of the graphical interface, VNC (Digital Community Computing) is a extremely beneficial instrument. VNC means that you can entry the Raspberry Pi's GUI remotely from one other laptop. In your SSH session, enter the next command:
sudo raspi-config
Throughout the Raspberry Pi Configuration menu, navigate to Interface Choices and press Enter.
Use the down arrow key to pick out VNC. Affirm your selection by urgent Enter once more.
In your PC or laptop computer, set up the RealVNC Viewer utility. Launch the RealVNC Viewer in your laptop. Within the RealVNC Viewer interface, underneath the Host part, enter the tackle raspberrypi.native and press Enter.
After connecting, you need to see the Raspberry Pi's graphical interface displayed in your laptop display.
Troubleshooting
There are frequent errors that you could be run into when establishing a USB connection between your Raspberry Pi and a PC.
In the event you encounter the Can't At present Present the Desktop error whereas making an attempt to connect with VNC, return to your SSH session and execute the command under:
sudo raspi-config
Navigate to System Choices and select Boot / Auto Login. Use the down arrow key to pick out Desktop Autologin Desktop GUI, robotically logged in as 'pi' consumer. Then navigate to Show Choices and select VNC session.
Press Enterthen choose End. You may be prompted to reboot; choose Sure. This could resolve the error and let you connect with VNC efficiently.
Additionally, be sure that your Raspberry Pi's working system is at all times up-to-date as this eliminates compatibility points and enhances general efficiency
Management the Raspberry Pi From a PC through USB
As soon as the Raspberry Pi board is related to your laptop computer (or different PC) through USB, you'll be able to entry its command line through SSH. Moreover, by enabling VNC, you can too entry Raspberry Pi's graphical interface out of your laptop computer utilizing the RealVNC Viewer utility.
This methodology offers a handy solution to work together with the Raspberry Pi utilizing solely a USB connection—particularly helpful in case you can’t entry a wi-fi community.
