DIY Single axis USB controller

Fixing and making things, what tools to get and what skills to learn, ...
jacob
Site Admin
Posts: 15962
Joined: Fri Jun 28, 2013 8:38 pm
Location: USA, Zone 5b, Koppen Dfa, Elev. 620ft, Walkscore 77
Contact:

DIY Single axis USB controller

Post by jacob »

I want to make a throttle for a game (Rise of Flight) so we're talking just the x-axis of a joystick. I'm fairly confident I can figure out the mechanics, but where do I even get started on the electronics?

(I was kinda expecting a $5 chinapost solution with a potentiometer on one end and a USB cable on the other, but either it doesn't exist or my google-fu is failing me.)

User avatar
Chris
Posts: 773
Joined: Thu Jul 22, 2010 2:44 pm

Re: DIY Single axis USB controller

Post by Chris »

I think you'll need a microcontroller with USB HID support.

Your cheapest option might be to scrounge up an old USB ball mouse (non-optical), or an optical mouse with a scroll wheel. Then the electronics are taken care of, and you can start making hacking the mechanical bits.

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »


jacob
Site Admin
Posts: 15962
Joined: Fri Jun 28, 2013 8:38 pm
Location: USA, Zone 5b, Koppen Dfa, Elev. 620ft, Walkscore 77
Contact:

Re: DIY Single axis USB controller

Post by jacob »

Chris wrote:
Fri Jul 01, 2022 10:14 am
Your cheapest option might be to scrounge up an old USB ball mouse (non-optical), or an optical mouse with a scroll wheel. Then the electronics are taken care of, and you can start making hacking the mechanical bits.
This could be rigged up so the rudder pedals drive a stick linearly under the optical reader. The mouse wouldn't even have to be taken apart for that, just conveniently dropped in. Only problem is that mouse axes are "infinite". However, this would work for something like a trim wheel that doesn't require a "0".
Sclass wrote:
Fri Jul 01, 2022 10:43 pm
https://github.com/FreeJoy-Team/FreeJoy
Ha, I knew you'd have something, but do you have something that's vastly simpler w/o requiring it's own learning curve just to get started? This is several steps up the ladder from where I currently am.

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »


jacob
Site Admin
Posts: 15962
Joined: Fri Jun 28, 2013 8:38 pm
Location: USA, Zone 5b, Koppen Dfa, Elev. 620ft, Walkscore 77
Contact:

Re: DIY Single axis USB controller

Post by jacob »

I've made it a bit further on this.

There's a simply/commercial solution in the form of a microcontroller that connects buttons to USB output. People use it to build arcade machines.
https://www.amazon.com/Reyann-Arcade-En ... 00UUROWWK/

I can now start engines and drop bombs.

However, it seems that most cockpit builders use an Arduino and sliding/rotating potentiometers for throttle/mixture/trim-like controls. However, there seems to be a lot of varieties of Arduinos to choose from these days depending on which features, etc. one desires. Everybody uses a different kind suggesting that the choice may not matter but what do I know...

Question so I don't waste too much money buying the wrong stuff: What would be a good starting Arduino that is easy to work with and doesn't cost a fortune. I'd be happy if it can read resistance on a port and run a few LEDs. It doesn't need to run linux or USB monitors. If it's easy to switch out leads and wires so much the better. Size is not an issue.

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »

Not too sure what your constraints are. You aren’t being really clear about what you’re trying to do.

I keep an old uno around to try code I find online. Sometimes there’s a really cool app I discover and it happens to be written for uno which was popular a decade ago. People are still tinkering with it. The code is somewhat portable around the ATMEGA3XX variants.

If you want to start creating just buy the cheapest clone. Right now the Nano clones are trending at $2. As you need more code space and IO just upgrade to fancier units.

Some may disapprove of piracy. You can learn on the clones and then get real ones as you upgrade. They’re in a surprisingly large number of appliances now. If you look in anything cheap and electronic and it has an Atmel 328 on the board it is often an Arduino in disguise.

I’m not an Arduino person. Also I’m not sure exactly what you’re shooting for here. Maybe others have more ideas.

loutfard
Posts: 356
Joined: Fri Jan 13, 2023 6:14 pm

Re: DIY Single axis USB controller

Post by loutfard »

Not entirely sure of your end goal. If(!) I understand you correctly, any simple Chinese ESP32 board should be perfectly sufficient for what you're trying to achieve.

Kincony (not affiliated) makes boards with detachable screw terminal i/o headers. That might save you quite a bit of soldering and breadboard work and expenses.

You might also want to look into esphome. Quite an elegant lightweight i/o system. If you're lucky, it does enough of what you want to do. Then it becomes yaml configuration only as opposed to C code.

Also, sliding usb midi controllers might be exactly what you want for a more complicated cockpit simulation. These can be found on ali just fine.

jacob
Site Admin
Posts: 15962
Joined: Fri Jun 28, 2013 8:38 pm
Location: USA, Zone 5b, Koppen Dfa, Elev. 620ft, Walkscore 77
Contact:

Re: DIY Single axis USB controller

Post by jacob »

My goal is to build a generic throttle controller and hook it up to a flight sim (likely Rise of Flight) on a win10 computer via USB.

Such as for example this one: https://www.logitechg.com/en-us/product ... 00032.html or this one https://www.amazon.com/Cessna-Throttle- ... 0948BHW2T/

The usual approach is:

1) Build the case/handle/mechanics and connect it to a potentiometer.
2) ????? (but usually involves an Arduino)
3) Connect to PC which somehow recognizes it as a "generic joystick with an axis"
4) Map "generic joystick with an axis" to the throttle in the game.

I know how to do steps 1 and 4.

I would prefer step 2 to use something that's widely available and noob-friendly. My physicist-based electronics knowledge extends to basic components (resistor, capacitor, transistor) and circuits but is limited to simple ICs like 555s. I'm only able to design extremely simple circuits like a pulse generator (lets say 4 components or less :) ). In ERE terms my electronics skill level is at the Compare/Compile stage. I have never programmed or flashed an eprom or whatever the terms are, so clever solutions w/o documentation will not work for me.

Step 3 probably requires some programming.

Since I'm likely to dismantle the throttle once I get bored with it, I'd like the electronics to be generally useful in other projects.

basuragomi
Posts: 419
Joined: Tue Oct 15, 2019 3:13 pm

Re: DIY Single axis USB controller

Post by basuragomi »

Pi Pico/RP2040 with MicroPython has a USB HID library and a billion GPIOs for about $5. Could even build a simple 28-position sliding wiper out of cardboard and tinfoil rather than decode a pot. Pico keyboards are simple enough to do that it's a pretty common beginners' tutorial.

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »

@loutfard ESP32 looks like a great ecosystem. Lots of great hacks coming out for this system. Makes me want to pick up one of those cheap boards and build something.

@jacob. Great. That clears things up. Arduino is the optimal choice for 2). You can do this with five lines of code and a few simple components. Look up reading a potentiometer online. Cut and paste the code. You’ll need a regulated voltage but depending on precision requirements you may just be able to steal the regulated rail off the Arduino. If not this is just a couple of discrete parts on a breadboard. Lots of examples online.

Step 3) I’m not too familiar with because I my old uno board uses a virtual com port for usb. It isn’t true USB and is handled more like an COM port by Windows…not a HID driver that your game may expect. Not sure what Nano does here but the connectivity is there. Also it depends on how your game sets up controllers. I’m not familiar with either so you will likely do some learning here. See how the joystick examples you found work. This is why the ecosystem is important. Somebody out there has done the details on this. The connection is there but you will have to do some digging. If there is a nano joystick or mouse app then you just write the binary values of your potentiometer to the mouse/joystick counts.

A Nano is so cheap on aliexpress it is free to try. First blink the led. Then sample a voltage with the ADC and upload it to your pC using the virtual com port. Then dig into connecting that to your game .

There are many ways to skin this cat. My knee jerk reaction is to download an example of a Arduino based mouse and build on that. You’ll get USB HID and then you can map the sampled rheostat voltages to encoder counts. Basically it’s a mashup of a Arduino custom mouse + potentiometer reader. Do both independently then connect them up with couple of lines of code.

Sounds like you need to just get started. That’s what Arduino is perfect for. Low barrier of entry in both SW and HW.

loutfard
Posts: 356
Joined: Fri Jan 13, 2023 6:14 pm

Re: DIY Single axis USB controller

Post by loutfard »

You may want to use an ESP32-S2 or ESP32-S3 device, preferably one with two usb ports or a jumper based host or guest usb mode. A fairly cheap and well-reputed brand is LilyGo.

For software, you want the tinyusb [0] library. This will help you make your ESP32 into a USB HID device. Into a keyboard/joystick/mouse in human speak. The library is fairly well documented [1].

[0] https://github.com/hathach/tinyusb/tree ... les/device
[1] https://docs.tinyusb.org/en/latest/reference/index.html

sky
Posts: 1726
Joined: Tue Jan 04, 2011 2:20 am

Re: DIY Single axis USB controller

Post by sky »

I bought Arduino Unos from AliExpress for about $5 each. They lasted a year running my hydroponic boxes 24/7, and I am pretty sure they still work.

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »

Okay I just did a quick read on the Arduino Nano. I kept saying Nano but I think the way it implements usb (via virtual com port) may not be compatible with modern game. Back in 1995 yes…when joysticks were RS232 but now I would think the game designers use HID drivers. You’ll need to check into your game documentation.

I have an UNO on my desk here. My recollection is it implements the USB through virtual COM too. A Nano is a little UNO from what I can tell.

After a cursory read it looks like another Arduino like the Leonardo, Due or another that supports the HID keyboard and mouse library is more appropriate.

jacob
Site Admin
Posts: 15962
Joined: Fri Jun 28, 2013 8:38 pm
Location: USA, Zone 5b, Koppen Dfa, Elev. 620ft, Walkscore 77
Contact:

Re: DIY Single axis USB controller

Post by jacob »

I think I'm looking for something like this: https://www.hackster.io/Ingeimaks/ardui ... ick-8c9722
I also see people mentioning using an Arduino Leonardo instead of an Arduino Uno since the former has native USB support. The goal is indeed to turn it into a HID controller.

Add: Sclass beat me to it.

The thing that still stops me in my tracks is seeing pages like this https://www.sparkfun.com/standard_ardui ... ison_guide with 20+ different options :(

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »

Ok…I’ve read over that example. :|

This is a lot more complicated than programming up a USB HID mouse or keyboard on a chip and expecting it talk to ROF. X360ce is an emulator program that presumably takes USB endpoint data and interprets it into xbox game pad IO for the PC. Then they need to reflash the UNO board with their own hack ware UNOJoy to get the Arduino to act like a USB joystick.

So while it is “just program up a board with HID counts from digitized pot values” there are a few more details in there to make this work. I read enough of the GitHub and x360ce documentation to realize this isn’t all that simple. If they got it all working that’s great. Use it.

jacob
Site Admin
Posts: 15962
Joined: Fri Jun 28, 2013 8:38 pm
Location: USA, Zone 5b, Koppen Dfa, Elev. 620ft, Walkscore 77
Contact:

Re: DIY Single axis USB controller

Post by jacob »

Progress was made!

I got 4 buttons hooked up to an Arduino Leonardo and working as a USB HID game controller on windows. So far so good.

Useful links:
https://www.youtube.com/watch?v=R6iJ2FMQFyw
https://docs.arduino.cc/software/ide-v2 (I installed IDE 2 on Win10)
https://github.com/MHeironimus/ArduinoJoystickLibrary (this seems to contain all the magic I need) (here using the included JoystickButton example)
https://www.amazon.com/dp/B008A36R2Y (the official $25 leonardo. Next time, I'll go with a $5 OEM "micro pro" which contains the same innards)
https://www.amazon.com/dp/B099MQV8ZW (useful components to get started---I've been looking for something like this for a long time :-P )

Next up ... the original problem.

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »

Cool! Keep going…,

jacob
Site Admin
Posts: 15962
Joined: Fri Jun 28, 2013 8:38 pm
Location: USA, Zone 5b, Koppen Dfa, Elev. 620ft, Walkscore 77
Contact:

Re: DIY Single axis USB controller

Post by jacob »

I found this instructable which introduces the above for a digital joystick (gamepad). That's not what I need, so ...

Also, I finally figured out what the Joysticktest.ino does and how to run it. Hint: It tests the full HID controller, not the joystick, so there's nothing to hook up unlike the button test.

I'm proceeding at a very conservative "nap on it"-pace here since I don't enjoy the smell of $25 going up in smoke. The trick for this test is to short the A0 pin to the GND pin to start the (auto)test. This mainly followed from already knowing C and reading through the program + having some prior electronics101 knowledge (voltage dividers, etc.). Otherwise, I think I would have been lost/stuck for a long time.

In any case, it looks like one arduino can easily handle the cockpit of an entire WWI crate. I was under the impression I needed separate electronics for each controller, but since I'm building my own controller, I can have one arduino handle the whole cockpit. I think I need to dial up the ambition level now.

User avatar
Sclass
Posts: 2801
Joined: Tue Jul 10, 2012 5:15 pm
Location: Orange County, CA

Re: DIY Single axis USB controller

Post by Sclass »

You sound like you know enough. The A0 input is able to take voltages from 0-5v (on an uno and likely a Leonardo). If you build your divider between 0 and 5v using a pot in rheostat mode there is no way you’ll smoke your new board. Build your entire circuit with 5v supplies and nothing will go wrong.

The C required for your application is just a few lines. You just do an analog read and then write the value or some scaled and thresholded version of it to your mouse variables. Then loop that routine forever.

I was going to say you’ve done the hardest part. You have the thing on the table running. Embedded people like to say getting an LED to blink is half of the problem. This is no small feat because it means you have a working board, interface, compiler, boot loader, clock source and more working when you just do that.

Have fun.

Post Reply