Servo Controller – 18 channel control using software
A servo controller is a dedicated board that helps the user to control servos based on the commands sent to it from an external device such as a computer or microcontroller. Using a dedicated servo controller frees up memory on a microcontroller which would be used to constantly update the servo’s positions.
Enables the user to control upto 18 servos with serial commands issued from PC or another Arduino. You can also set various parameters like minimum, maximum, reset angles, speed and save these parameters permanently. You can also enable / disable individual servo as well as set the position.
The servo controller is built around the popular chip ATMega328P running at 16MHz clock controls the servos based on serial commands received. The servos are connected to digital pins 2 to 19 in order [as labelled on the board]. Reset switch is provided to reset the controller.
Powering the board
The board can be powered through on board micro USB or screw terminal (K4) or through berg strip connector (K2). If we use external power for the board put the J3 jumper to VCC.
The servo motors can be powered directly through external dc source connected in screw terminal (K4) or by connecting battery to berg strip(K2). Make sure that the voltage used should be compulsorily in the recommended range of servo motor you are using.
The rest of the board gets powered from external source / USB based on jumper (J1) selection. Once the board is powered, the power indicator LED lights up.
If J1 selects external source as power source, then keep J3 open if the source voltage is >5V. Shorting the jumper shorts the input and output terminals of regulator.
Plugging the Servo
For most RC servos, a 500us long pulse (0.5ms) at 5V would rotate the servo to 0 degrees, a 1500us (1.5ms) long pulse would rotate the servo to 90 degree and a 2500us (2.5ms) pulse corresponds to 180 degrees. This pulse needs to be repeated every ~20ms. These pulses are given by the servo controller to signal pin of servo which in turn moves the servo to corresponding position.
Labelled multi- colour berg strip connectors enable you to plugin the servos with ease. The 18 connectors are laid out as 2 different sections with one section having 10 strips [D2-D11] and the other having 8 strips [D12, D13, A0-A5]. Servo1 (as per software) is connected to D2 and the servos are numbered in anti-clockwise direction to end up with servo18 connected to A5 (D19)
> The White strips are the signal pins
>The Red strips are the Vcc pins
>The Black strips are the Gnd pins
Testing the servo controller board using Servo controller software
- The board can communicate with PC via micro USB cable plugged into the micro USB port and the Xbee/USB selector DPDT slide switch pushed to USB side. In this case the PC should automatically detect the servo controller and install the appropriate drivers to let the board appear as a COM port. If your computer does not detect the board, you should manually install the CP2102 chip VCP drivers (based on your operating system)
- The controller has Xbee port with on-board 3.3V regulator and level converter that enables you to plug in XBee / Bluebee directly without any additional circuitry. The orientation of Xbee has been marked for ease of use. The Xbee/USB selector DPDT slide switch pushed to XBEE side. The paired Xbee can be interfaced to PC using an XBee Explorer Dongle
- You can also use a TTL – USB / TTL – RS 232 converter to communicate with the MCU directly via 3-pin RMC connector K25. The port has 3 pins namely TXD, RXD, GND and communicates in 5V level [Programming not possible].
Note : You should open the software only after connecting the communicating device(micro USB cable/XBee / Bluebee) to the PC.
- Open the servo controller software and select the com port to which micro USB cable/XBee / Bluebee connected and press connect button.
- Different Functions of servo controller software.
- RST button: -For resetting each servo.
- Factory Reset: -It will reset the software to its initial condition .
- Reset All:- To reset all servos to its initial position.
- ADC6 and ADC7 button:-For displaying ADC values in the dialogue box.
- Set Delay(ms) button: -To set delay for servo movement.
- Add Move:-We can add the servo movement by sliding the bar and press reset button.
- Remove button:-To remove the selected sequence of servo.
- Clear All:-To Clear all added Sequence.
- Copy Parameters:-To copy the added sequence.
- Run sequence:-To run the added sequence.
- Stop button:-To stop the running sequence.
- Set as Minimum/Maximum:-set the selected servo angles to its maximum and minimum position.
- Set reset value:-To set the initial value of servo.
- Upload Sequences:-To upload the saved sequence.
- We can control the speed of each servo in the settings by selecting the servo and its speed.
- Select the needed servo by marking tick in the box.
- Connect the servos and mark tick in the box for needed servos.Move the slide bar then we get the servo movement.
- We can add a sequence of movement by dragging the slide bar to a particular angle and press Add Move.While pressing the Run Sequence button the servo will move.
- To stop the running sequence press Stop button.
- To clear the sequence press Clear All button.
- To remove a particular sequence, select a sequence and press Remove button
- To set Maximum and Minimum angle.
- Select the servo which you want to set the angle from SETTINGS.
- Move the slide bar to your desired angle and press Set As Minimum button to set minimum angle.
Arduino Code for Communicating with Servo Controller Software
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
#include<Servo.h> #include <EEPROM.h> /****************************************************************************************************************************** #Global Variables *******************************************************************************************************************************/ int Value = 0, Angle = 0, /*Command = 'A',*/ i, Eeprom_Index=0; int Seq[20], Seq_Index=0, Loop_Count=0, Enabled_Servos=0; static boolean Set_Servo_number=0, Servo_Enable_Disable=0, Servo_Reset_Angle=0, Servo_Reset=0, Sequence=0, Sequence_Finish=0; static boolean Get_Servo_Position=0, Set_Servo_Direction=0, Set_Servo_Speed=0, Servo_Default=0, Command_Finish=0, Save=0; char Command='A'; /****************************************************************************************************************************** #Array of servo objects *******************************************************************************************************************************/ Servo servo[19]; /****************************************************************************************************************************** #Structure to store parameters *******************************************************************************************************************************/ struct Servo_Controller { int Reset_Angle; int Current_Angle; int Prev_Angle; int Speed; } Servo_No[19]; /* Array of 18 objects store the parameters of 18 servos */ /****************************************************************************************************************************** #Setup *******************************************************************************************************************************/ void setup() { Serial.begin(9600); for(i=1; i<19; i++) { if(EEPROM.read(Eeprom_Index)==255) { Servo_No[i].Reset_Angle = 90; Servo_No[i].Current_Angle = 90; Servo_No[i].Prev_Angle = 90; } else { Servo_No[i].Reset_Angle = EEPROM.read(Eeprom_Index); Servo_No[i].Current_Angle = Servo_No[i].Reset_Angle; Servo_No[i].Prev_Angle = Servo_No[i].Reset_Angle; } if(EEPROM.read(Eeprom_Index+1)==255) { Servo_No[i].Speed = 50; } else Servo_No[i].Speed = EEPROM.read(Eeprom_Index+1); Serial.print("Servo");Serial.print(i); Serial.print(" >Rst:");Serial.print(EEPROM.read(Eeprom_Index)); Serial.print(" >Speed:");Serial.println(EEPROM.read(Eeprom_Index+1)); Eeprom_Index+=2; } pinMode(13,OUTPUT); Serial.print(F("Servo Controller")); } /****************************************************************************************************************************** #Loop *******************************************************************************************************************************/ void loop() { if(Read_command()) /* True if new command / sequence received */ { Check_Command(); /* Check the command / sequence received */ Command = 'A'; /* Reset the command variable */ Value = 0; Angle = 0; } if(Sequence_Finish) /* True if sequence is received */ { Set_Sequence(); /* Assign the received angles to corresponding servos */ Rotate_Sequence(); /* Turn the servos to new positions */ Seq_Index = 0; Sequence = 0; Seq[Seq_Index] = ''; Sequence_Finish = 0; Loop_Count=0; /* Reset the variables to receive next sequence */ } } /****************************************************************************************************************************** #Function 1 - Read_command() Extracts all the necessary parameters from the received sequence *******************************************************************************************************************************/ boolean Read_command() { if(Serial.available() > 0) { char Rec_data = Serial.read(); Serial.print(Rec_data); if(Set_Servo_number && (Rec_data != '\r' && Rec_data != '\n')) { if(isdigit(Rec_data)) { Value = (Value*10) + (Rec_data-'0'); /* Get servo number */ Angle = 0; } if(Sequence==1 && Rec_data == ' ') { Seq[Seq_Index] = Value; /* Extract the angles of 18 servos from the seq. */ Seq_Index++; Value=0; /* & store in array */ } } if(Rec_data == '0' && Servo_Enable_Disable) { Servo_Enable_Disable = 0; } if(Rec_data == '0' && Set_Servo_Direction) { Set_Servo_Direction = 0; } if((Servo_Reset_Angle == 1 || Get_Servo_Position == 1 || Set_Servo_Speed == 1) && (Rec_data != '\r' && Rec_data != '\n')) { if(isdigit(Rec_data)) { Angle = (Angle*10) + (Rec_data-'0'); /* Get angle received as parameter with command */ } } if(Set_Servo_number == 1 && Rec_data==':') { Sequence=1; /* Seq. received in the format S:<sequence> */ } if(Rec_data == '\n') /* Command ends with \r\n */ { if(Sequence==1) /* If seq. is received, terminate the array & set flag */ { Seq[Seq_Index]=''; Sequence_Finish=1; } Command_Finish = 1; Set_Servo_number = 0; return true; } if(Rec_data == 'S') { Set_Servo_number = 1; } if(Rec_data == 'E') { Servo_Enable_Disable = 1; Command = 'E'; Set_Servo_number = 0; } if(Rec_data == 'Z') { Servo_Reset = 1; Command = 'Z'; Set_Servo_number = 0; } if(Rec_data == 'R') { Servo_Reset_Angle = 1; Command = 'R'; Set_Servo_number = 0; } if(Rec_data == 'P') { Get_Servo_Position = 1; Command = 'P'; Set_Servo_number = 0;Angle=0; } if(Rec_data == 'D') { Set_Servo_Direction = 1; Command = 'D'; Set_Servo_number = 0; } if(Rec_data == 's') { Set_Servo_Speed = 1; Command = 's'; Set_Servo_number = 0; } if(Rec_data == 'F') { Servo_Default = 1; Command = 'F'; Set_Servo_number = 0; } if(Rec_data == 'W') { Save = 1; Command = 'W'; Set_Servo_number = 0; } } return false; } /****************************************************************************************************************************** #Function 2 - Check_Command() Perform action based on the command received *******************************************************************************************************************************/ void Check_Command() { if(Command_Finish) { Command_Finish = 0; Serial.println(Command); switch(Command) { case 'E' : Enable_Disable(); break; case 'Z' : Reset_Servo(); break; case 'R' : Set_Reset_Angle(); break; case 'P' : if(((Angle - Servo_No[Value].Prev_Angle) > 3)||((Servo_No[Value].Prev_Angle - Angle) > 3)) Set_Servo_Position(); break; case 'D' : //Set_Direction(); break; case 's' : Set_Speed(); break; case 'F' : Factory_Reset(); break; case 'W' : Save_Parameters(); break; default : break; } } } /****************************************************************************************************************************** #Function 3 - Enable_Disable() Enable / Disable the servo as per the command received *******************************************************************************************************************************/ void Enable_Disable() { if(Servo_Enable_Disable) { Servo_Enable_Disable=0; Enabled_Servos++; Serial.print("Servo"); Serial.print(Value); Serial.print("Enabled , ");Serial.print(Enabled_Servos); servo[Value].attach(Value+1); servo[Value].write(Servo_No[Value].Reset_Angle); Servo_No[Value].Prev_Angle = Servo_No[Value].Reset_Angle; } else { Serial.print("Servo"); Serial.print(Value); Serial.print("Disabled, "); servo[Value].detach(); Enabled_Servos--;Serial.print(Enabled_Servos); } Value=0; Angle=0; } /****************************************************************************************************************************** #Function 4 - Reset_Servo() Resets the servo *******************************************************************************************************************************/ void Reset_Servo() { Serial.print("Reset "); Serial.print("Servo"); Serial.print(Value); if(servo[Value].attached()) { servo[Value].write(Servo_No[Value].Reset_Angle); Servo_No[Value].Prev_Angle = Servo_No[Value].Reset_Angle; Value = 0; Angle = 0; Servo_Reset = 0; } } /****************************************************************************************************************************** #Function 5 - Set_Reset_Angle() Sets reset angle of the servo *******************************************************************************************************************************/ void Set_Reset_Angle() { Serial.print("Servo"); Serial.print(Value); Serial.print(" Reset Angle : "); Serial.print(Angle); Servo_No[Value].Reset_Angle = Angle; Value = 0; Angle = 0; Servo_Reset_Angle = 0; } /****************************************************************************************************************************** #Function 6 - Set_Servo_Position() Moves servo to the position received *******************************************************************************************************************************/ void Set_Servo_Position() { Serial.print("Servo"); Serial.print(Value); Serial.print(" Position : "); Serial.println(Angle); if(servo[Value].attached()) { while(Angle != Servo_No[Value].Prev_Angle) { Serial.print(Servo_No[Value].Prev_Angle); if(Angle < Servo_No[Value].Prev_Angle) { servo[Value].write(Servo_No[Value].Prev_Angle); Servo_No[Value].Prev_Angle--; } else { servo[Value].write(Servo_No[Value].Prev_Angle); Servo_No[Value].Prev_Angle++; } delay(Servo_No[Value].Speed); } } Value = 0; Angle = 0; Get_Servo_Position = 0; } /****************************************************************************************************************************** #Function 7 - Set_Speed() Set the angles as per the sequence received *******************************************************************************************************************************/ void Set_Speed() { switch(Angle) { case 1 : Servo_No[Value].Speed = 100; break; case 2 : Servo_No[Value].Speed = 50; break; case 3 : Servo_No[Value].Speed = 20; break; case 4 : Servo_No[Value].Speed = 10; break; case 5 : Servo_No[Value].Speed = 5; break; default : break; } Serial.print("Servo"); Serial.print(Value); Serial.print(" Speed : "); Serial.println(Servo_No[Value].Speed); Value = 0; Angle = 0; Set_Servo_Speed = 0; } /****************************************************************************************************************************** #Function 8 - Factory Reset() Initialize the objects with default values *******************************************************************************************************************************/ void Factory_Reset() { for(i=1; i<19; i++) { Servo_No[i] = {90,90,90,50}; /* Initialize the objects with default values */ } Serial.print("Factory Reset"); Value = 0; Angle = 0; Servo_Default = 0; } /****************************************************************************************************************************** #Function 9 - Set_Sequence() Set the angles as per the sequence received *******************************************************************************************************************************/ void Set_Sequence() { for(i=0; i<18; i++) { Servo_No[i+1].Current_Angle = Seq[i]; Serial.print(i+1); Serial.print(' '); Serial.println(Servo_No[i+1].Current_Angle); } if(Servo_No[i+1].Current_Angle == Servo_No[i+1].Prev_Angle) Enabled_Servos--; Seq_Index=0; Sequence=0; Seq[Seq_Index]=''; } while(Loop_Count != Enabled_Servos) { for(i=1; i<19; i++) { if(servo[i].attached()) { //Serial.print("Servo"); Serial.print(i);Serial.print(" "); if(Servo_No[i].Current_Angle < Servo_No[i].Prev_Angle) { //Serial.print(Servo_No[i].Prev_Angle);Serial.print(", "); servo[i].write(Servo_No[i].Prev_Angle); Servo_No[i].Prev_Angle--; if(Servo_No[i].Current_Angle == Servo_No[i].Prev_Angle) {Loop_Count++;} } else if(Servo_No[i].Current_Angle > Servo_No[i].Prev_Angle) { //Serial.print(Servo_No[i].Prev_Angle);Serial.print(", "); servo[i].write(Servo_No[i].Prev_Angle); Servo_No[i].Prev_Angle++; if(Servo_No[i].Current_Angle == Servo_No[i].Prev_Angle) {Loop_Count++;} } } } //Serial.print(Loop_Count);Serial.print(", ");Serial.println(Enabled_Servos); } //Serial.println("Loop Finished"); } /****************************************************************************************************************************** #Function 11 - Rotate_Sequence() Saves the parameters permanently *******************************************************************************************************************************/ void Save_Parameters() { Eeprom_Index=0; for(i=1; i<19; i++) { EEPROM.write(Eeprom_Index, Servo_No[i].Reset_Angle); EEPROM.write(Eeprom_Index+1, Servo_No[i].Speed); Eeprom_Index+=2; } } /****************************************************************************************************************************** >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< *******************************************************************************************************************************/ |
Resources
Shop With Us








Leave a Reply
You must be logged in to post a comment.