Arduino + Java + Joystick

Interfacing your own hardware with a Java app couldn’t be easier than this example. [Pn] created this proof-of-concept using an Arduino, an analog joystick from a gaming controller, and a few lines of Java code. The Arduino reads an ADC value from the joystick’s x-axis and transmits it over the serial connection ten times a second. The Java program triggers on every serial event, parsing the data based on the @ symbol that the Arduino sends as a start and end condition.

We like this kind of example because there’s nothing extra involved. It lets you take the concept and run with it in any project imaginable. Be it a more complicated Joystick, or simple sensors that you’d like to interface with.

Comments

  1. nes says:

    Nicely written project. I beg to differ regarding the easiest way to do this. If you don’t already have a ready made Arduino then Byron is way simpler as it uses the OS’s built in HID driver for USB and will happily enumerate itself as a joystick or keyboard or whatever.

    http://1010.co.uk/org/byron.html

    I’ve used this a couple of times. It’s great and just works for up to 6 analog channels.

  2. Gdogg says:

    That byron thing looks pretty cool. Like a cheaper Teensy

  3. Gdogg says:

    That said, this arduino thing is a total hack. You don’t really learn anything (who didn’t know you could read an analog input and communicated serially, who didn’t know you could interpret a serial stream on a computer). What would be COOL is him hooking up the joystick, then implementing an HID interface, so the data that is passed (over usb, not usb to serial) is meaningful to more than just one application built to read that specified @@ ‘protocol’ and uses a standard, well defined interface. Through that you could build your own game pads, etc.

  4. Todd Grigsby says:

    This gave me a geek chubby. This is going to be my next project…

  5. nes says:

    @Gdogg: I rats’ nested the first one I did from old junk so it cost two parts of nothing:

    http://postimage.org/image/2cfmum7vo/

    The teensy does look a bit better supported though.

  6. Tomasito says:

    I’ve done something similar but more funcional.

    An arduino with a 2 axis joystick + 1 button, send the data via serial to the pc, and in the pc I use PPJoyCOM, so I can use it like a real joystick in any game.
    If anyone want the arduino code I send it, it’s very simple btw, once you figure out what PPJoyCOM expects to read from the serial port..

  7. Gdogg says:

    @nes omg haha that looks horrible, but I guess you got it working.

    I’m thinking of getting a teensy to mod an xbox controller, but I need the motivation to START the project. sigh.

  8. Moggie100 says:

    With the Uno series you could build a proper HID joystick using this method.

  9. epokh says:

    Well done Pn, but the way to go is defo the HID crafting method. It will be also cool to build a wireless HID host receiver. So that you can build a wireless network with a usb hid node host.
    Then you can attach everything you want.
    I have some jeenodes ready to go.
    I’m gonna do that, it’s awesome!

  10. Pn says:

    Epokh I’m waiting for your new article, so.
    However I know the connect a potetiometer to arduino is not cool, infact the interesting thing, for me, is the java code.

  11. epokh says:

    Yes I know, so have a look at this:

    it’s using processing to show the joystick position.

  12. MS3FGX says:

    The Byron board looks pretty cool, I’ll have to keep that one in mind.

  13. Whatnot says:

    Erm, right, take apart a $10 joypad, connect parts to a $20 arduino and have a dinky joypad.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 93,967 other followers