Go Down

Topic: Program a GUI in C/C++ for arduino and mouse cursor control (Read 15264 times) previous topic - next topic

Shploop

Jul 20, 2012, 06:39 pm Last Edit: Jul 21, 2012, 06:42 am by Shploop Reason: 1
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++ - http://www.wikihow.com/Write-Arduino-Software-in-C
*Eclipse/Glade - Python -http://fabian-affolter.ch/blog/index.php/arduino-controlled-by-a-gtk
*"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.

PaulS

Quote
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.

karlok

#2
Jul 23, 2012, 05:22 pm Last Edit: Jul 23, 2012, 05:25 pm by karlok Reason: 1
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
using Arduino Uno Rev 3

David K

#3
Jul 24, 2012, 12:52 pm Last Edit: Jul 24, 2012, 12:53 pm by fazalnasir Reason: 1
hi all..
shp loop and karlok i need your help regarding this issues for my project.

your help will be highly appreciated thanks.

PaulS

Quote
i need your help regarding this issues for my project.

What issues?

David K

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.



karlok

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.

Quote
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?



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



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 ...
using Arduino Uno Rev 3

PaulS

Quote
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.

Quote
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?

Quote
please give me the solution in each case

Why? Neither is appropriate.

Quote
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.

David K

#8
Jul 27, 2012, 11:28 pm Last Edit: Jul 27, 2012, 11:35 pm by fazalnasir Reason: 1
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)

3) 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.

2) 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
1) loading bullet from magzin
2) cahnging magzine etc
that is what i suppose, mr. paulS and requested for help.


thanks

karlok

Hello.

Quote
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.
using Arduino Uno Rev 3

karlok

Some example code (untested)
Quote

/*
 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
 }
}




using Arduino Uno Rev 3

PaulS

Quote
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.

Quote
2) 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
1) loading bullet from magzin
2) 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.

David K

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

karlok

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.
using Arduino Uno Rev 3

David K

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

Go Up