8 ms·
Connect to your Raspberry Pi over USB using gadget mode
- megous 3y agoYou can also get console access this way, if you use a different "gadget" (g_serial) and set tty to it on kernel command line. You can also make your own combinations of USB configurations over configfs which is more flexible.
- rektide 3y agoThe beagleboard SBC was amazing for how setup it was. I think the stock image had serial. It also presented a network adapter & host a small network. If you connected, it would advertise a webserver, which was a web IDE for programming the device. Incredible out of box experience.
- astrobe_ 3y agoAs you seem to know well this thing, I'll ask you: they write type "ssh pi@raspberrypi.local" and voilà !", but I know that just enabling an IP stack over a USB link is not enough per se* normally, the device has to have a network configuration (IP address, netmask, gateway) which usually means DHCP. Moreover, how does the ssh client computer know that "raspberrypi.local" is this device?
- megous 3y agoDomain names: https://en.wikipedia.org/wiki/Multicast_DNS https://en.wikipedia.org/wiki/Multicast_DNS Yes, you have to have either some kind of network configuration, and enable the network interface that appears after you pluging in the USB device. It's no different from using USB-ethernet adapters. The easiest is probably to rely on link local addresses and mDNS if all you need is local access from the computer you connected the device to. On a systemd based Linux distros, mDNS is enabled by default in systemd-resolved daemon. On my distro, there's no default configuration for usb network adapters, so I have to do that part by myself. Other systems may work differently and auto-enable USB interfaces and at least setup link local addresses on them. The device implementig the gadget has to do the same.
- regularfry 3y agoI don't think it's possible for the pi to also act as a host on its other USB port if you do this, is it?
- xg15 3y agoSeems true unfortunately, though you can at least switching between the modes somewhat convenient: https://forums.raspberrypi.com/viewtopic.php?t=282649 https://forums.raspberrypi.com/viewtopic.php?t=282649
- regularfry 3y agoYeah, not quite what I'm after. I want usb microphone into usb gadget. Bit of a pain that getting audio in takes an extra hat otherwise.
- simcop2387 3y agoYou should be able to do this with a pi 4, since the usb-c power port is also the gadget port. The usb 3.0 ones off the pcie bus on the pi should be completely independent from that and still work (not sure about the 2.0 ports or anything).
- regularfry 3y agoOh, now that's interesting. Not quite the form factor I had in mind, but worth proving an idea or two out on. Thanks.
- simcop2387 3y agoYep, and if that does work for you, then you might be able to get closer to the form factor you want using a CM4. That said you'd have to learn how to design your own board for it and potentially handle the pcie lane. But that would be a much smaller starting footprint with it at least.
- defparam 3y agoOne of the unfortunate things about the Raspberry Pi Zero is that the second micro usb is power only. For this type of configuration I encourage all to check out the Allwinner ARM-based SoCs and boards built from friendlyelec. With the NanoPi Neo I was able to enable USB ethernet gadget mode on its micro-usb and then have it host and power another device on its USB-A (for me a mobile phone). In my use case the laptop powered both the NanoPi and charging the mobile device all from USB power while also acting a an ethernet packet router from the mobile device back to the laptop all over USB on its own subnet. https://www.friendlyelec.com/index.php?route=product/product&path=69&product_id=132 https://www.friendlyelec.com/index.php?route=product/product...
- villgax 3y agoIf this let's me format USB drives to whatever filesystem & flash ISOs on them then I'm golden with an iPad/Type-c with a decent middleware iOS app
- nfriedly 3y agoThis works on the Raspberry Pi Zero, and the Raspberry Pi 4. I'm not sure about the Zero 2, but I know the other models lack hardware support for the feature. You can buy a cool little PCB that attaches to the Zero and gives it a male USB-A port, turning it into a chunky flash drive or whatever. (They're sometimes referred to as a "BadUSB".)
- regularfry 3y agoDefinitely works on the zero 2. I've built hardware that uses it.
- gruturo 3y agoIt works on any Pi which has only 1 USB port - except for the power port. So on the various "Model A's" and on the zeros. The reason is, the Pi's SOC actually is natively capable of USB Gadget mode, but only offers 1 USB port, and on the various B models they interpose a hub to offer more ports - but gadget mode stops working due to the hub being in between. The Pi 4 is an exception - its USB-C power port works in gadget mode too, unlike its normal USB-A ports, which do not, like all other Pis, because of said hub.
- pletnes 3y agoSo on a raspberry 3A this works over USB-A… but how? Get a female-to-male adapter/cable somehow?
- hinkley 3y agoI see keyboard kits built around the Pico. Are they using this technique or something else?
- regularfry 3y agoGoing to toot my own horn a little bit here. I used this capability on this work project: https://github.com/nhsx/il-magic-scanner https://github.com/nhsx/il-magic-scanner (long story short: use a pi camera to OCR ID info off a phone screen, then pretend to be a keyboard and "type" it into an attached computer). There's a spun-off standalone daemon at https://github.com/nhsx/il-keebd https://github.com/nhsx/il-keebd which handles the "pretend to be a keyboard" bit. It listens on a local socket for text, converts it to scancodes, and squirts them up to the usb host. The keymap isn't complete by any means, but it's got enough there to be interesting.
- jrm4 3y agoOKAY. This is a step closer to my dream idea which I feel like should be possible but haven't figured out, and am curious if anyone has done anything like this: I want to be able to wirelessly change the music on the "USB drive" in my car; i.e. the "drive" is actually an always-on computer, e.g. a Pi. Change the music from the computer at home and be on my way?
- lukifer 3y agoHere’s the solution I built for that, with a combination of on-device voice control, and a Bluetooth remote: https://github.com/lukifer/voicetunes https://github.com/lukifer/voicetunes Something I’d still like to add is a USB OTG emulation of iOS/Android/iPod/etc, so that the currently playing track shows on the dash, steering wheel controls can be used, etc, but my last experimentation a couple years ago didn’t go anywhere. (All the open source stuff for emulating CarPlay and Android Auto seem to be for the other direction: the dash, not the device.)
- jrm4 3y agoThis is very cool - but also waaay more complicated than what I'm talking about here. As in, I'm fine with the SYSTEM that plays music now (I have Toyota Entune) and I don't much want to mess with it. I literally just want to be able to remotely change the files on the USB drive in the car -- without ever having to take it out of the car; that's it.
- sidpatil 3y agoIf you have a spare Android phone with enough storage, and can configure it to mount as a USB mass storage device, maybe you can install an FTP server/Syncthing client/etc. on it, use that to manage the music remotely, and plug it in to your car so that it can see the library.
- numpad0 3y agoAndroid phones usually don’t mount as actual storage devices. The interface is worded that way but it’s different protocol called MTP.
- GlenTheMachine 3y agoUnfortunately there seems to be a bug on Ubuntu 22.04 for Arm that, when you configure the Pi for gadget mode and log in via VNC, X locks after a few minutes. Didn’t do this on 20.04.
- saulrh 3y agoI've done this, it's super useful. The use case for me was that I wanted to simultaneously use two joysticks with the same game, mixing their inputs together instead of just using one or the other for each axis. The behavior only ended up being possible by writing a "joystick mux" program that would accept input from multiple joysticks, combine it, and then retransmit it as a gadget-mode device. Side note, USB HID descriptors are a disaster and someone should do something about it. Even commercial devices by reputable manufacturers have broken descriptors. A tool with modern ergo and integration would probably get a surprising amount of traction. https://github.com/saulrh/composite-joystick https://github.com/saulrh/composite-joystick
- h2odragon 3y agonifty project, thanks.
- sitkack 3y agoThis is awesome! A huge boon to digital artists those interested in HCI research. Also in rust! :) I also noticed how problematic it is to support even major controllers like the PS4 controller under SDL. Games have to be aware of the exact model of controller that they are attached to. I was thinking you could use a RPi0 and it could "clean" all the device specific issues. In your case, there is no reason that a FUSE like USB interposer couldn't exist purely in userland, but this is what we have.
- saulrh 3y agoI actually prototyped the thing in python the first time around, but performance was too poor to pass through even a single joystick, so Rust it was, lol. As for software translation, that was out early in the design process: I needed Windows and I did not want to write a Windows device driver or fight with code signing. Nor did I want a Windows-only or Linux-only solution. So the only solution was to control the platform the software ran on (-> raspberry pi), then drop down far enough in the stack that everyone agreed on a protocol (-> USB HID). I would have been very very happy if I could have implemented this at a higher level.
- jaygreco 3y agoOne cool and lesser-known fact is that you can enable adb on Raspberry Pi with adbd. It’s a fairly seamless way to get console/push/pull over USB. Only downside is that it requires the adb tool on the host as well, vs gadget serial/ssh.
- m463 3y agoNone of this seems to address power. maybe the pi zero is ok. For a pi4 you have to provide power though the usb-c connector and it needs up to 3A. This is also why implementing pi-kvm is so complicated.
- regularfry 3y agoWith the zero 2 you can put the power through one port and the USB-OTG connection into the other. It's fine. I don't actually know if you could power the zero fully through the OTG port, although I wouldn't be that surprised.
- roeles 3y agoYou can, I recently did it. Power on the Zero is connected to the pins, the power USB connector and the OTG USB connector. Afaik, there are no components in-between.
- Eumenes 3y agoDoes a splitter cable exist?
- satori99 3y agoYou can buy cables or small splitter pcb's; https://shop.pimoroni.com/products/usb-c-pwr-splitter?variant=39299226992723 https://shop.pimoroni.com/products/usb-c-pwr-splitter?varian...
- 2OEH8eoCRo0 3y agoI fried one of my Pis by plugging it into my desktop's front USB port.
- velcrovan 3y agoFeels like the ubiquity of these kinds of how-tos implies that the Raspberry Pi is an abundant, ready-to-hand device, which hasn't been true for a few years now. But maybe we’ll get there again soon? Seems like I’ve read people being optimistic about rpi sourcing but it also hasn’t really materialized yet.
- jamiek88 3y agoThe prices aren’t that bad on eBay etc right now. The pi 4 8gb is around $100. I bought one last week for $98. Circa $30 over old retail but then they and so much else will never get back there. Why would it when people will pay the new normal?
- bequanna 3y agoI’ve watched this for the past few months and picked up a Zero W and rpi 3 at msrp. https://rpilocator.com/ https://rpilocator.com/?
- musicale 3y ago> watched this for the past few months yeah I got tired of doing that
- hinkley 3y agoWould be good if more people called this out. I said something regarding how memory inefficient software is these days and how that makes pi clones difficult to use as a sandbox and someone helpfully responded back about how I should be using some model of RPi for that. First, I already have devices. Second, people are still waiting in like to get Pi’s and based on the last interview I saw the Raspberry people think the system is working. They don’t want to raise their prices. I am fairly sure if you have more money to offer your suppliers that scarce components are easier to get ahold of. They could keep their margins the same and raise their rates and generate a lot more revenue.
- LeoPanthera 3y ago> Would be good if more people called this out. "Call it out"? For what? Do you think the Raspberry folks are just choosing to not make enough? I'm pretty sure they don't like the current situation as much as you don't.
- michrassena 3y agoI'm currently trying to do this on my little stack of Pi Zero and Zero 2 boards. I remember at some point this worked great, and then I couldn't get it to work again. So far I'm not having any success. The Pi doesn't show up as a USB device using lsusb on the host. Working my way through a stack of micro-usb cables. Maybe they all are charge only. Anyone have recent success with 64-bit Raspberry Pi OS and Ubuntu on the host end?
- wasabinator 3y agoI used this mode to defeat some arcade dongle protection. It's very handy.
- thomashabets2 3y agoI prefer to connect with SSH over bluetooth. https://blog.habets.se/2022/02/SSH-over-Bluetooth-cleanly.html https://blog.habets.se/2022/02/SSH-over-Bluetooth-cleanly.ht...
- roeles 3y agoDid this with a uugear mega4 ppps usb switch between two pi zero ws. One can be permanently on, drawing just 0.6watt. It can turn on the second pi zero and connect to it.
- musicale 3y agoDidn't realize that the Pi4 supported gadget mode (Pi3 doesn't.) Part of it might be that I got tired of dealing with rpilocator just to find a Pi4 at msrp...