The Raspberry Pi Zero is limited, or so everyone says, and everyone is trying to cram a USB hub and WiFi adapter on this tiny, tiny board. One thing a lot of people haven’t realized is that the Raspberry Pi Zero comes with a USB OTG port, meaning it can function as a USB device rather than a USB host. This means the Raspi can become a serial device with just a USB cable, an Ethernet device, MIDI device, camera, or just about anything else you can plug into a USB port. Adafruit has your back with a tutorial for using the USB OTG port as a serial and Ethernet interface, and the possible applications are extremely interesting.
The only requirement for using the USB OTG port for device applications is an update to the kernel. This is easily installed by dumping a few files on an SD card and a employing bit of command line wizardry. The simplest example is setting up the Pi Zero as a USB serial device, allowing anyone to log into a serial console on the Pi with just a USB cable.
A slightly more interesting application is setting up the Pi as an Ethernet gadget. This effectively tunnels all the networking on the Pi Zero through a USB cable and a separate computer. The instructions are extremely OS-specific, but the end result is the same: you can apt-get
on a Pi Zero to your heart’s desire with a new kernel loaded onto the SD card and a USB cable.
This experimentation is just scratching the surface of what is possible with the OTG port on the Pi Zero. MIDI devices are easy, and with a ton of GPIOs, the Pi Zero itself could become a very interesting musical instrument. Want the Pi Zero to be a storage device? That’s easy too. The USB Gadget will end up being one of the most exciting uses for the Pi Zero, and we can’t wait to see what everyone will come up with next.
Masstorage is possible?
Trying to make this as simple as i can, yes, it is basically a hex word that determines what class the device is. Another decides the subclass etc.
On this level the only difference between HID(human interface device class) , or MSD (mass storage device class) is a few bytes called descriptors.
CDC class for the serial stuff they mention most likely. Any of these protocols are good reading to see how it works, usb complete the book by jan axelson is the next place to go if you wanna become an expert.
It is a bit more than a few bytes in the descriptor. The commands are different and the data transfer are different: HID uses interrupt transfer and MSD uses Bulk transfer.
in most reasonable usb stacks this is all handled by switches in code. Just flip a flag and you are set. But you need to actually look up the descriptors. Not many people write their own usb stacks and need to worry about that.
In the Linux stack which we’re talking about here, you don’t manipulate the descriptors, you just load the usb-f-mass-storage module instead of the usb-f-hid module. And if you had to manipulate the descriptors then you’d be at a level where you’d need to implement a completely different behaviour for the mass storage device to work.
when you dive below the board pc level and make your own it is as i say.
Much more insteresting is Masstorage emulated device with extra features.
Such like: Emulated USBdongle/(SD or HDD) with ethernet do media players or STB without LAN port
or really strong encrypted disk. ( many comercial disks with encryption have backdoors :P like xored password in WD HDDs)
Another idea is device which has 2 connections STB is recording TV stream (exlusive access read+write)
and another device(only reading) for example TV is reading/playing other content in same time.
I am missing long time low power consumption device like this. It’s possible only with LAN devices :(
isostick.com project emulating masstorage with AVR32 processor.
XOR a password with itself = super strong security!
Agree, the first custom usb device I made from as low as you can get before writing a stack from scratch, was an audio device midi subclass, and composited with an msd device that installed when you plugged it in. It had a midi mixer and an sd card to hold the music to mix. It was also capable of some shady business since if you didnt tell people they often didnt realize it had a harddrive in it. It just didnt make sense to me that usb midi mixers didnt have on board storage for the music you mix at gigs. :) The one in this video I didnt solder on the sd card and i never made a video of one with it before I gave them all away. https://www.youtube.com/watch?v=5kYEQ0o0pSo
Would be interesting to see if the PI Zero could be used as a PC controller. giving quite a bit of customisation. add a couple of sliders and some switches and you’ve got a pretty solid flight sim panel or something along those lines.
in this case a duino is a better , easier , more accessible choice imho.
Or a Digispark Pro.
Or a regular Digispark from China for $1.20 (including shipping) running V-USB-
https://www.obdev.at/products/vusb/index.html
Or MSP430F5529 or comparable with USB, capsense, RTC and ….
Might be fun- to use the full potental of the Zero you could use a little touchscreen too, instead of just pots.
Ain’t that possible with a Pi A/A+?
My understanding is it is not, because the SoC USB OtG port on those is already directly hooked into a USB hub chip (with Ethernet).
Not on the A/A+. The SoC USB goes right to the jack.
You’re mistaken, that’s why I said A/A+ – they don’t have a USB hub chip.
Yes, correct about no hub on A/A+, but still not wired up as OtG USB port like on Zero. Maybe this could be hacked around, I’m not sure.
Care to explain the wiring differences?
I am no expert, but as I understand it, an OtG port has an extra “sense” or “ID” line that determines when it should be a USB host instead of a USB device. See https://en.wikipedia.org/wiki/USB_On-The-Go and http://tech.firstpost.com/wp-content/uploads/gallery/2012/jun/difference_circuit_271738111300_640x360.jpg
There may well be some way around this, but I haven’t seen it.
Actual high res USB camera? Most webcams are horrible. Maybe make an interface to a DSLR or point and shoot?
Logitech has some nice HD webcams
We already have CHDK and chdkptp for Canon point and shoot.
Most cheap webcams are junk. I have a 24megapixel usb webcam that takes C mount lenses. you have to spend money if you want good. and it was only a couple hundred sans lens.
Mind sharing what your make and model are?
Beaglebone says hi.
BeagleBone says “gimme 700% more cash”
Good point. BB is bigger, more powerful, more expensive, more capable. For many purposes, this is enough; if it isn’t, a BB(B) is a great alternative.
Very true, though the extra USB host on the BBB is great for USB protocol analysis
Beaglebone also has 4000+ pages of CPU and peripheral documentation, HW 2xCAN, 2xEthercat, PRU’s and more. Beat that Broadcom!
Idea: use it as a password manager. It’s got a relatively strong cpu, so encryption shouldn’t be too big of an issue, especially if it’s just encrypting and decrypting passwords on the fly. I would make a break out board with a small number pad and an enter key. There would also bee two leds, one red, one green.
When you plug the pi in it appears as just a generic keyboard, and the red light appears. You type in your pin and hit enter. The light turns green. Then you punch in a number corresponding to the password you need and hit the enter button. The green led flashes as it “types” out the password into whatever password prompt you have open on the PC. Then it locks it self again so you don’t have to worry about forgetting it plugged in and unlocked.
It would also be a nice base for something like a Mooltipass.
A great use case could be emulating a USB optical drive from ISO files stored on the SD card. That would be very helpful as existing ISO to USB drive solutions might not work with some “special” images.
That is a very cool idea.
Don’t isosticks already do that?
They cost quite a bit more than a Raspberry Pi Zero, a BeagleBone Black, or even a Dragonboard 410c.
yes they do, and this would be really helpful but I dont want to have to keep swapping out the uSD all the time, wish the pi’s had a sata port :/
You guys should really talk more about gadgetfs, the greatest usb gadget driver for this crowd. The ability to emulate usb devices in any language!
the main problem i still see with this (otg gadget) is that the SD image still gets corrupted if powered down unexpectedly, we really, really need a distro that runs live from memory-only or is otherwise resistant to this.
Literally nothing requires you to have a read-write filesystem on your SD card. Boot Linux with an initramfs embedded into the kernel image.
You can treat the SD essentially as NVRAM, if you want; one location should be an index, and you should have at least two “slots” for data in some fixed-size struct. Update data by writing a whole slot at once, sync, then update the index to point at the new slot. (In other words, if you want minimal redundancy, just keep two slots and alternate back and forth; otherwise do something more interesting if the slot or the index appear to be invalid, like scan for any “valid” slot in any of the known locations.) It’s poor-mans journaling.
Yup. Last of all, put a CRC on your structure, so you can tell if the write failed. Beyond my experience to code, but there’s plenty of clever people working on Linux, plenty of Pi’s around the place, really surprised this bug has persisted for so long. It’s affecting people’s ability to use the Pi in embedded applications, really not good enough.
Yep the #1 reason that limits my use of the PI in any long term way.
They exist, and though I haven’t seen one on raspi yet, I doubt it would take that much work.
OpenWRT?
honestly make your own, it’s brain dead simple to do.
http://www.ibm.com/developerworks/linux/tutorials/l-embedded-distro/
Is it possible to have 2 partitions on the SD card, one writable, one not? So you’ve at least got a stable OS to boot from, even if your data gets lost?
And could the filesystem people sort it the fuck out? How about a supercap and an IO line to detect when main power goes down? Surprised that isn’t a common hack, although I realise it’d double the cost of the Zero, and add a big chunk to the other Pi’s.
Should surely be possible though to produce a robust file system, rely on atomic operations, and step-by-step writing, so that when reading it the computer can detect where it failed. At most you should lose whichever files were open, and even they should be partly recoverable. Is there a reason why this hasn’t happened? Kindof a major bug.
Debian (and raspbian) comes with the package ‘flashhybrid’.
So can it be used as an Ethernet to USB adapter, with a USB to RS232-C adapter, to connect something like a TI-99/4A to a LAN?
It would be easier to use a B+ for that but with this: http://hackaday.com/2015/12/06/pi-zero-ethernet-the-hard-way/ and MAX3232 you could do a serial to ethernet or even a wireless version with this: http://hackaday.com/2015/12/09/raspberry-pi-wifi-through-sdio/
Could this be used as a bus pirate / ft232h / tiny bit dingus?
BeagleBone has had this feature for years now and its one of the reasons i will still choose the BBB for projects. Not sure why this didnt come about sooner :P
You could use it as a fake KVM (only after the OS has booted, though), based on https://github.com/kopasiak/f_dl_ffs, and the HID gadget support already built in to the kernel.
http://pi.gbaman.info/?p=699
Bit more info here
I’m going to guess it’s the ancient USB2.0..
But back on subject, obviously you can already do much of this with other boards but what makes the pi zero different is its ability to run more complex code. So to think up something innovative it would need to use that capability IMHO.
But of course thinking up something new is hard, ask apple/samsung/HTC/sony/microsoft/et cetera
Just checked pi zero availability, it’s now on pre-order at a big euro retailer for… €19.99 (current exchange rate= 22 US dollar), but that is including tax.
So much for $5. But I predicted it already.
I made a preconfigured image for this, which fits on 2GB card:
https://sourceforge.net/projects/pizero-usbhost (ignore the wrong title in url !)
Only the USB networking enabled in that, but gets you up and running quicker.
I realize this is a newer entry to an older activity, but I’ve finally found the time to make up of the little guys.
For those of you in NYC, I shall be exhibiting my creation, plus two mascots at the Hack A Day NYC Demo activity for 8/30/2017.
And it would be worth a big heap of a very special crystals, if you could be there Brian B.