Program a GUI in C/C++ for arduino and mouse cursor control

Hello, I know this topic must have been covered many times but I haven't found a solution that suits my needs:
*To program in C/C++ and a maximum of one more programming language(possibly python).
*To use as less as possible tools (IDE/SDK/compilers...).
*To send and receive data from an Arduino(I/O ports) to the PC over USB communication.
*To use a cross-platform solution(bonus if it can be transfered to Android).
*I want to keep things as simple as possible(although I know this won't be simple :P)
*I want to control the mouse cursor with using the data the Arduino sends to the PC.

so far I found these possibilities:
*Qt - C/C++ - http://www.instructables.com/id/Control-your-arduino-from-your-PC-with-the-Qt-Gui/
*Eclipse+arduino plugin - C/C++ - How to Write Arduino Software in C: 6 Steps (with Pictures)
*Eclipse/Glade - Python -Arduino controlled by a GTK interface | bits and pieces
*"robot" Java class to control the mouse cursor - http://www.javalobby.org/java/forums/t84094.html

I would love to hear if you have experience in this area and how you accomplished this task.

I would love to hear if you have experience in this area and how you accomplished this task.

I used C#. It is trivially easy to define user interfaces and to read from/write to the serial port. The only remotely challenging part is that the user interface runs one thread and serial data processing is done in another.

But, a little understanding of threads and how to communicate between threads solves that issue (which will be present in C++, too). C# threading is easy. C++ threading is not as easy.

Hello,

for those issues, I use Lazarus. Lazarus is the IDE, FreePascal its language which is like Delphi.
There is a library called Synapse and you need the synaser unit and its TBlockSerial.
http://synapse.ararat.cz/doc/help/synaser.TBlockSerial.html

Then, if you are able to program with Delphi like languages, you can use Mouse.CursorPos.X and Mouse.CursorPos.Y ...
If you need help, I think I can help you.

Additionally, to be mentioned, that I already controlled my DC motor (connected to my Arduino) via this method. I also wrote a GUI (graphical user interface) for it !

Good luck !

Greetings

hi all..
shp loop and karlok i need your help regarding this issues for my project.

your help will be highly appreciated thanks.

i need your help regarding this issues for my project.

What issues?

i have to control two DC motors each for X & Y direction motion.
The control will be through Serial comm-- between Arduino and PC through rs232 port by following methods:

a. From mouse courser motion like that in Games or
b. From keyboard arrow keys

the motors used for motion of paint Gun base. So, issue is how to control both the motors at a time i-e X and Y motion and

Secondly i want to create GUI for different action to perform:
e.g

  1. Reloading (GUI should have Reload button)
  2. magazine changing (GUI should have magazine change button) etc..

please give me the solution in each case ( mouse control and keyboard control) and also want to know which programming software can i use to create GUI that can communicate with Arduino.

thanks.

I think you already succeeded in controlling the motors from your Arduino board?
If you did that, the rest will be easy. If not, I think I cannot help you.
Can you show the source code for it? Zhis might help.

i have to control two DC motors each for X & Y direction motion.

You mean both can move in x and y direction? Or do you mean one motor for x direction, the other one for y?

fazalnasir:
and also want to know which programming software can i use to create GUI that can communicate with Arduino.

karlok:
for those issues, I use Lazarus. Lazarus is the IDE, FreePascal its language which is like Delphi.
There is a library called Synapse and you need the synaser unit and its TBlockSerial.
synaser: Class TBlockSerial

Then, if you are able to program with Delphi like languages, you can use Mouse.CursorPos.X and Mouse.CursorPos.Y ...

The control will be through Serial comm-- between Arduino and PC through rs232 port by following methods:

a. From mouse courser motion like that in Games or
b. From keyboard arrow keys

Neither is appropriate. The Arduino understands bytes, like letters. Send 'f' to move along the x axis in the positive direction. Send 'b' to move along the x axis in the negative direction. Send 'u' to move along the y axis in the positive direction. Send 'd' to move along the y axis in the negative direction.

Secondly i want to create GUI for different action to perform:
e.g

  1. Reloading (GUI should have Reload button)
  2. magazine changing (GUI should have magazine change button) etc..

Go right ahead.

How, exactly, is the GUI supposed to reload the weapon? How, exactly, is the GUI supposed to change the magazine? How, exactly, does changing the magazine differ from reloading?

please give me the solution in each case

Why? Neither is appropriate.

and also want to know which programming software can i use to create GUI that can communicate with Arduino.

Any one that you are familiar with that can write to the serial port.

Answers to karlok:

  1. yes i know well how to control motors

  2. yes one motor for x direction, the other one for y.

Let say the control is from keyboard:
control means, if i press right arrow key from keyboard the motors should rotate in one direction and vice virsa...
the responce of motor should like this:
by pressing arrow key once... the motor should responce (jerk)
by holding arrow key .... the motor should keep rotaion unless the key is release
my Question is (is this control is possible through Serial communication..? if yes, how i can control by CODE or somthig else)

  1. i think it will take so much time to understand Lazarus. So, if you have any such code or stuff made by you. Can you mail me?
    in this way i will make focus on my requirements.

thanks

Answer to paulS:

  1. i know Arduino understands byte, i want to explian this problem like

by pressing arrow key once... the motor should responce (jerk)
by holding arrow key .... the motor should keep rotaion unless the key is release.
if we send continously 'F' Serially to Arduino(by holding F key from keyboard) and then reading that byte(containing 'F')
and then make condition accordingly in code for rotating motors.

  1. GUI will have Buttons each will send info (byte) to Arduino serially and check that byte for respective actions that will
    be perform by Arduino by sending signal to actuators( Servos, steppers etc) to perform
  2. loading bullet from magzin
  3. cahnging magzine etc
    that is what i suppose, mr. paulS and requested for help.

thanks

Hello.

control means, if i press right arrow key from keyboard the motors should rotate in one direction and vice virsa [...]
by holding arrow key the motor should keep rotaion unless the key is release

Hint:
First) define a time how long the motor should move when pressed a key once (e.g. 1sec).
Then the code is like the following (pseude code):
rightarrowkey_onkeydown:
if (Gettickcount-a) > 1000 {
send_command();
a=gettickcount;
}
Otherwise the command would be always sent if the rightarrowkey is pressed, that would result in a buffer overflow, I guess. So avoid it. With this code you also include your wish that the signal is sent once when you press short on rightarrowkey .
a is a Dword variable, you could also use integer for it, both are working.

second) you have to write the Arduino sketch, As far as I understood, you already have one working. Then it will be simple.
Just use Serial.begin(9600); at the beginning or some arbitrary other baud rate for initialization. Then with Serial.read(); you read the data sent to your Arduino via serial communication (datatype should be byte because it's 256bit and thats a char, and chars are sent via serial comm.).


third) finish your computer code that controls your arduino "robot motor". I will post an example later...


IMPORTANT question: What programming language are you familiar with? You need one to conrol your Arduino.

Some example code (untested)

/*
KARLOK, 28/7/2012
*/

void setup()
{
Serial.begin(9600);
Serial.println("\n[Arduino-Motor] started with 9600 baud ...");
}

void loop() {
byte rx_data;

if (Serial.available()) {

// read the most recent byte (which will be from 0 to 255):
rx_data = Serial.read();

Serial.print("Received command: ");
Serial.println(rx_data, DEC);

switch(rx_data){ // intentionally omitted 0 because it should be the "set idle mode" command, see below
case 1: // move motor left
case 2: // move motor right
case 3: // move blablabla
case 4: // move whatever
case 5: // arbitrary commands...
}

// Clean up last received command.
// Otherwise you would have a non-stop run of your command after sent once!
rx_data = 0; // 0 (zero) is the "set idle mode" command
}
}

by pressing arrow key once... the motor should responce (jerk)
by holding arrow key .... the motor should keep rotaion unless the key is release.

There is no difference between these two actions. Send a value when the key is pressed. Send another value when the key is released. In the two cases, the only difference is the time between when the two values are sent. The easiest thing to do is send 'F' on press and 'f' on release, for one key.

  1. GUI will have Buttons each will send info (byte) to Arduino serially and check that byte for respective actions that will
    be perform by Arduino by sending signal to actuators( Servos, steppers etc) to perform
  2. loading bullet from magzin
  3. cahnging magzine etc

So, what is the problem? The sending and receiving of serial data is the same, The action to be performed is different. Although, how a solenoid can load a bullet or change a magazine escapes me. Not that it matters, since that is up to you to arrange for the hardware to manage.

i use C language for controlling Arduino.

thanks karlok

the hardware is another problem i will do that, but my question is " what are the guidelines (program in which i create GUI easily, any Links)
that would help me to create GUI for above requirements that i explained, easily.
karlok told me about Lazarus but i have know idea and will take so much time for understanding Lazarus. i have idea of C/C++

thanks paulS

I don't know much about C++ expect of that I use for Arduino language, however I think there can be created GUI applications, too. Have you never created a GUI with C++? You better ask in some C++ forums because this is not Arduino concerning directly even if there might be many members who know C++ programming, if your question is just how to make a GUI with C++ then here is not the right place, I guess.

no never use C++ for creating GUI, i am going to do this. i am trying to search but if you have any best links of forums regarding this problem..?

thanks for your help, karlok

sorry i cannot help you with that
there is much information on the internet about it

Good Luck!

my question is how to create a GUI that will work with Arduino not how to make a GUI I need only directions not a whole guide. for example I found I can make a GUI for Arduino with Qt(by nokia) I need a GUI that will interact with an Arduino, just the "method" all the coding and headache i'll handle.

I need a GUI that will interact with an Arduino, just the "method" all the coding and headache i'll handle.

The only way for the GUI to communicate with the Arduino is via the serial port. Some languages make that easy. Some do not.

what about threading? when I have a GUI let's say in C++ and a user is interacting with it while it receives and processes data from the Arduino do I need some kind of threading?

I don't use threads in my applications that communicate with my Arduino. However, it would be an optimization and an option to do so, my programs work very well and I can rely on them without using threads.