Jump to content
43oh

msp430g2553:everything compiled fine, but the servo wont respond to the exe


Recommended Posts

ive compiled and uploaded my code (below) and when plug my msp430g2553 in it goes to the programmed angle it should when plugged in, but when i run the exe that is supposed to change its  angle it doesnt do anything. the exe is programmed to connect to com4, and the msp430 application uart is set to com4. i know the exe can detect it because it wont run unless it can, it just isnt responding. im am using energia 0101E0010 to compile and upload. any help would be appreciated.

 here is the code:

 

 

#include <Servo.h>

Servo myServo;

const int servoPin = 9; // the pin the servo is connected to

int val = 0;    // a value accumulated from data on the serial port
int angle = 90; // the current angle of the servo



void setup()
{
  Serial.begin(9600);
  myServo.attach(servoPin);
  myServo.write(angle);  // center the servo
}


void loop()
{
  if ( Serial.available())
  {
    char ch = Serial.read();

    if(ch >= '0' && ch <= '9')        // is ch a number?
   val = val * 10 + ch - '0';        // yes, accumulate the value
    else if(ch == '-') // is this the minus sign?
    {
   angle = angle - val;
   if(angle < 0)
      angle = 0;
   myServo.write(angle);      // write the new angle
   val = 0;
    }
    else if(ch == '+') // is this the plus sign?
    {
   angle = angle + val;
   if(angle > 180)
      angle = 180;
   myServo.write(angle);      // write the new angle
   val = 0;
    }
  }
}

Link to post
Share on other sites

According to the logic in this Sketch you would type first type the value and then either + or - depending on which direction you want the servo to move.

So sending 9+ in the Serial terminal will move the Servo +9 degrees and sending 9- will move the Servo +9 degrees.

 

Below is a slightly modified Sketch that prints some information to make sure that you are actually receiving data over serial.

#include <Servo.h>

Servo myServo;

const int servoPin = 9; // the pin the servo is connected to

int val = 0;    // a value accumulated from data on the serial port
int angle = 90; // the current angle of the servo



void setup()
{
  Serial.begin(9600);
  myServo.attach(servoPin);
  myServo.write(angle);  // center the servo
}


void loop()
{
  if( Serial.available()) {
    char ch = Serial.read();
      
    if(ch >= '0' && ch <= '9') {   // is ch a number?
      val = val * 10 + ch - '0';  // yes, accumulate the value
      Serial.print("val: ");
      Serial.println(val);
    } else if(ch == '-') {          // is this the minus sign?
      angle = angle - val;

      if(angle < 0)
        angle = 0;

      Serial.print("moving servo to: ");
      Serial.println(angle);
   
      myServo.write(angle);      // write the new angle
      val = 0;
    } else if(ch == '+') {         // is this the plus sign?
      angle = angle + val;
      
      if(angle > 180)
        angle = 180;

      Serial.print("moving servo to: ");
      Serial.println(angle);
  
      myServo.write(angle);        // write the new angle
      val = 0;
    }
  }
}
Link to post
Share on other sites

i uploaded the modified sketch and it didnt respond at all in parallax, the computer can detect the device, as in device manager you can see in the COM section "MSP430 Application UART" as a device, and parallax detects it as well, im not quite sure why it isnt communicating.

 

edit: i should also add that i am using the msp-exp430g2 rev1.4, and i have crossed the txd and rxd pins on J3. i should also add that me servo is a standard servo from radio shack, and although it says the voltage is 4.8 to 6v, i tried a 5v wall plug and the servo would turn clockwise until it couldnt any more every time it was plugged in, and is now powered by the gnd and vcc pins on J6, and is functioning properly(as ive said before), as it turns to the programmed default angle when plugged in, as it should, the servo just doesnt respond when you try to give it a command. i feel like it is an issue with some setting or program on my computer interfering or just not set properlly.

Link to post
Share on other sites

I use this program to test the servos I buy on ebay, just open the serial console and send single characters (space to go all the way on one side, up to z to go all the way on the other side). Set the line ending to "no line ending".

 

Change MIN MAX to define the min/max angle of the servo.

#include <Servo.h> 
#define MIN 15
#define MAX 165

Servo myservo;  // create servo object to control a servo 
 
int pos = 0;    // variable to store the servo position 

int position (int value)
{
  if (value>100)
    value=100;
  if (value<0)
    value=0;
  return map(value, 0, 100, MIN, MAX);
}

void setup() 
{ 
  myservo.attach(2);  // attaches the servo on pin 2 to the servo object 
  Serial.begin(9600);
  pos = 80;
  myservo.write(pos);
} 
 
 
void loop() 
{ 
  delay(15);
  if (Serial.available()) {
    int data = Serial.read();
    data -= ' ';
    pos = position(data);
    Serial.println(pos);
  }
  myservo.write(pos);
} 
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...