[prog] Any Arduino-chix and/or Java coders out there?
Akkana Peck
akkana at shallowsky.com
Mon Dec 30 03:48:44 UTC 2013
Camilla Montonen writes:
> Hello everyone,
> I'm trying to hack the open source Arduino mouse glove (
> http://mouseglove.sourceforge.net/), but have so far run
> into problems.
>
> I need to write a driver for the mouse glove to communicate with
> my computer, but unfortunately many of the Java libraries required
> have very obscure documentations (too much for a newbie :( ).
>
> Has anyone written mouse drivers in Java?
I haven't ... and Java seems like a strange language to use for
that, though I know some Arduino people love it. But I often hit
the same problem you did: that the Java code doesn't "just work",
and I usually find that trying to get it to work turns into more
effort than just writing it myself.
Because personally I'd usually use Python for something like this,
I googled arduino python mouse linux OR x11 (after trying a few
other keyword combinations that didn't yield anything useful) and
found a project that's doing something similar, but with a Wii nunchuck:
http://news.anarchy46.net/2013/04/arduino-wii-nunchuck-on-linux.html
The key to moving the mouse seems to be this, done when the program
initializes:
d = Xlib.display.Display(None)
and then this when it's time to move the mouse:
d.warp_pointer(x, y, src_window = root)
(that's in the move_mouse() routine).
So if you read the serial stream coming over USB from the Arduino,
you could use Xlib.warp_pointer to move the mouse accordingly.
Reading the stream from the Arduino is easy: I have an example
here that just shows everything coming from the Arduino (and
lets you type things to send to it but you won't be needing that):
https://github.com/akkana/arduino/blob/master/scripts/ardmonitor
And if the mouse-glove code isn't as well documented as they say it
is, you could use ardmonitor (or just plain old screen) to watch
what's coming over the USB line.
Make sure you check what speed they're using on the serial line,
since you have to open the serial device at the right speed or
nothing will work.
I'm not sure if you're a newbie to programming in general, or just
to Java and Arduino. This all might sound a little daunting to a
beginner, but actually, I think if you fiddle around with that
Wii nunchuck code you'll probably be able to understand it and use it.
And the end result will be so much cooler than spending the same
amount of time trying to reverse-engineer a bunch of complicated
undocumented Java libraries ...
Of course, if your favorite language is Perl or Ruby or C, I'm sure
it's just as easy, just look for similar libraries. I'm pretty sure
there are examples out there for reading arduino output in perl and
ruby; I haven't looked for mouse-moving examples.
This sounds like a fun project -- good luck! And let us know how it
works out.
...Akkana
More information about the Programming
mailing list