Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Serial Servo Control on: December 05, 2012, 10:13:16 pm
Found one... Processing.org was a treasure trove of ideas.... Thought I'd mention this in case anyone else read this thread with same problem. Wrote a terminal app from scratch using bare minimum requirements for serial link using processing ide... Resembles Arduino IDE so much I think they may be related? .. Mad easy to use
2  Using Arduino / Programming Questions / Re: Serial Servo Control on: December 05, 2012, 03:34:33 pm
Code:
#include <Servo.h>

Servo servoL;
Servo servoR;

int inByte;

void setup()                                                 
{
   Serial.begin(9600);                                   
     
   servoL.attach (5);                                     
   servoR.attach (6);                                     
}

void loop()                                           
{
  if(Serial.available() > 0)                         
  {
     inByte = Serial.read();                       
     control();                                       
  }
}

void control()                                       
{
   switch(inByte)                               
   {
    case 'a':                                       
       servoLeft();
       break;
----------------------Continued---------------------------

void servoLeft()
{
    servoR.write(99);
    servoL.write(120);
    return;
}

Here's my code the way you suggested btw, wasn't sure if you could see it the way i originally posted it or not, but this is my current set up...
3  Using Arduino / Programming Questions / Re: Serial Servo Control on: December 05, 2012, 03:32:49 pm
Thanks for the advice on posting code in the forum, this is my first time posting here, but I have a feeling it won't be my last.

Do you have any recommendations for terminal applications like that which work well with Arduino?
I'm thinking I can get your suggestion working pretty well with while loops, or maybe while loops nested in switch statements...
4  Using Arduino / Programming Questions / Serial Servo Control on: December 05, 2012, 12:51:47 pm
I've been working on a "robot" of sorts that is mobilized by two continuous rotation servos, which is controlled via my Arduino Uno R3.

Currently I drive the bot around by sending commands to the Arduino from the serial comm. terminal in the Arduino IDE, works fine, but is a bit annoying to control having to send one command at a time.

I understand Serial communication is asynchronous and can only do one bit at a time... But are there any tricks someone can point me towards where I can make it a bit more "real-time"?

i.e. -- I press the up-arrow key and while the key is being pressed the bot goes forward, as soon as I release the key the bot stops.

I do plan on making a stand alone controller down the road and I realize that'll make my life a lot easier, but in the interest of time, I have no other choice than to rely on serial comm. to control my bot (school project with a  due date).

----------------------------

Currently I have my two servos driven by a power circuit I built, which the Arduino uses as an interface to the servos (power board feeds servos 6V, Arduino operates servos via signal line to servos).
My code is currently just a switch statement which decides which action to take depending on key pressed, following is a portion of my code:

----------------------------Start code------------------------------------------------
#include <Servo.h>

Servo servoL;
Servo servoR;

int inByte;

void setup()                                                
{
   Serial.begin(9600);                                  
      
   servoL.attach (5);                                    
   servoR.attach (6);                                    
}

void loop()                                          
{
  if(Serial.available() > 0)                        
  {
     inByte = Serial.read();                      
     control();                                      
  }
}

void control()                                      
{
   switch(inByte)                              
   {
    case 'a':                                        
       servoLeft();
       break;
----------------------Continued---------------------------

void servoLeft()
{
    servoR.write(99);
    servoL.write(120);
    return;
}

-----------------------------------End code--------------------------------

Obviously I only included the parts of interest, but is there anyway to make the servo respond upon a closed key? I tried looking up how to stream data to Arduino but could not figure out how to make it work for my purposes, obviously I'm still learning here...

Thanks for any help, it is greatly appreciated!

-jay

P.S. -
Sorry if this is in the wrong section, wasn't sure if it should go in the motor section or this one, but I figured it was mainly a programming issue...
Pages: [1]