Mini Maestro with LibSerial

I have the code:

#include <SerialStream.h>
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace LibSerial;

int main(int argc, char** argv){
     
    SerialStream maestro;
    maestro.Open("/dev/ttyACM0");

    if (!maestro.good())
    {
        std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] "
                  << "Error: Could not open serial port."
                  << std::endl;
        exit(1);
    }
    
    maestro.SetBaudRate(SerialStreamBuf::BAUD_115200);
    maestro.SetCharSize(SerialStreamBuf::CHAR_SIZE_8);
    maestro.SetNumOfStopBits(1);
    maestro.SetParity(SerialStreamBuf::PARITY_NONE);
    maestro.SetFlowControl(SerialStreamBuf::FLOW_CONTROL_NONE);

    char cmd[] = {0xAA, 0x0C, 0x04, 0x04, 0x70, 0x2E};
    maestro.write(cmd, sizeof(cmd));
    
    maestro.Close();
}

and I compiled it with g++ SimpleServo.cpp -L/usr/etc/lib -lserial. When I run the program with the controller connected, it doesnt move the servo at all. I know the servo and controller work because the command works fine using Pololu’s serial terminal. Are all of my settings correct? I wasn’t sure about Flow control, and there are also VTime and VMin that I haven’t messed with. I am running Ubuntu. Any help would be appreciated.

Hello.

I am sorry you are having trouble with the Maestro.

What is “Pololu’s serial terminal”? Are you referring to the Pololu Maestro Control Center? Could you please use the Maestro Control Center to save a settings file and post it here so we can check your settings? Does the green LED on the Maestro blink when you run the program? That would indicate USB activity. It looks like your command sets the target of the servo on channel 4 to 1500 us. Are you sure there is a servo on that channel and are you sure it isn’t already at the 1500 us position? Could you post some pictures of your setup and a wiring diagram?

I did not see any problems with your code, but I am not familiar with LibSerial. You might try some of the code we have in the “Serial Example Code” section of the Maestro user’s guide just in case there is a problem with your code.

–David

The serial terminal is called “pololu serialtransmitterV1.3” pololu.com/docs/0J23 (and it worked fine). However, my green LED wasn’t blinking when I ran my C++ program. I changed the baud rate from 115200 to 9600 and now it works. Do you know what would cause that?

I am glad you got it working but I don’t know why changing the baud rate would have fixed it.

–David