6 ms·
V-USB – A Firmware-Only USB Driver for Atmel AVR Microcontrollers
- peterburkimsher 5y agoFor those curious: Atmel AVR Microcontrollers are commonly sold as Arduino. Some chips (not ATMega 328P but ATMega 32U4) have native support for USB. This allows them to be used as USB HID devices: a keyboard and mouse. Here is someone else's tutorial: https://codeandlife.com/2012/02/11/v-usb-tutorial-continued-hid-mouse/ https://codeandlife.com/2012/02/11/v-usb-tutorial-continued-... And a shameless plug for an app that I wrote that uses an Arduino to turn your laptop into a keyboard & mouse, so you don't have to carry around an external keyboard for your Raspberry Pi. https://hackaday.com/2015/06/27/keymouserial-solves-your-raspberry-pi-keyboard-problems/ https://hackaday.com/2015/06/27/keymouserial-solves-your-ras... In practice I now use CNLohr's EspUSB because it's even smaller. I dug out the old KeyMouSerial code last week to turn a mouse scrollwheel and iPod clickwheel into a rotary encoder. https://www.youtube.com/watch?v=FPBzOaLbWhM https://www.youtube.com/watch?v=FPBzOaLbWhM V-USB can do much more besides: actuators (power switch, DMX), sensors (thermo, hygro), chip programmers, LCD displays... there are 170 projects listed on the Obdev page. https://www.obdev.at/products/vusb/projects.html https://www.obdev.at/products/vusb/projects.html
- szc 5y agoI highly recommend using Dean Camera's LUFA stack if you are going to use the Atmel AVRs that have on-board USB hardware. <https://fourwalledcubicle.com/LUFA.php https://fourwalledcubicle.com/LUFA.php>
- sgtnoodle 5y agoI recently built a force feedback steering wheel from scratch, and used a 32u4 as the MCU. I started the project a few years years ago, but lost interest in favor of picking up 3D printing. It was a lot easier to finish now that I can make arbitrary 3D shapes. I ended up printing an inline 80:1 two stage gear reduction. Thankfully someone in 2020 implemented the HID PID stack for the 32u4. That dropped the firmware work from probably a month to only a few days. The AVR is a bit long in the tooth; I only get a few hundred loops per second while the USB stack is running. It's plenty fast enough for all the haptic effects to feel good, though. It helped to offload the quadrature decoding to a dedicated IC. Years ago I made a control panel for Kerbal Space Program, and I used a V-USB based MCU to drive two analog voltage meters as fuel gauges. I also had an Arduino Uno in the control panel, but I used up every single IO pin on it doing a button matrix and LEDs. Enumerating the V-USB MCU is touchy, but once it's up it seems reliable enough to gamble Jeb's life with!
- aspenmayer 5y agoDo you have any writeups, schematics, parts lists, and/or code you can share? I know folks in the flight sim community who would love to know more!
- sgtnoodle 5y agoIt's on my list of things to do, but I'm about 3 hobby projects behind documenting at the moment. :-) The most interesting bit is probably the gearbox, since it's an 8:1 stage then a 10:1 planetary stage. It's all printed PLA, stainless steel bolts, and bearings from amazon. There's two motors (to make it look cool, since one motor with the 80:1 reduction is probably already excessive), and a 1024 count encoder on the sun gear, giving 40960 counts per wheel revolution. It's all designed around the mounting holes of the steering wheel I used, too, so it's very pretty. The electronics are "boring" in that I used an Arduino Leonardo, a quadrature decoder IC, and a 13A rated H-bridge. The trickiest bit was adding a "braking resistor" to keep the power supply voltage from shooting up when applying deceleration torque. Here's my fork of the Arduino library: https://github.com/sgtnoodle/ArduinoJoystickWithFFBLibrary https://github.com/sgtnoodle/ArduinoJoystickWithFFBLibrary Here's my Arduino sketch containing my project specific code, including the motor control and stuff: http://sgtnoodle.com/files/steering_wheel.ino http://sgtnoodle.com/files/steering_wheel.ino
- glassconclusion 5y agoIs HID PID fully implemented on Windows / Linux (i.e. does it load a generic driver like USB ACM or USB HID mouse / keyboard). I remember that I looked into this, but couldn't find any recent devices that use this.
- sgtnoodle 5y agoYes, both windows and linux have generic driver support for USB force feedback devices. All the firmware needs to do is provide the appropriate HID descriptor. The tricky bit is that the windows driver doesn't fully comply with the protocol spec, though. So, vendors that rely on the generic driver implement their firmware to be out of spec so that their products work in windows. The linux driver is rather pedantic about the spec, and errors out during initialization if the firmware doesn't conform to it. In order to get my wheel working on linux, I had to modify the arduino library to comply with the spec. It was clearly written to work with windows. I haven't tried it on windows yet, but I suspect that it wouldn't work. There are smaller wheel vendors with stale customer support tickets regarding linux incompatibility. I assume this is one of the reasons that larger companies like Logitech provide their own custom drivers, despite being 90% compatible with the generic HID spec. If you're curious, I forked the arduino library with my fixes: https://github.com/sgtnoodle/ArduinoJoystickWithFFBLibrary https://github.com/sgtnoodle/ArduinoJoystickWithFFBLibrary
- guerrilla 5y agoThank you for puting the minimal circuit diagram right there. That was my first question. Everyone else, make sure you check out the examples. Some of these are neat. I have a feeling I'm going to have a lot of use for this later.
- tzs 5y ago> Thank you for puting the minimal circuit diagram right there. And I thank them for it being a proper schematic. Far too many projects nowadays just give a drawing that is essentially a picture of how the circuit would be built on a solderless breadboard such as this [1]. [1] https://v6f7u6f8.rocketcdn.me/wp-content/uploads/2017/04/Mixed.png https://v6f7u6f8.rocketcdn.me/wp-content/uploads/2017/04/Mix...
- arcticbull 5y agoThis has been around for a long long time now so it's super mature, and it's very cool! I've used it in the past to make some esoteric keyboard adapter. You can do a lot with it, but you may run up against a ceiling once you've committed an AVR to V-USB use as the timing requirements even at low bit rates are very strict, and you might want to consider AVRs with built-in USB transceivers if this becomes limiting.
- rkagerer 5y agoMe too! It's great. And one of the few samples of this sort of thing that worked right out of the box.
- linux_is_nice 5y agoOnly somewhat related, but what are some other cheap(~$1) MCUs for a few-key USB keyboard?
- analog31 5y agoI made such a thing using a board called "Teensy LC." I'm a long time user of Teensy boards for prototyping in an R&D environment, and the LC is the cheapest. My interest was just PgUp and PgDn buttons for a foot pedal page turner. In addition, I programmed an ESP32 board to do the same thing, but as a Bluetooth keyboard. Both the Teensy and ESP32 can be programmed via the Arduino development environment. Now there's cheap and there's cheap. The stuff I use is cheap in terms of, it won't break the bank for a R&D or hobby project. Then there's cheap in terms of wringing cost out of a commercial product, which I know little to nothing about.
- HeyLaughingBoy 5y ago> Then there's cheap in terms of wringing cost out of a commercial product This is a very astute distinction that hobbyists wanting to go from Arduino to production often miss. I went from the basically cost-unconstrained world of Medical Devices to wearable consumer sensors (e.g., heart rate monitors, etc.) and it was a bit of a shock to see just how much impact cost had. I mean, you know that in a "theoretical" sense, but it's completely different when you are dealing with it on a daily basis.
- duskwuff 5y ago1. Any ATmega32U4 development board. Most commonly sold as "Arduino Pro Micro". Developing a keyboard emulator in the Arduino IDE is pretty easy; if you don't want to do that, LUFA is a great little USB stack. 2. Raspberry Pi Pico. Newer, so it's less well documented, but much more powerful.
- peterburkimsher 5y agoYes, Arduino, Raspberry Pi, and ESP8266 are the best "cheap MCUs" for personal use, quick shipping, good documentation, for a one-off USB keyboard. For the RPi Pico specifically, the TinyUSB driver is the way to go. This also supports USB host (plugging a keyboard into the Pico), but that didn't support the mouse scrollwheel when I tried. https://github.com/hathach/tinyusb/blob/master/examples/device/hid_generic_inout/hid_test.py https://github.com/hathach/tinyusb/blob/master/examples/devi... If you're interested in larger-scale manufacturing, and are willing to invest more time and effort in once-off R&D to reduce the per-unit cost, then there's a lot more options of other MCUs (e.g. PIC, Cypress, STM32). https://en.wikipedia.org/wiki/List_of_common_microcontrollers https://en.wikipedia.org/wiki/List_of_common_microcontroller... Mitch Davis gave a great talk at the Embedded Online Conference this year (which my wonderful manager assigned us time to watch during working hours!), where he bridges the gap between hobbyist Arduino development and professional Embedded engineering. (It's closer than you might think) https://www.youtube.com/watch?v=mI4FDp5crhE https://www.youtube.com/watch?v=mI4FDp5crhE Miro Samek also has a great series of lectures (which I learned about in the same Embedded Online Conference), which then levels up from an Arduino-style "superloop" to an RTOS, Active Object design pattern, and beyond. https://youtu.be/o3eyz1gEqGU?t=363 https://youtu.be/o3eyz1gEqGU?t=363 Welcome to embedded development, I hope you enjoy creating new gadgets, and don't forget to share your adventures with the community so we can encourage you along!
- colechristensen 5y agoWow, I never would have thought it would be possible to bit bang USB. Did it once for a serial port and that was a big effort in itself
- zamadatix 5y agoIt's USB 1.1 low speed which is 1.5 mbps making it much more achievable than one might think on this class of hardware.
- deleted 5y ago[deleted]
- FounderBurr 5y agoNot to put too fine a point on it, but how can it be “usb 1.1 compliant” while ignoring “communication errors”? Most of the devils in the usb protocol, the kind people resort to usb analyzers for are usually related to communications error states and transitions in the protocol that aren’t being handled properly.
- DarthNebo 5y agoPretty cool to revive a bunch of old Arduino's as plug n play HID input devices across platforms!
- follower 5y agoMany moons ago I "ported" V-USB to the Arduino platform (before any Arduino used an AVR with hardware USB support) & designed a small shield to enable the required hardware side: * http://web.archive.org/web/20120204231721/http://code.rancidbacon.com/ProjectLogArduinoUSB http://web.archive.org/web/20120204231721/http://code.rancid... (via http://web.archive.org/web/20200119053709/http://www.labradoc.com/i/follower/p/vusb-for-arduino http://web.archive.org/web/20200119053709/http://www.labrado... (No thanks to Google for screwing over Google App Engine early adopters.)) The project even got featured in a chapter in a book: http://web.archive.org/web/20120203210440/http://www.practicalarduino.com/projects/virtual-usb-keyboard http://web.archive.org/web/20120203210440/http://www.practic... As I recall it, mine was not the first ever port of V-USB to the Arduino but was IIRC the first released with source & schematic. Fun times & enabled some fun example projects (e.g. keyboards, "encryption" dongle, dynamic product/vendor ID driver fuzzing) before hardware USB support became more common & affordable. I highly recommend the write-up of how they achieved the required throughput to make USB work: https://www.obdev.at/articles/implementing-usb-1.1-in-firmware.html https://www.obdev.at/articles/implementing-usb-1.1-in-firmwa... The write-up is the kind of engaging roller-coaster process of discovery narrative that I thoroughly enjoy reading. :)