Pages: [1]   Go Down
Author Topic: Arduino BT with SC16a Servo Controller  (Read 1572 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I have an arduino BT connected to a cytron sc16a servo controller and i am trying to use thi to drive a servo motor. The commands being sent to the arduino BT are gotten from a GUI on my pc. so basically, i click a button on my pc screen, a character is sent to the arduino where it is processed and then info is sent to the servo controller which in turn drives the motor. this is the plan.

however nothing seems to be happening (i.e the servo is not turning). It seems as though the arduino is receiving the commands from the pc but nothing is being transmitted to the servo controller. I suspect that this is because the RX and TX pins of the arduino are already taken up by the WT11 bluetooth chip on-board  and thus these cannot transmit to the controller.

so the big question is how do i add extra serial ports on the arduino BT so that I can communicate with the servo controller.

would really appreciate your help guys....

thanks!

Logged

Australia
Offline Offline
Full Member
***
Karma: 8
Posts: 161
You dont have to touch powerlines for them to kill you, even looking at them for too long will make them angry.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Reference/SoftwareSerial Have a look at this, it may be what you are looking for.
Logged

"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent di

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

hi, thanks for the link,

I have looked at the website and tried out the codes it talks about but still nothing happens (i.e) the servo does not turn. do you have any idea what the possible problems might be?
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest you start first by connecting the arduino directly to the servo controller and see if you can get the servo to move. Once you get this to work, add the bluetooth back. If the servo controller accepts ttl input, then you can directly connect the arduino tx to the servo controller rx (and connect common grounds).
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Australia
Offline Offline
Full Member
***
Karma: 8
Posts: 161
You dont have to touch powerlines for them to kill you, even looking at them for too long will make them angry.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and post your code that has had the best results
Logged

"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent di

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

@zoomKat,

thanks for the suggestion. but the arduino module i am using (ArduinoBT) has an in-built bluetooth component and so it is basically impossible to seperate the two physically(at least to the best of my knowledge).

@fliggygeek,
here are the best codes. pls note that the final aim of the code is to drive 8 servos...so you will see 8 variables set up to achieve this. enjoy

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
unsigned int FrontServo1 =0X41;                      //
unsigned int FrontServo2 =0X42;
unsigned int BackServo3 =0X43;
unsigned int BackServo4 =0X44;
unsigned int PanelServo5 =0X45;
unsigned int MainServo6 =0X46;
unsigned int MainServo7 =0X47;
unsigned int MainServo8 =0X48;

//these variables won't change:
const int Midpoint=732;                        //variable to determine angle midway of servo extremes
const int rate = 100;                          //Variable to determine the rate of turning of servo motors
const int panelPin = 2;
//these variables will change
int bufferIn =0;                        // Variable to store incoming byte
byte pinState = 0;
int position1 = Midpoint;
int position2 = Midpoint;
int position3 = Midpoint;
int position4 = Midpoint;
int position5 = Midpoint;
int position6 = Midpoint;
int position7 = Midpoint;
int position8 = Midpoint;

void setup()
{
  Serial.begin (9600);            //Set USART Baud Rate to 115200 
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  mySerial.begin(9600); 
  pinMode (panelPin, INPUT);        //set panel pin as input
  send_cmd(FrontServo1, position1,0);        /*Set the Default position of all servos in order to avoid floating*/
  send_cmd(FrontServo2, position2,0);
  send_cmd(BackServo3, position3,0);
  send_cmd(BackServo4, position4,0);
  send_cmd(PanelServo5, position5,0);
  send_cmd(MainServo6, position6,0);
  send_cmd(MainServo7, position7,0);
  send_cmd(MainServo8, position8,0);
}
void loop()
{
  if (Serial.available()) {      // Look for char in serial que and process if found 
     bufferIn= Serial.read();    //store char in variable
       switch (bufferIn)
     {
        case '1':                //if char is '1'
           main_Forward();      //move main body forward
           break;
          case '2':               //if char is '2'
           main_Reverse();      //move main body in reverse
           break;
           
        case '3':              //if char is '3'
           main_Right();       //rotate main body to the right
           break;
       case '4':              //if char is '4'
           main_Left();        //rotate main body to the left
           break;
       case '5':              //if char is '5'
           while (digitalRead(panelPin) == LOW) //check the state of the panel safety pin
           {
             main_PanelDown();       // safety pin not triggered, launch main panel
           }
           main_PanelUp();
           break;
       case 'w':             //if char is 'w'
           front_Up();        //move front flipper upwards
           break;
      case 's':              //if char is 's'
           front_Down();       //move front flipper downwards
           break;
      case 'd':            //if char is 'd'
           front_Right();    //move front flipper to the right
           break;
     case 'a':            //if char is 'a'
           front_Left();    //move front flipper to the left
           break;       
        case 'i':            //if char is 'i'
           back_Up();        //move back flipper upwards
           break;       
        case 'k':              //if char is 'k'
           back_Down();        //move back flipper downwards
           break;     
         case 'j':              //if char is 'j'
             back_Left();       //move back flipper to the left
             break;     
         case 'l':              //if char is 'l'
             back_Right();      //move back flipper to the right
             break;             
         case 'x':              //if char is 'x'
            Stop();
            break;             
         default:
             Serial.println("invalid command");
         }
  }
}

void front_Up()
{
  if (position1=1463)                      //check if servo is at max angle,
  {
     send_cmd(FrontServo1, position1,0);   // yes, Servo stays at the same position
  }
  else
  {
    position1=position1 + rate;            //No, increase angle according to rate
    send_cmd(FrontServo1, position1,0);
    delay(15);                           // waits 15ms for the servo to reach the position
  }
}
void front_Down()
{
  if (position1=0)                      //check if servo is at min angle,
  {
    send_cmd(FrontServo1, position1,0);        // yes, Servo stays at the same position
  }
  else
  {
    position1=position1 - rate;            //No, Decrease angle according to rate
    send_cmd(FrontServo1, position1,0);
    delay(15);                           // waits 15ms for the servo to reach the position
  }
}

void front_Right()
{
  if (position2=1463)                      //check if servo is at max angle,
  {
    send_cmd(FrontServo2, position2,0);        // yes, Servo stays at the same position
  }
  else
  {
    position2=position2 + rate;            //No, increase angle according to rate
     send_cmd(FrontServo2, position2,0);
    delay(15);                           // waits 15ms for the servo to reach the position
  }
}

void front_Left()
{
  if (position2=0)                      //check if servo is at min angle,
  {
    send_cmd(FrontServo2, position2,0);        // yes, Servo stays at the same position
  }
  else
  {
    position2=position2 - rate;            //No, Decrease angle according to rate
    send_cmd(FrontServo2, position2,0);
    delay(15);                           // waits 15ms for the servo to reach the position
  }
}
.
.
.
. //same procedure repeated for the rest of the servos
.
.
.
void send_cmd(unsigned int num, unsigned int data, unsigned int ramp)
//UART transmit 4 bytes: servo number, higher byte position,
//lower byte position and speed

{
     unsigned char higher_byte=0, lower_byte=0;

   
      
   higher_byte=(data>>6)&0x003f;
   lower_byte=data&0x003f;


         
         mySerial.print(num);                //First byte is the servo channel 0x41-0x60
         delay(2000);
         mySerial.print(higher_byte);        //second byte is the higher byte of position
                                                          //0b00xxxxxx
         delay(2000);
         mySerial.print(lower_byte);         //third byte is the lower byte of position 0b00xxxxxx
         delay(2000);
         mySerial.print(ramp);              //fourth byte is the speed value from 0-63
         delay(2000);
                   toggle(13);

}

void toggle(int pinNum) {
  // set the LED pin using the pinState variable:
  digitalWrite(pinNum, pinState);
  // if pinState = 0, set it to 1, and vice versa:
  pinState = !pinState;
}


Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Per the below you should be able to connect the arduino BT tx/rx pins to the tx/rx pins on the servo controller.

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins are connected to the corresponding pins of the Bluegiga WT11 module.

http://www.cytron.com.my/datasheet/ServoController/SC16A_User's_Manual.pdf
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

@zoomKat

this was the very first connection  i made. but nothing seemed to be transmitted. I figured the error was because, as you have mentioned, the arduino rx(0) and Tx(1) pins are taken up by its Bluegiga WT11 module and so cannot transmit serially to the sc16a on these pins. this is what drove me to look for an alternative pin for serial communication (i.e  softwareserial) as you can see in the codes...is this thinking wrong?
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using a multimeter you might check to see if the arduino tx/rx pins are in parallel with the tx/rx inputs of the WT11 module.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

@zoomKat,

dats a good point. From the arduinoBT datasheet found at  http://arduino.cc/en/uploads/Main/arduino_bt06.pdf it indicates that the rx and tx of the BT module is parallel to that of the the arduino pins.

Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the connections are in parallel, you should be able to connect the servo controller rx to the arduino rx (also connect common grounds) and the controller will see what is sent from the serial monitor to the arduino. This way you can directly send commands to the servo controller from the serial monitor for testing.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

@zoomKat

I have done that. but still no response from the cervo controller or the servo. the rx LED on the servo controller does not even blink to indicate that it is receiving anything
Logged

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

hello...is anybody out there??
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
hello...is anybody out there??

yes
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

hi, pardon the way i sound. I just really need to resolve this issue in d next few days. thanks for your help so far. really appreciate it . u have any ideas of what else i can try?
Logged

Pages: [1]   Go Up
Jump to: