Can a USB joystick directly control pwm voltage?

I just want to know the possibilities here before buying a beaglebone black and starting a project. Im completely new here so perhaps there would be a better micro-controller out there. I just want to be able to use a generic usb joystick (or 2 rather simultaneously) to get user inputs that in turn control pwm pins to vary the output voltage. From there i know the voltage can be amplified to get into my 24v needed range to proportionally control a hydraulic function. The key here is that i want to be able to make a system that if components get damaged they can be swapped out and i don’t have to fabricate a new analog multi-axis joystick each time. I would need the possibility of 6 pwm’s being controlled at the same time via 2 joysticks but i will do my research to get to there. I’m just wanting to know what the possibilities are. Thanks

Sounds like a cool project, and looks doable. In Linux joysticks show
up as input devices, typically in /dev/input/js0
That file appears automagically when you plug in the USB joystick, and
it contains the binary event stream from the joystick.
There's a input device test program jstest in the linuxconsoletools
package, which decodes that binary traffic, decoding that stream.

A typical game pad has two joysticks and a dozen or so buttons (mine
has 4 front buttons, colored ABCD cross on the right, 4-way hat on the
left, 3 buttons in the middle and two center buttins in the joysticks.
Since each joystick provides X and Y analog position, each gamepad can
drive four PWM outputs, so you need two gamepads---I think that's what
ou mean by 'two joysticks'/

Yes, it is possible. It is also possible with any number of the other SBCs
on the market. However in most cases, the beaglebone has the distinct
advantage of having multiple PWMs on board / die. There are more than
enough for you to have 4 PWMs without having to buy additional hardware. Of
course, all things external to the beaglebone is "on you".

Hi, Interesting task you have ahead. while it can be done with the BeagleBone Black their could be issues with accurate PWM control
as the OS is not real time. If your pwm is allowed to skip a beat from time to time or is is slow enough that it is not a problem for you . . .
Others please chime in if I am off track on this. You also mention a “swapped out” Plug and Pray situation. For this you might
consider a less expensive solution. There are all kinds that would not require a steep learning curve of linux and the BB’s to use.
Consider st’s stm32fxxx series development boards or a robotics solution already developed for almost exactly what you are attempting.
or a higher end arduino Mega or Due. That being said, Take a look at the new Beaglebone Blue by the same good folks. .
All kinds of possibilities. I might get thrashed with a wet noodle for promoting others hardware but, I say, wear the shoe that fits.
I use many embedded boards from BasicX, rabbit 2k and 3k, TI Launchpad, STM32fxxx and beaglebones as well as others. I use the one that
fits the need.

On Sat, 18 Mar 2017 14:00:02 -0700 (PDT), djlewis
<> declaimed the following:

or a higher end arduino Mega or Due. That being said, Take a look at the

  FYI: the Due was discontinued some years back; the current ARM based
Arduino is the Zero, as I recall (ARM M0 vs the Due M3).

  The Mega2560 supposedly has up to 15 PWM outs, but doesn't have USB
host mode, so probably not usable for the joysticks; would need plain
analog joysticks via the ADC inputs.

I use many embedded boards from BasicX, rabbit 2k and 3k, TI Launchpad,

TIVA TM4C123 has a micro A/B USB (which I believe means it can be used as
either host or client), the pinout seems to support 5 PWMs. {80MHz M4F
[floating point], 256kB flash, 32kB RAM, and too many timers for its own

TIVA TM4C1294 has the micro A/B and Ethernet; the pinout appears to list 10
PWMs {120MHz M4F, 1MB flash, 256kB RAM}

  And one sure can't complain about pricing -- ~$13 and ~$20 respectively
(and ~$25 for the 129E with encryption hardware).

  Code Composer Studio is now "free" -- and TI-RTOS is relatively easy to
use on them (granted, I've only done the RTOS lesson book -- how many ways
can one blink an LED), or Energia (Arduino IDE fork).

  For a task that basically consists of translating joystick inputs into
PWM outputs, it feels like a job for a microcontroller board more than an
SBC with OS/display drivers, and all that overhead.

This can all be done from userspace. Seriously, how do you games that use joysticks as in input work ? All those other board mentioned are not worth the time investment, specifically for this single task. Also, I own several TI LM4F dev boards as well as the TM4C1294. The TM4C1294 has issues, but the original Stellaris LM4F boards are pretty solid.

Quite honestly, if I had to use a micro to do this job right now. I’d probably use an MSP430. Just because they’re proven, for 10’s of years, and have open source toolchain support. Meaning GCC. However, this would probably be easier for a beginner to use a beaglebone.

And yes, technically the MSP430’s at least the ones I’d use do not have PWM. But they have something better. Two hardware timers, that can be configured in a way suitable for PWM duties.

You said directly, so I thought I might add this.

You can take a PIC16Fx with integrated ADC’s and set up your joystick’s pots in voltage divider mode. To explain, you hook up your VCC to one end of your pot and then take the voltage as sunk through another fixed resistor to ground. Ask me if I’m still not explaining it right or just google voltage divider.

Then assembly code your PIC such that the raw ADC value is used in a timed loop (use a 20 Mhz XTAL and just count the instructions, on a PIC each instruction runs per cycle…nice that way) that drives a GPIO pin out giving you your PWM. This will easily allow a pot (ie. a joystick which is 2 pots) to DIRECTLY control something like a hobby servo. For a hobby servo you need to get the PWM running nicely at about a few hundred or khz and to move it you just adjust the ratio of the on/off on its signal line (there are a lot of tutorials out there on the specifics).

Seriously you can have like a rotary pot that get’s the servo to mimic the rotation on the pot this way.

Right, but I don't even know where to get the old-style analog
joystick that could be wired this way---everything that's easily
available is USB and requires a host mode. For better or for worse,
full blown Linux makes it the easiest to use them, because the USB
stack is already up and running, automagically producing the joystick
data stream. Without it, i.e. when using a small microcontroller with
USB host mode, the software for this project would be dominated by
the USB handling code.

I got several analog joysticks at a local thrift store. Or there is always EBAY :slight_smile:

Or "Sparkfun" enter 'joystick' in the search box