Pages: [1]   Go Down
Author Topic: Controlling Arduino with Processing GUI  (Read 1697 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I am working on a project for school that involves making a spring powered launcher that has to fire a projectile a set distance by adjusting the angle and amount of tension in the spring.  I would like to make it so that I can enter a distance into a processing program on the computer, and have it automatically calculate the required angle and tension for the spring (using a pre-made equation).  I would like it to then send this data to the Arduino via USB and have it move the motors to the correct location. Finally, I would like to have a button (either real or virtual) that will fire the projectile by activating a solenoid. I already know how to interface stepper motors and solenoids to the Arduino, but I need some help with how to approach the computer side of the project. 

Any help would be greatly appreciated.

Thanks!
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Interesting project.  Every office should have one.

The way I would approach this problem is to get the Arduino side working and debugged before you start on the GUI.  

You're going to be using the usb serial port to control it from Processing, so why not design the data transfer format to be human-readable commands so you can control it from the Serial Monitor… then when it's working, processing can send those same commands from the GUI to the Arduino.

There are simpler approaches, but suppose you could send these commands to the Arduino via the Serial Monitor or a Processing program:
Code:
setangle(23)
settension(137)
fire()

There is plenty of information here on the forum how to parse serial input and call your C code to work the motor and solenoid.

Good luck with your project,


-br

Edit: grammatical correction.
« Last Edit: December 30, 2012, 06:58:19 pm by billroy » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help,
I understand what you are suggesting, and I think it will work quite well, but I am having trouble figuring out how to get the Arduino to read the commands from the serial port in the format that you suggested.

I know that I will have to read the data into some kind of variable, then determine what the data is and what needs to be done, but I am not sure what code to use to do this.  In the past, I have done very basic serial control where I used code like this:

Quote
 void loop() {
   
   // see if there's incoming serial data:
   if (Serial.available() > 0) {
     
     incomingByte = Serial.read(); // read the oldest byte in the serial buffer

//Preform the code to activate the stepper motor and the LEDs

    if (incomingByte == '0') {
    
      myStepper.step(14); // moves the stepper 14 steps forward
    
      delay(50); // wait 50ms
      
      myStepper.step(-14); // moves the stepper 14 steps backward



Also, what would be a simple way to convert an angle into a set number of steps?

Thanks again for all of the help.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 653
Posts: 50881
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I know that I will have to read the data into some kind of variable
Actually, an array. You'll need an index variable, too. Don't forget the NULL terminator.

strtok(), atoi(), and/or atof() would bear looking at, once you have a NULL terminated array of chars.

Quote
Also, what would be a simple way to convert an angle into a set number of steps?
There isn't. What does an angle of 47 degrees mean, in terms of steps, anyway? If you want the stepper to rotate 47 degrees, that's one thing. How to do that depends on the number of steps per rotation of your stepper, which is not defined in your snippet.
Logged

Pages: [1]   Go Up
Jump to: