Micro Maestro 6 on Mac OS X 10.8

(1st posted this in the wrong forum - reposting here)

New to Maestro. I have a working setup using a Maestro 6 where it drives a Hobbywing motor controller and a motor. I have this working on a Windows PC running the Maestro Control Center program, but I need to get this working on a Mac mini from a C program.

When I plug the Maestro’s USB cable into the Mac, OS X auto-creates 2 serial devices, /dev/cu.usbmodem00026231 and /dev/cu.usbmodem00026233. The documentation says the lower numbered device is the command port. My C program can open the device, set tty attributes on it, and write to it, but the motor never moves. I can see the green LED on the Maestro flicker, so I know data is coming into the Maestro over the USB line, but nothing happens.

Here is my (very) short but complete C program. It uses the ‘mini SSC protocol’ and is based on the sample code in the documentation.

Thanks for your help!

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>

int main(int argc, const char * argv[])
{
    ////////////////////////////////////////////////////////
    //  Open the Maestro's virtual serial port
    const char * device = "/dev/cu.usbmodem00026231"; // Mac OS X cmd port
    int fd = open(device, O_RDWR | O_NOCTTY);
    if (fd == -1) {
        perror(device);
        return -1;
    }    
    
    ////////////////////////////////////////////////////////
    //  Set the serial port's attributes and baud rate
    speed_t baudRate = B9600;
    struct termios options;
    tcgetattr(fd, &options);
    options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    options.c_oflag &= ~(ONLCR | OCRNL);
    cfsetspeed( &options, baudRate );
    tcsetattr(fd, TCSANOW, &options);
    
    ////////////////////////////////////////////////////////
    //  Command the servo
    unsigned char val = 0;
    for (val=0x00;val<0xFF;val++) {
        unsigned char command[] = {0xFF, 0x00, val};
        if ( write(fd, command, sizeof(command)) == -1) {
            perror("error writing");
            return -1;
        }
    }
    close(fd);
    return 0;
}

Hello.

What serial mode have you configured your Maestro be in? I recommend “USB Dual Port”. Also you’ll probably want to delay between commands or else all your commands might just take a few milliseconds to send.

–David

Hi David,

For a while, I did have a usleep() command in my C program after every write() command, ranging from 500000 down to 10000. It did change the flicker rate of the green LED on the board, so it was making some kind of difference, but wasn’t the core problem. I’ll put it back in at any rate. Do you recommend any specific value for it?

In the Maestro Control Center program, I had set the Maestro’s serial mode to “UART fixed baud rate 9600”. Is this mutually exclusive to the “USB Dual Port” mode? I will set that up again with the Windows PC, and then try again from the Mac. At that point, should I still set the serial device (/dev/cu.usbmodem00026231) to 9600 baud?

Thanks!

The serial modes are mutually exclusive and they are documented in the “Serial settings” section of the Maestro user’s guide. Since you are using a virtual COM port and the bytes you are sending are never actually manifested as TTL serial signals, it doesn’t matter what baud rate you choose in your code.

–David

Indeed, setting it to USB Dual Port mode did the trick! And a usleep does help to keep things working orderly.
Thanks, David!

Hi Santous,

Don’t know if you’ll see this, but how did you find the two virtual serial port numbers on your mac? I can’t figure out how to find the numbers. Are they the same as the serial numbers that can be found in the command software on windows?

Thanks,
George

Hello, George.

It looks like you created a new thread about the same issue. Please see my response there.

- Amanda