mikerr
Posts: 2825
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: 2963
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.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

lb
Posts: 263
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: 23143
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 ??
Rather than negativity think outside the box !
RPi 4B 4GB (SSD Boot)..
Asus ChromeBox 3 Celeron is my other computer...

User avatar
thagrol
Posts: 2963
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.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

User avatar
thagrol
Posts: 2963
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.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

Aardappeltaart
Posts: 109
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.

ingotee
Posts: 12
Joined: Sat Feb 27, 2016 2:37 pm
Location: Hannover, Germany

Re: Very simple OTG on pi4

Mon Mar 23, 2020 2:07 pm

mikerr wrote:
Fri Jun 28, 2019 2:21 pm
I've found OTG is really simple and useful on the pi4 with new firmware.
May I ask why "the new firmware" should be necessary for OTG? I thought the big fw update just dealt with the VLI USB controller whereas the OTG-capable USB-C port is connected to the USB-2.0-Controller inside the SoC?
If it wasn't for bad luck, I would have no luck at all.

trejan
Posts: 1877
Joined: Tue Jul 02, 2019 2:28 pm

Re: Very simple OTG on pi4

Mon Mar 23, 2020 2:38 pm

ingotee wrote:
Mon Mar 23, 2020 2:07 pm
May I ask why "the new firmware" should be necessary for OTG? I thought the big fw update just dealt with the VLI USB controller whereas the OTG-capable USB-C port is connected to the USB-2.0-Controller inside the SoC?
It isn't necessary. As you said, the new USB firmware is only for the USB 3.0 controller.

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Very simple OTG on pi4

Mon Mar 23, 2020 4:41 pm

ingotee wrote:
Mon Mar 23, 2020 2:07 pm
mikerr wrote:
Fri Jun 28, 2019 2:21 pm
I've found OTG is really simple and useful on the pi4 with new firmware.
May I ask why "the new firmware" should be necessary for OTG? I thought the big fw update just dealt with the VLI USB controller whereas the OTG-capable USB-C port is connected to the USB-2.0-Controller inside the SoC?
Look at the date of the post you are quoting.
Signature retired

ingotee
Posts: 12
Joined: Sat Feb 27, 2016 2:37 pm
Location: Hannover, Germany

Re: Very simple OTG on pi4

Tue Mar 24, 2020 6:33 am

davidcoton wrote:
Mon Mar 23, 2020 4:41 pm
Look at the date of the post you are quoting.
I did. The post is dated after the VLI fw update, so it *could be* that this update made OTG possible. I found another reference that this was because it reduced power consumption and that before that no host would have been able to provide enough power to the RPi. But then you could have powered the RPi via GPIO.

I have no problem if people skip over this rather historical issue. But I am writing/editing a piece about the RPi and OTG so I would like to get it right. The firmware release notes do not mention OTG being faulty or unavailbable before that fw update. I guess I will try and go back to the original fw on one of my RPis.
If it wasn't for bad luck, I would have no luck at all.

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Very simple OTG on pi4

Tue Mar 24, 2020 10:33 am

My point is, nine months on that release of firmware is no longer "new". Unless you are writing about the history, it is just that -- history.
To avoid confusion, write about the latest version, and add the version and date as a header section in your document.
Signature retired

rompelstilchen
Posts: 71
Joined: Thu Mar 03, 2016 10:37 am

Re: Very simple OTG on pi4

Thu May 21, 2020 3:29 pm

this can't work
I plugged my pi4 with an usb C cable , the computer cant even power the PI
you need a Y split cable

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

Re: Very simple OTG on pi4

Thu May 21, 2020 3:38 pm

rompelstilchen wrote:
Thu May 21, 2020 3:29 pm
this can't work
I plugged my pi4 with an usb C cable , the computer cant even power the PI
you need a Y split cable
I think you'll find that had you read through the spec for the 4B and this thread that would have been obvious.

There are a number of options, all of which have been discussed more than once elsewhere on this forum.

A "Y" cable is one depending on how it's used (connecting to two USB ports on the host likely still won't provide enough power), the GPIO header is another.

There is a catch though. Using an unmodified cable risks backpowering the PC. It may or may not be damaged byt this (depending on a number of factors).
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Very simple OTG on pi4

Thu May 21, 2020 3:48 pm

rompelstilchen wrote:
Thu May 21, 2020 3:29 pm
this can't work
I plugged my pi4 with an usb C cable , the computer cant even power the PI
you need a Y split cable
It can work. I had no problem powering the Pi4 from my PC USB3 port and running it as a keyboard gadget.

It may not work in that configuration for everyone, and there are certainly things that would mean the Power was inadequate for the Pi.

I think it depends. YMMV.

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

Re: Very simple OTG on pi4

Thu May 21, 2020 3:53 pm

PiGraham wrote:
Thu May 21, 2020 3:48 pm
I think it depends. YMMV.
Indeed. Reading this might help: https://www.raspberrypi.org/documentati ... /README.md
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Very simple OTG on pi4

Thu May 21, 2020 3:57 pm

thagrol wrote:
Thu May 21, 2020 3:53 pm
PiGraham wrote:
Thu May 21, 2020 3:48 pm
I think it depends. YMMV.
Indeed. Reading this might help: https://www.raspberrypi.org/documentati ... /README.md
Indeed.
Typical bare-board active current consumption 600mA
So a Pi just acting as a keyboard, or maybe just an SD card based storage, might be OK.
But don't get the GPU busy or run any CPU benchmarks!

rompelstilchen
Posts: 71
Joined: Thu Mar 03, 2016 10:37 am

Re: Very simple OTG on pi4

Thu May 21, 2020 6:42 pm

what does dwc2 do ?
please give some explanation instead of blindly copy pasting anything from the web

rompelstilchen
Posts: 71
Joined: Thu Mar 03, 2016 10:37 am

Re: Very simple OTG on pi4

Thu May 21, 2020 6:48 pm

just tried with this setup

Image

modifying the config.txt and crontab as you suggested, it does not work
I get a Unrecognised USB device on win 7

please provide more infos on how to do this

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

Re: Very simple OTG on pi4

Thu May 21, 2020 7:43 pm

rompelstilchen wrote:
Thu May 21, 2020 6:42 pm
what does dwc2 do ?
please give some explanation instead of blindly copy pasting anything from the web
Given the attitude expressed there the only response you're gonna get is: try google.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

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

Re: Very simple OTG on pi4

Thu May 21, 2020 7:47 pm

rompelstilchen wrote:
Thu May 21, 2020 6:48 pm
just tried with this setup

Image

modifying the config.txt and crontab as you suggested, it does not work
I get a Unrecognised USB device on win 7

please provide more infos on how to do this
Largely same suggestion as above for the same reason.

I've used a commercially produced USB A male to USB C male cable and a USB A male to micro B male cable with the offical micro USB to USB C adapter. Both successfully.

Edit:
Fixed typos.

It's likely a driver issue on the windows side. The fact in knows there is a devcie there at all suggests that your wiring is correct.

There have been issues in the past with g_ether and windows. It's a CDC or RNDIS thing. Try a forum and /or web search but broaden it to include the Pi zero.
Attempts to contact me outside of these forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

rompelstilchen
Posts: 71
Joined: Thu Mar 03, 2016 10:37 am

Re: Very simple OTG on pi4

Sat May 23, 2020 11:38 am

thanks for the help

sorry for being "acid" on that one, but

- I found it very frustrating, that no explanation was given, there is a lot of fake, quick crap posted on the web

- I already been searching and it seems like nobody ever tried to use the RPI4 as a USB slave afaik

regards

rompelstilchen
Posts: 71
Joined: Thu Mar 03, 2016 10:37 am

Re: Very simple OTG on pi4

Sat May 23, 2020 11:41 am

thagrol wrote:
Thu May 21, 2020 7:43 pm
rompelstilchen wrote:
Thu May 21, 2020 6:42 pm
what does dwc2 do ?
please give some explanation instead of blindly copy pasting anything from the web
Given the attitude expressed there the only response you're gonna get is: try google.
there is no tutorial on google, hence my suspicious "attitude" toward so few informations

Return to “General discussion”