Interfacing The arduino with a java program

We are a team of two kids going into high school. Our Goal is to control a electronic wheelchair with the arduino.

We would like to be able to program in java on a host macbook that is connected to the arduino.

We want to be able to read and write to the arduino pins.

What is the best way to do this? Does anyone have examples of something similar.

Thank You

Any application that can write to the serial port can communicate with the Arduino. The Arduino can be sent instructions like or <Write D11 148> which it could then parse and see that it needed to set digital pin 2 HIGH or analogWrite the value 148 to pin 11.

You could have similar commands to read analog pins () or digital pins ().

As long as you can get Java to connect to, write to, and read from the serial port, you should have no problems with this.

Keep in mind that the most challenging aspect of the project is not going to be making the PC talk to the Arduino or making the Arduino activate the pins. The most challenging part is going to be making the wheelchair controllable by the Arduino without endangering yourselves, the wheelchair user, or the Arduino.

Is there some particular reason to write the PC application using Java?

Do you have an example of the code i would upload to the arduino(i am not very good with c)

I chose to use java because it is the only language both my friend and i know.

i am not very good with c

The sooner you get started learning to program in C, the better.

Actually programming involves several steps. First is understanding what the program is supposed to do, what the user will enter, and what the program will output.

Next is developing some psuedo code that describes the steps to take to convert the input to the output.

Finally, you develop the actual code that does just that.

The first two steps do not require any understanding of C, C++, C#, Java, Fortran, Cobol, Assembler, or even Basic.

The final step is the easiest, and the only one that is language dependent. If you can accomplish the task in one language, you can probably accomplish the same task in another language even without a thorough understanding of that language. Except for Assembler, maybe.

However, as I mentioned earlier, the control of the Arduino is the easy part. The control of the wheelchair is the hard part. Controlling the wheelchair from the PC is a matter of making the PC send commands to the Arduino, making the Arduino read the commands, parse the commands, and execute the commands. This is easy.

Just create a list of commands that the PC should send to the serial port, and send that to me. I'll write the code to parse the serial data, and activate the appropriate pins on the Arduino, or return the appropriate data from the Arduino.

Then, you just install the Arduino in the wheelchair, and you'll be done, right?

So, you go first. What commands will the PC send to the Arduino?

Keep in mind that the most challenging aspect of the project is not going to be making the PC talk to the Arduino or making the Arduino activate the pins. The most challenging part is going to be making the wheelchair controllable by the Arduino without endangering yourselves, the wheelchair user, or the Arduino.

Something else to keep in mind:

When doing a project of this sort (ie, large robotic device - which is what this is), it is best to do the primary development off-platform; that is, don't even think about connecting the motors to the Arduino until you are completely certain about your control system, and kill-switch system.

Instead of motors, wire up LEDs to the output pins, in such a way that you know (based on the LEDs lit) what way the "motor" should be turning based on the commands sent to the Arduino by the PC.

You also need to set up some kind of "heart-beat" system between the Arduino and the PC - such that should the serial port connection become broken (that is, disconnected), the Arduino and/or the PC will take steps to shut the system down. You also will want a remote-controlled, as well as a physical (on-board) kill switch, such that activating either will disconnect power from the motors and/or system entirely. You don't want to have any way for the system to "run away" from you in testing, endangering bystanders. If this is a system where there is a user on-board (ie, a wheelchair command interface for a disabled individual), you will want such a kill-switch system in place, and available for their use as well if needed (and if possible for them to use it). You may want to govern the speed of the motors so that they only turn so fast, or add a braking system, or something similar.

Large scale robots (and a battery powered wheelchair device counts) are not something you want to leave anything to chance on; even when they move slow, they can have enough speed, mass, and power to cause some injury and/or damage to bystanders and property should they "get loose" or run-amok in some other manner. So think about this issue -first-, and design your system around preventing it from happening. If you are planning on using the device in any sort of contest or other competition, you are likely going to need such a system involved anyhow, so it is better (and easier and cheaper) to design it in first, than to try to shoehorn/band-aid it in later (just like security in IT and software development).

:)

PaulS The pc will send the following commands

We want to be able to read and write all the pins, using commands like

"write d2 high" or "write a2 147" or "read a3" or "read d6"

by the way we use a arduino Duemilanove

thank you so much for your help :D

We are a team of two kids going into high school. Our Goal is to control a electronic wheelchair with the arduino.

We would like to be able to program in java on a host macbook that is connected to the arduino.

We want to be able to read and write to the arduino pins.

What is the best way to do this? Does anyone have examples of something similar.

Thank You

Note: when you say "electronic" wheelchair, I assume you are talking about a "motorized" wheelchair.

I suggest you might start by using servos to control the wheel chair via its mechanical controls. When you get done, just remove them and then the wheelchair can go back to its intended use.

If you want wireless control instead of wired, then you need to research what is available for wireless communication.

If you know java programming, then it should be assumed you have mastered serial I/O operations using java.

Google should provide a lot of info concerning similar projects others have done.

As to robot safety, keep the wheelchair on blocks to keep the wheels off of the floor while testing. The motors in motorized wheelchairs are strong and can cause damage if one is not careful.

The motors in motorized wheelchairs are strong and can cause damage if one is not careful.

Which is why a mechanical control system with servos might not be the best method of control. Unless you really know what you are doing with designing and building a mechanical control system, you could easily get into a "locked" situation, leading to an out-of-control 100-200 pound wheelchair careening around a room.

As I noted before, when designing a control system for a robotic system of this size, safety and shutoff/kill procedures and mechnisms must be designed in as first priority, especially if this is to carry a human or be used in a contest in which bystanders are around. I am not saying you couldn't design a safe mechanical control of such a wheelchair, but by the time you made it safe, your time could have been spent on interfacing with the control/drive system electronically, with likely safer and more responsive results.

:)

Sorry to rush you PaulS but i was wondering if you have worked on the code? do you maybe have an start i can work on?

Thank You so, so much!!!!

I'm not feeling rushed. I'm not going to write a program for you. I've described what you need to do. There are examples provided with the Arduino IDE that can be modified to implement whatever protocol (set of commands) that you define.

There is a string library that is useful for collecting data from the serial port, and has the necessary functions to implement a parser.

There is a Messenger library class that has done all the work for you. It even comes with examples.

YOU need to learn something about programming the Arduino yourself, or you might as well put it back in it's box and return it.

You have not answered any of the concerns expressed about actually controlling the wheelchair. If you can't answer them, perhaps you should be looking around the pool, and noting that you are at the deep end.

I have made some code. This code should control a led attached to pin 8. But it dose not.

void setup()   {                
 Serial.begin(57600);
 pinMode(8, OUTPUT);
 digitalWrite(8,HIGH);
 delay(500);
 digitalWrite(8,LOW);
}

 int incomingByte = 0;

void loop()                     
{
   // send data only when you receive data:
      if (Serial.available() > 0) {
                int text = Serial.read();
                Serial.println(text);
                if (text == 111) {
                 
                 digitalWrite(8,HIGH);
                  
                }
                
                if (text = 102) {
                 
                 digitalWrite(8,LOW);
                  
                }
      }

}

I fixed the code and it works ;)

If your code now works, post it so others can see working code.

I will post as soon as it works again. Right after i sad it worked i ripped the whole thing apart to make it more advanced ::)

Some comments about the code you posted.

if (text == 111)

What does the user need to type into the Serial Monitor to get it to send a 111 to the Arduino? Will you remember what that letter is a month from now?

if(text == 'o')

This does exactly the same thing, with no need to consult an ascii table to figure out what 111 represents. A week, a month, a year from now, you'll still be able to see what to send to get a 'o' to the Arduino.

if (text = 102)

Here, you assigned the value of 102 to the variable type. Since assignments always succeed, and since the = operator returns the value assigned, this test is equivalent to if(102). Since 102 is not zero, the test is true, and the light will be turned off, regardless of what character was sent (even the 'o' to turn it on).

First thing to learn: = != ==

Even when you fix these error, you have:

if(text == 'o')
{
}
if(text == 'f')
{
}

What can you possibly send to the Arduino that would make both tests true? If you can not think of anything, you want to re-write this to:

if(text == 'o')
{
}
[glow]else[/glow] if(text == 'f')
{
}