12 channel maestro not responding to serial via USB

Hi, when i connect the 12 channel maestro to windows and use maestro control center i am able to move the servo.
however, when it is plugged into my debian linux, i try to write the example bytes 0x84, 0x00, 0x70, 0x2E (using php) to set the servo to 1500 uS, the maestro does not respond (though the green solid light starts flashing).
here are the things that i have done:
set serial setting to dual port (using maestro control center), used the PHP serial communication script by remy sanchez.
in php, ive set the byte length to 7 bits. i write bytes into /dev/ttyACM1 by writing chr(byte value). (im sure using chr(byte value) works as i’ve done this with another project.)

this is my script. please tell me what i am doing wrong:

<?php

    require("php_serial.class.php");


    $serial = new phpSerial();


    $serial->deviceSet("/dev/ttyACM1");


    $serial->confBaudRate(9600); //Baud rate setting, although apparently not needed
    $serial->confParity("none");//partiy, needed?
    $serial->confCharacterLength(7); //byte length to 7 bits
    $serial->confStopBits(1);//stop bits, needed?

    $serial->deviceOpen();

    $serial->sendMessage(chr(0x84));
    $serial->sendMessage(chr(0x00));  //bytes sent one bye one
    $serial->sendMessage(chr(0x70));
    $serial->sendMessage(chr(0x2e));

    $serial->deviceClose();

?>

thank you

Hello, Bashar.

I’m sorry you are having trouble. In the future please use [code ] and [/code ] tags (without the spaces) around your code to format it nicely.

The device /dev/ttyACM1 is probably the Maestro’s TTL Serial Port, not the Command Port. Please try “/dev/ttyACM0”.

–David

thanks a lot mate. solved everything :slight_smile:

Thanks for this code! I got it working for the 24 Channel Maestro, can send instructions but not receive responses. When I “readport” from the connection, after sending the get_position (compact protocol) command, I do get 2 bytes back as expected, but they are both 0. It should be the position of the servo (which is definitely not 0). Here is the code:

$serial->sendMessage(chr(0x90));
$serial->sendMessage(chr(1)); 
$result = $serial->readPort();
echo "length: " . strlen($result) . " hex: " . bin2hex($result) . "\n";

The output is: “length: 2 hex: 0000”

Has anyone got some experience receiving responses from the theses devices in PHP, that might help me in the right direction please?

Howard

Ah, I found out the problem. The speed of the servo needs to be set to equal to or lower than the physical limitation of the servo.

Here are some working functions that work with the code above that use the Compact Serial Protocol that is documeted in the in Pololu Maestro user guide.

[code]
function set_servoposition(&$serial, $servonum, $position)
{
$serial->sendMessage(chr(0x84) . chr($servonum) . chr($position & 0x7F) . chr(($position >> 7) & 0x7F));
return 0;
}

function set_servospeed(&$serial, $servonum, $speed)
{
$serial->sendMessage(chr(0x87) . chr($servonum) . chr($speed & 0x7F) . chr(($speed >> 7) & 0x7F));
return 0;
}

function set_servoacceleration(&$serial, $servonum, $acceleration)
{
$serial->sendMessage(chr(0x89) . chr($servonum) . chr($acceleration & 0x7F) . chr(($acceleration >> 7) & 0x7F));
return 0;
}

function set_servohome(&$serial)
{
$serial->sendMessage(chr(0xA2));
return 0;
}

function get_servoposition(&$serial, $servonum)
{
$serial->sendMessage(chr(0x90) . chr($servonum));
$result = $serial->readPort();
return (ord(substr($result,-2,1))+ord(substr($result,-1,1))*256);
}

function get_movingstate(&$serial)
{
$serial->sendMessage(chr(0x93));
$result = $serial->readPort();
return (ord(substr($result,-1,1)));
}

function moving_wait(&$serial, $servonum)
{
while(get_movingstate($serial))
{
}
}[/code]

Enjoy.

Howard