Raspberry Pi 4 connect it to a computer via USB












Problem:

In the Raspberry Pi 4, the USB Type-C power jack can also be used for data transfer. This can be used for various useful project purposes and ideas, for example, how to connect to a computer trough USB port as an OTG device. ( USB OTG introduces the concept of a device performing both master and slave roles – whenever two USB devices are connected and one of them is a USB OTG device  source )

Solution:

1. Turn on a dwc2 driver writing the next line in /boot/config.txt

dtoverlay=dwc2

2. Use the options for using the Raspberry Pi as a USB device connected to a computer

You will be able to create a small FAT32 file system in a file on an SD card that will appear on the computer as a read / write drive

sudo dd if=/dev/folder of=/piusb.bin bs=512 count=2880
sudo mkdosfs /piMyUSB.bin
sudo modprobe g_mass_storage file=/piMyUSB.bin stall=0

For example, using the next Makerfun USB dongle expansion board for your Raspberry Pi Zero, you will be able to attachc your raspberry pi zero to your computer