Raspberry Pi B models have 5 USB ports. The USB type and speed improved with later versions. Here we discuss the Raspberry Pi's USB ports.
Table of contents
Introduction to the Raspberry Pi’s USB ports
Raspberry Pi B models have 5 USB ports — one for power input and four to connect peripherals to. On the Raspberry Pi 4B the USB-C port doubles as an “OTG” port.
The four standard USB (Type-A) ports are used to connect peripherals such as a keyboard and mouse, game controllers, USB Drives, USB adapters, and external hard drives.
When more than four peripherals are required, a USB hub can be used to add additional USB ports to a Raspberry Pi.
Important factors when it comes to the USB ports of the Raspberry Pi are the type of USB ports, the USB port transfer speed, the current limit per USB port and USB boot capabilities. OTG functionality for the Raspberry Pi 4B is also discussed.
- Get the Raspberry Pi 4B 4GB Starter Kit from Amazon.com
- Get the Raspberry Pi 4B 8GB Starter Kit from Amazon.com
- Get the 512GB USB 3.0 Flash Drive from Amazon.com or BangGood
Raspberry Pi USB types
Power to the Raspberry Pi B+, 2B, 3B, and 3B+ is supplied using the Micro-B USB (aka Micro USB) port on the side of the board. This port has been replaced by a USB Type-C on the Raspberry Pi 4B.
The four larger Type-A USB ports at the bottom of the board range from four x USB 2.0 on the Raspberry Pi B+, 2B, 3B, and 3B+ to 2 x USB 2.0 plus 2 x USB 3.0 on the Raspberry Pi 4B.
Raspberry Pi USB port speed
USB Flash drives and external hard drives are commonly connected to transfer data to and from a Raspberry Pi. For data transfer, the faster USB 3.0 ports are preferred over USB 2.0 ports. At the time of updating this post, it was only the Raspberry Pi 4B that had USB 3.0 ports.
USB port speeds are dependent on their version and can be classified as follows:
- USB 1.0/1.1 (low-speed) = 1.5Mbit/s
- USB 1.0/1.1 (full-speed) = 12Mbit/s
- USB 2.0 (high-speed) = 480Mbit/s (60MB/s)
- USB 3.0 (SuperSpeed) = 4.8Gbit/s (600MB/s)
Unfortunately, these are not the actual USB port speeds of the Raspberry Pi. The USB ports of Models B+, 2B, 3B, and 3B+ have a single root USB bus from the processor which is shared with Ethernet. This means that the maximum bandwidth (480Mbit/s) is shared between the four USB ports.
The Raspberry Pi 4B has a PCIe lane running from the processor to the PCIe-USB Chipset, meaning its maximum bandwidth (4.8Gbits/s) is also divided between the four USB ports. The USB 2.0 ports will be limited to high-speed.
Changing the port speed of the Raspberry Pi
Sometimes the Raspberry Pi gives issues after connecting older USB 1.0/1.1 devices. In these cases, it might be necessary to change the Raspberry Pi’s USB port speed from high-speed to full-speed.
This can be done by adding the speed parameter to the USB driver in the /boot/cmdline.txt
file. By default, this parameter will not be set.
To access and append the cmdline.txt file for this purpose, the nano terminal command can be used (with sudo privileges):
sudo nano /boot/cmdline.txt
and adding the following line to the end of the file:
dwc_otg.speed=1
The file can be saved and closed by pressing Ctrl + X and then Y and Enter.
The trade-off of downgrading the USB port speeds on the Raspberry Pi is that newer devices might now start to give issues. If this is the case, it’s better to change the USP port speeds back to their default and upgrade the devices instead.
Raspberry Pi USB current limits
Another important aspect of the Raspberry Pi USB ports is their current limit.
When the recommended power supply is used, the cumulative current output of the Raspberry Pi B+ and 2B USB ports is 600mA. This can be increased to 1.2A by changing the max_usb_current
boot parameter in the boot configuration file.
To access and append the boot configuration file for this purpose, the nano
terminal command can be used (with sudo privileges):
sudo nano /boot/config.txt
and adding the following line to the end of the file:
usb_max_current = 1
The file can be saved and closed by pressing Ctrl + X and then Y and Enter.
Since the Raspberry Pi 3B, the maximum current of the USB has been increased to 1.2A and it can’t be changed.
When the cumulative current of the connected USB devices is higher than 1.2A, the Raspberry Pi is starting to give errors or show abnormal behaviour or external USB drives are to be connected, it is better to use a powered USB hub (see below).
Connecting a USB hub to a Raspberry Pi
A USB hub is a device that expands one USB port into several. This will allow more than, the usual, four USB devices to connect to a Raspberry Pi. Up to 15 USB devices can be connected to a Raspberry Pi at the same time.
Some USB hubs are powered, while others draw their current from the main USB connection. Because the current limit on the Raspberry Pi’s USB port is fairly low, especially when other USB devices are also connected, it is advised that a powered USB hub is used instead.
Raspberry Pi USB boot
The Raspberry Pi 4B has USB boot capabilities. This feature allows the Raspberry Pi to boot from a bootable Flash drive connected to one of the USB ports.
Any Raspberry Pi compatible operating system can be installed onto a USB Flash drive in the exact same way it is installed on a MicroSD card.
USB boot is configured in the Raspberry Pi’s bootloader, which is stored in the EEPROM. Older versions of the bootloader still have USB boot disabled. Fortunately, by simply updating the Raspberry Pi’s firmware, the bootloader will also be updated to enable USB boot. Even if USB boot is enabled, the Raspberry Pi will revert back to the MicroSD card if no bootable USB device is available.
The Raspberry Pi’s firmware is updated using the following terminal command:
sudo apt-get dist-update
The updates will only take effect on the next boot, but before then the USB Flash drive can be connected and the MicroSD card needs to be removed. The Raspberry Pi can be safely shut down by using the shutdown terminal command:
sudo shutdown
To boot the Raspberry Pi after it has been shut down, simply connect the power supply again.
Raspberry Pi USB On-The-Go functionality
The Raspberry Pi 4B has so-called On-The-Go (or OTG) USB functionality on the USB-C port.
Technically speaking, OTG is a technology that allows a USB device (e.g. a mobile phone) to act as a host for devices such as keyboards, Flash drives, cameras, etc. It allows the mobile phone to switch back and forth between the host and the peripheral.
Although referred to as OTG, the Raspberry Pi 4B USB-C port was designed to turn it into a peripheral. The other four USB ports can be used when the Raspberry Pi is to be used as a host.
This, for example, allows the Raspberry Pi to be connected directly to a PC using a USB-C cable and have SSH access to it. In this case, there is no need for a network connection, keyboard, mouse and/or screen.
Conclusion
Here we discussed the Raspberry Pi’s USB ports. The boards come standard with four USB ports which can be used to connect peripherals such as a keyboard and mouse, game controllers, USB Drives, USB adapters, and external hard drives. A USB hub can also be connected to the Raspberry Pi to extend the number of available USB ports.
Important factors when it comes to USB ports are their data transfer speed, the amount of power they can supply and USB boot capabilities.
The type of USB ports, the USB port transfer speed, the current limit per USB port, USB OTG functionality and USB boot capabilities of the Raspberry Pi were also discussed.