Mini Maestro 12 Channel servo controller

Hi I bought the Mini Maestro 12 channel servo controller and can run it with the Maestro controller UI. I am using a Pico ITX board that runs linux. So ive downloaded the Maestro controller UI and also the necessary files as explained in the Maestro Servo Controller’s user guide. I tried using the c code here to try and send commands to the Maestro using my ITX computer, but when I run this in command line it runs the code but the servo does not seem to move, neither does the yellow light flash on the board. Any ideas of what I might be doing wrong. I have copy pasted the same exact code provided.

Please help me,
Thank you,
Divey

Hello, Divey.

Could you please provide a link to the C code you tried to run? If you found it in the Maestro User’s Guide, there will be comments at the top telling you how to configure the Maestro. Did you follow those instructions? Is there any output from the program at all?

–David

Hi thanks so much for your fast reply. I have posted the code which i have used. Basically there are no build errors and also no run time errors but the servo just does not move. Well one thing im not sure about is the like that says ttyACM0, how does it know which USB port to find the maestro at?? maybe thats why the maestro does not receive the commands. Any help with this please. Thanks in advance.
Thanks,
Divey

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
 
 
 
// Sets the target of a Maestro channel.
// See the "Serial Servo Commands" section of the user's guide.
// The units of 'target' are quarter-microseconds.
int maestroSetTarget(int fd, unsigned char channel, unsigned short target)
{
  unsigned char command[] = {0x84, channel, target & 0x7F, target >> 7 & 0x7F};
  if (write(fd, command, sizeof(command)) == -1)
  {
    perror("error writing");
    return -1;
  }
  return 0;
}
 
int main()
{
  // Open the Maestro's virtual COM port.
  //const char * device = "\\\\.\\USBSER000";  // Windows, "\\\\.\\COM6" also works
  const char * device = "/dev/ttyACM0";  // Linux
  //const char * device = "/dev/cu.usbmodem00034567"; // Mac OS X
  int fd = open(device, O_RDWR | O_NOCTTY);
  if (fd == -1)
  {
    perror(device);
    return 1;
  }
 
  int target = (position < 6000) ? 7000 : 5000;
  printf("Setting target to %d (%d us).\n", target, target/4);
  maestroSetTarget(fd, 0, target);
   
  close(fd);
  return 0;
}

It looks like your code is taken from our cross-platform C example in the user’s guide but you removed important parts of the code. I do not expect your code to compile because you did not define the variable “position” anywhere. Please try to compile and run our example code without modifying it, just so you can get something working. Please tell me how exactly you are compiling and running the code.

Also, please type ls /dev/ttyACM* and show post the output from that command here.

Once again, the original code has comments at the top telling you how to configure the Maestro. Did you follow those instructions?

–David

hi, i am ney palma, the person who send the code for pic18f4550 in c, maybe i can help u with your problem?

Greetings

Hi David,
The code i previosuly sent you is the way I expect to use it, because for my purposes I dont need to know the current position of the servo so i just took the get position function out and set a default value of the position variable. One piece of information I forgot to give you was i am connecting the servo controller to the ITX using a mini USB, does that affect anything? I have posted below the actual code im using and also the output of ttyACM0. Thanks in advance.

Output of ttyACM0:
ls /dev/ttyACM*
output: /dev/ttyACM0 /dev/ttyACM1

My code that i am using is below:
// Uses POSIX functions to send and receive data from a Maestro.
// NOTE: The Maestro’s serial mode must be set to “USB Dual Port”.
// NOTE: You must change the ‘const char * device’ line below.

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

#ifdef _WIN32
#define O_NOCTTY 0
#else
#include <termios.h>
#endif

// Sets the target of a Maestro channel.
// See the “Serial Servo Commands” section of the user’s guide.
// The units of ‘target’ are quarter-microseconds.
int maestroSetTarget(int fd, unsigned char channel, unsigned short target)
{
unsigned char command[] = {0x84, channel, target & 0x7F, target >> 7 & 0x7F};
if (write(fd, command, sizeof(command)) == -1)
{
perror(“error writing”);
return -1;
}
return 0;
}

int main()
{
// Open the Maestro’s virtual COM port.
const char * device = “\\.\USBSER000”; // Windows, “\\.\COM6” also works
//const char * device = “/dev/ttyACM0”; // Linux
//const char * device = “/dev/cu.usbmodem00034567”; // Mac OS X
int fd = open(device, O_RDWR | O_NOCTTY);
if (fd == -1)
{
perror(device);
return 1;
}

#ifndef _WIN32
struct termios options;
tcgetattr(fd, &options);
options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
options.c_oflag &= ~(ONLCR | OCRNL);
tcsetattr(fd, TCSANOW, &options);
#endif

int position = 1500;
printf(“Current position is %d.\n”, position);

int target = (position < 6000) ? 7000 : 5000;
printf(“Setting target to %d (%d us).\n”, target, target/4);
maestroSetTarget(fd, 0, target);

close(fd);
return 0;
}

The original code (and the new code you posted) has comments at the top telling you how to configure the Maestro. Did you follow those instructions?

–David