mikerr
Posts: 2770
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Very simple OTG on pi4

Fri Jun 28, 2019 2:21 pm

I've found OTG is really simple and useful on the pi4 with new firmware.

Since the USB-C power port can now carry data, you can plug that into a USB port on your PC and access the Pi via a drive letter.

Image Image

Here's how:

1. Add a single line to config.txt :

Code: Select all

dtoverlay=dwc2
2. Mount the boot partition as MSD on bootup:

crontab -e

Code: Select all

@reboot sudo modprobe g_mass_storage file=/dev/mmcblk0p1 removeable=1
After a reboot the pi will appear as a drive letter under windows, with the boot partition being read/write.

Almost the same as if you'd removed the SD card and put it in a card reader on the PC,
with the difference that this is on the live running Pi.

I've already found this useful for changing wifi settings (drop a wpa_supplicant.conf file on boot), and for small file transfers (boot partition is now bigger in buster: 256MB with 200MB free space)
Android app - Raspi Card Imager - download and image SD cards - No PC required !

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: Very simple OTG on pi4

Fri Jun 28, 2019 6:37 pm

That is weird I got to try that.
Antikythera

User avatar
thagrol
Posts: 1700
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Very simple OTG on pi4

Fri Jun 28, 2019 9:04 pm

mikerr wrote:
Fri Jun 28, 2019 2:21 pm
I've already found this useful for changing wifi settings (drop a wpa_supplicant.conf file on boot), and for small file transfers (boot partition is now bigger in buster: 256MB with 200MB free space)
I'm surprised you've been sucessful with that though things may have changed with Buster.

On stretch (and earlier) if you make a change from one side of the mass storage gadget (e.g. from the USB host) the other side (raspbian) won't see it without unmounting and remounting the partition. Or a power cycle. Or disconnect/reconnect.

You're going to corrupt your data doing this.
This space unintentionally left blank.

lb
Posts: 260
Joined: Sat Jan 28, 2012 8:07 pm

Re: Very simple OTG on pi4

Sat Jun 29, 2019 2:16 am

Yeah, it's not safe to do this!

However, what is completely safe and also very useful is the g_ether module which allows you to let the OTG port act as a network device. It's probably not reliably to possible to power a Pi 4 plus peripherals from a typical PC USB port, but the Pi 4 on its own was fine, with the occasional low voltage warning.

Ebraheem Bambotia
Posts: 43
Joined: Fri Jan 11, 2019 1:27 pm

Re: Very simple OTG on pi4

Sat Jun 29, 2019 4:54 am

This is probably only useful for people who don't have an SD card reader on their PC or laptop and need to make changes in a hurry. Otherwise I don' tsee any point in risking data corruption as thagrol said

fruitoftheloom
Posts: 20143
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Very simple OTG on pi4

Sat Jun 29, 2019 5:33 am

lb wrote:
Sat Jun 29, 2019 2:16 am
Yeah, it's not safe to do this!

However, what is completely safe and also very useful is the g_ether module which allows you to let the OTG port act as a network device. It's probably not reliably to possible to power a Pi 4 plus peripherals from a typical PC USB port, but the Pi 4 on its own was fine, with the occasional low voltage warning.

If using the PoE Hat it could be useful ??
adieu

Asus CS10 Chromebit / HP Envy 4500 Wireless Printer / Raspberry Pi Model 2B v1.1 / RealVNC Software...

User avatar
thagrol
Posts: 1700
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Very simple OTG on pi4

Sat Jun 29, 2019 10:15 am

fruitoftheloom wrote:
Sat Jun 29, 2019 5:33 am
lb wrote:
Sat Jun 29, 2019 2:16 am
Yeah, it's not safe to do this!

However, what is completely safe and also very useful is the g_ether module which allows you to let the OTG port act as a network device. It's probably not reliably to possible to power a Pi 4 plus peripherals from a typical PC USB port, but the Pi 4 on its own was fine, with the occasional low voltage warning.

If using the PoE Hat it could be useful ??
Or power the 4B through the GPIO header.
This space unintentionally left blank.

User avatar
thagrol
Posts: 1700
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Very simple OTG on pi4

Sat Jun 29, 2019 10:19 am

lb wrote:
Sat Jun 29, 2019 2:16 am
Yeah, it's not safe to do this!

However, what is completely safe and also very useful is the g_ether module which allows you to let the OTG port act as a network device. It's probably not reliably to possible to power a Pi 4 plus peripherals from a typical PC USB port, but the Pi 4 on its own was fine, with the occasional low voltage warning.
It can be done safely, just not the way the OP suggests.

The trick is to only have the shared storage mounted on one side at a time.

Or use g_ether as suggested combined with an sftp client or run a samba server on the 4B.
This space unintentionally left blank.

Aardappeltaart
Posts: 45
Joined: Wed Mar 02, 2016 11:32 am

Re: Very simple OTG on pi4

Sat Jun 29, 2019 5:06 pm

I got the RPI4 working and connected to the internet with just an USB cable from my laptop using Ethernet OTG.

Like described here:
https://dev.webonomic.nl/4-ways-to-conn ... e-internet

Dunno if my laptop delivers enough juice to do something fancy, but it's already sweating doing nothing:
61° idle.

Return to “General discussion”