Make a USB Device, Control It In Java
Asked Answered
S

6

15

I'm thinking about making a physical controller (device?) with knobs, buttons, and LEDs. I'd like to interact with it using Java (respond to the knobs, light up LEDs, etc). The reason I mention Java is two-fold: first, I know Java well1. Second, I've written the rest of the program I need to interface with in Java (though there are ways to talk to the Java program from another language).

I would like the device to connect via USB and be (computer-)platform independent.

I haven't the slightest idea of where to start, except to start reading the Arduino website. Is this my best/only option? Is there something better suited for communicating with Java?

Note: I know that Arduino has something to do with Java (not sure what), but it seems like code must be written in a subset of C.

How would I get moving on this topic?


1 - No laughter, please.

Serving answered 29/1, 2010 at 1:10 Comment(0)
D
7

The Arduino development environment is written in Java.

But the standard language you write a program for the Arduino platform is effectively C++.

The Arduino platform is based on an Atmel AVR chip. There is at least one Java VM for AVR chips. There are other languages available for the AVR such as Forth and BASIC (although I could only find commercial versions, so I'll if you want to find them, search for "AVR BASIC").

The Arduino uses a virtual COM port to communicate between the host computer and it. A virtual COM port emulates an old style serial line but is done with USB. You can use the Java communication API to then have a Java program running on the host computer communicate with your physical device.

Dominique answered 29/1, 2010 at 1:21 Comment(5)
@R Samuel Klatchko: I'm curious, is it platform independent, say, linux, what about drivers? I've heard a lot of good reviews about Arduino... :)Pastore
The IDE is platform independent but the virtual COM port driver is not. That said, I believe recent versions of the Linux kernel have the necessary driver built in.Dominique
+1 Fascinating stuff, especially the link to the NanoVM. Still digesting all of this, but it seems like the easiest thing, though it doesn't sound like it, is doing the Arduino part in the Arduino Language...?Serving
I've been using Arduino for over a year now -- great cross platform support with Windows and Linux. Pick up the book "Getting Started with Arduino" it helped tremendously when I was getting started. If you know Java, the Arduino language is going to be a cinch to pick up.Tapley
Thanks @Tapley I didn't see this comment until just now. I will check it out (soon). Best.Serving
B
4

For some encoders and buttons, you probably want to implement a USB HID device. If you're going to produce more than a couple of them, you'll want to do a custom board. Check out V-USB, an open-source library for making USB HID devices using Atmel microcontrollers. They have a bunch of examples of projects that use this library.

You could probably make this look like a HID joystick, using the encoders to produce X/Y axis information and having the buttons act like buttons. They you could use standard Java gaming APIs to read the joystick values.

Bailor answered 1/2, 2010 at 21:14 Comment(0)
S
1

Can you expand on your need for a custom device? It seems to me that designing hardware has a pretty high barrier to entry and that most applications I can think of would be better resolved by repurposing an existing piece of game controller hardware. If you really need new hardware, then i suggest you start by googling 'USB development kit' or 'USB development board' which will get you links like this, this and this.

As for working with USB hardware from Java, I've played around with the JUSB library a bit and it looks promising, but appears to be limited to Linux only because the Windows version of the native library half of the library hasn't been written. Alternatives can by found by googling 'HID java'.

Stagemanage answered 29/1, 2010 at 2:54 Comment(1)
Thanks Jherico. The device would have some of these "endless rotary encoders with LED rings: These controls have no end points, so offer full 360 ̊ of movement. These controls offer speed dependent variable resolution, so moving the encoder slowly gives finer resolution than moving the encoder quickly." It would also have some "LED-backed buttons." That's about it for the first run.... Hope that helps a bit. Now that I actually write it, it sounds daunting.Serving
P
0

Ok, computer-platform independant? What platforms are you targetting? That would depend on the driver and support for that said platform, what does the usb device do? Is it a mass storage device...You may have to look around and see if you can find a device driver that can talk to the device...

Hope this helps, Best regards, Tom.

Pastore answered 29/1, 2010 at 1:25 Comment(1)
Thanks for that, sorry if the question wasn't clear: the device is not built yet.Serving
A
0

I know for the serial port there were libraries that existed for interacting with it (rs232 library). Googling for java and USB returned several answers (the first was called jUSB). That would be the first type of thing I would be looking for.

Alvaalvan answered 29/1, 2010 at 1:27 Comment(1)
Right, but then what would you do? Get out your soldering iron and improvise? I have no idea how to build a USB device either, though I do have people who can solder stuff for me and follow schematics (though I personally know nothing about it).Serving
O
0

sample for java usb connection to freescale microcontroller:

http://javausbapi.blogspot.com/

Oppose answered 22/5, 2010 at 13:27 Comment(1)
having trouble understanding if this is relevant...?Serving

© 2022 - 2024 — McMap. All rights reserved.