hi guys,
i have seriel 8 servo controler and im using it on mini ssc mode.
i want to connect to it with a switch (pico switch).
im tring to make it do on and off.
can someone help me use it in c++, what I need to send to get it on and how can I get it off.
thanks.
I have an old C++ demo program for Pololu mode here. If you wanted to simplify it to use MiniSSC-II mode, it would look something like this:
/*
Pololu Serial Servo Controller Test Program, MiniSSC-II Mode
V 1.0
Adam Borrell
3/31/09
*/
#include <stdio.h>
#include <windows.h>
#include <time.h>
//FUNCTION PROTOTYPES
HANDLE openPort(int);//Serial protocol stuff, don't worry about it
HANDLE comPort;//Serial protocol stuff, don't worry about it
void putMSSCII(int servo, int angle);//Moves servo (0-7) to angle (500-5500)
void waitMS(int ms);
int done=0;
int main(){
printf("Pololu Serial Servo Controller Test Program, MiniSSC-II Mode\n\n");
comPort=openPort(5);//***PUT YOUR COM PORT NUMBER HERE!***
if(done){
printf("Program Terminated!\n");
system("PAUSE");
return -1;
}
putMSSCII(0,0);//set servo 0 to position 0
waitMS(500);//pause for 1/2 second
putMSSCII(0,254);//set servo 0 to position 254
CloseHandle(comPort);
printf("Program Terminated!\n");
system("PAUSE");
return 0;
}
void putMSSCII(int servo, int angle){
unsigned char buff[3];
DWORD len;
if(angle>254){
angle=254;
}
if(angle<0){
angle=0;
}
buff[0]=255;
buff[1]=servo;
buff[2]=angle;
WriteFile(comPort, &buff, 3, &len, 0);
printf("Servo %d Set to %d\n", servo, angle);
}
void waitMS(int ms){
clock_t endwait;
endwait=clock()+ms*CLOCKS_PER_SEC/1000;
while(clock()<endwait);
}
HANDLE openPort(int portnum){
char port[]="com", pnum[]="Error";
itoa(portnum,pnum,10);
strcat(port,pnum);
HANDLE serial=CreateFile(port,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
if(serial==INVALID_HANDLE_VALUE){
if(GetLastError()==ERROR_FILE_NOT_FOUND){
printf("Error, %s Not Found\n", port);
done=1;
return serial;
}
printf("Com Error\n");
done=1;
return serial;
}
DCB dcbSerialParams={0};
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
if(!GetCommState(serial, &dcbSerialParams)){
printf("Com State Error\n");
done=1;
return serial;
}
dcbSerialParams.BaudRate=CBR_19200;//CBR_baudrate
dcbSerialParams.ByteSize=8;
dcbSerialParams.Parity=NOPARITY;//NOPARITY, ODDPARITY, EVENPARITY
dcbSerialParams.StopBits=ONESTOPBIT;//ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS
if(!SetCommState(serial, &dcbSerialParams)){
printf("Serial Protocol Error\n");
done=1;
return serial;
}
COMMTIMEOUTS timeouts={0};
timeouts.ReadIntervalTimeout=50;
timeouts.ReadTotalTimeoutConstant=50;
timeouts.ReadTotalTimeoutMultiplier=10;
timeouts.WriteTotalTimeoutConstant=50;
timeouts.WriteTotalTimeoutMultiplier=10;
if(!SetCommTimeouts(serial,&timeouts)){
printf("Timeout Setting Error\n");
done=1;
return serial;
}
return serial;
}
-Adam
P.S. I’ve been pushing my luck with less than thoroughly tested code lately, so let me know if this doesn’t work properly.
itws not working
but thanks.
and I need only the way to turn on and off the pico switch.
to use the servo I already know.
Controlling the PicoSwitch should be just like controlling a servo. You would send it to a low “position” (i.e. 0) to switch it one way, and a high “position” (i.e. 254) to switch it the other way.
-Adam
Thank you very much i but u found another way