An application of systems theory (Arduino, DE-ACCM3D and Java Swing and AWT)

Imagine to lead the motion of a ball on the screen by controlling the inclination of an imaginary plane through an accelerometer.
Thanks to the Arduino microcontroller, the small DE-ACCM3D accelerometer and, finally, the Java Swing and Java AWT libraries, a program
that realizes this stuff is not so hard to be written. Let’s start from the beginning.

We have to connect the accelerometer to the Arduino microcontroller. Here you can find the DE-ACCM3D datasheet.

Now we make the arduino send interrupts to the computer every 60 ms. Each interrupts contains informations about the acceleration on the three axis.
The following script is the sketch I run on my arduino (be sure that the accelerometer is connected on the right pins):


#define Xax 0
#define Yax 1
#define Zax 2

int x;
int y;
int z;

void setup() {
Serial.begin(9600);
}

void loop() {
x = analogRead(Xax);
y = analogRead(Yax);
z = analogRead(Zax);
Serial.println("####");
Serial.println(x);
Serial.println(y);
Serial.println(z);
delay(60);
}

Note that Serial.println() prints data to the serial port. But how can we make arduino interface with software? There are plenty of wikis on this subject: interfacing with software.

Now that we manage to make the arduino happily communicate with the computer, we need to determine the right position of the ball on the screen. From systems theory point of view this is the most interesting part of this work. I explained it here:

Finally, I wrote the program. You can find the sources file here and RXTXcomm.jar here.
In order to compile and run these sources file you need to type the following commands (it works only on linux!):
javac -classpath .:RXTXcomm.jar Labyrinth.java
java -classpath .:RXTXcomm.jar Labyrinth

Enjoy this video!

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

2 Responses to “An application of systems theory (Arduino, DE-ACCM3D and Java Swing and AWT)”

  1. Emanuele Says:

    Congratulations!
    Is a very good and interesting project! :)

  2. ilraccoglitore Says:

    thank you, man!
    I’ll publish some other application about control theory as soon as possible. Keep in touch :-)

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image