Some functions of Arduino Pololu library do not seem to work

I’m trying to get the moving state from a Mini-Maestro (12) using “int movingState = maestro.getMovingState();” (where maestro is the object) but the Arduino script blocks when it reaches that instruction. I noticed the same problem with “getPosition(x)”.
My Arduino is interfaced with the Mini-Maestro through pins 18 (Tx) and 19 (Rx) at 9600 bds and also provides the power to the Maestro card.
The only instructions i use are setTarget(x,y) (Pololu lib) and delay(z) (Arduino)
What did i wrong?
Thank you,

Hello, Richard.

Which Arduino board are you using? Can you provide more details about your setup? Reading through our support page should give you a good idea of the kind of information that would be helpful in troubleshooting. In particular, posting your entire code would be helpful.

- Amanda

Hello Amanda,

Thank you for your answer.

My card is an Arduino Mega and i use pins 18 (Tx) and 19 (Rx) to connect to Maestro.
The set-up of the Maestro card is as described in the example program (i did not change it as it was already like that by default)

  • Serial mode: UART, fixed baud rate
  • Baud rate: 9600
  • CRC disabled

I suspect a problem with receiving data at Arduino side…

Here is my code (i just re-used the example program and made some changes; blocking instructions
are commented out)

/* This example shows how to control a single servo on a Maestro
servo controller using the PololuMaestro library. It assumes you
have an RC hobby servo connected on channel 0 of your Maestro,
and that you have already used the Maestro Control Center
software to verify that the servo is powered correctly and moves
when you command it to from the Maestro Control Center.

Before using this example, you should go to the Serial Settings
tab in the Maestro Control Center and apply these settings:

* Serial mode: UART, fixed baud rate
* Baud rate: 9600
* CRC disabled

Be sure to click "Apply Settings" after making any changes.

This example also assumes you have connected your Arduino to your
Maestro appropriately. If you have not done so, please see for more details on how
to make the connection between your Arduino and your Maestro. */

#include <PololuMaestro.h>

/* On#include <SoftwareSerial.h> boards with a hardware serial port available for use, use
that port to communicate with the Maestro. For other boards,
create a SoftwareSerial object using pin 10 to receive (RX) and
pin 11 to transmit (TX). */
  #define maestroSerial SERIAL_PORT_HARDWARE_OPEN
  #include <SoftwareSerial.h>
  SoftwareSerial maestroSerial(19, 18);

/* Next, create a Maestro object using the serial port.

Uncomment one of MicroMaestro or MiniMaestro below depending
on which one you have. */
//MicroMaestro maestro(maestroSerial);
MiniMaestro maestro(maestroSerial);

int  movingState=0;
int serPosition = 0;

void setup()
  // Set the serial baud rate.

void loop()
  /* setTarget takes the channel number you want to control, and
     the target position in units of 1/4 microseconds. A typical
     RC hobby servo responds to pulses between 1 ms (4000) and 2
     ms (8000). */

  // Set the target of channel 0 to 1500 us, and wait 2 seconds.
  Serial.println("Set to 6000");
//  movingState = maestro.getMovingState();
//  serPosition = maestro.getPosition(0);
//  Serial.print("Position: ");
//  Serial.println(serPosition,DEC);

  Serial.println("Set to 2200");

Thank you,

I looked at your code and did not notice anything obviously wrong. Can you disconnect the Maestro from your Arduino Mega and try doing a loopback test to make sure pins 19 and 18 on your Arduino are working? You can use the Serial Monitor in the Arduino IDE to send data to your Arduino and verify it is being echoed back in the terminal. Please make sure to also connect RESET to GND in addition to connecting pins 19 and 18 together on your Arduino board so that your program does not run during the loopback test.

If the loopback test works, can you post pictures of your setup showing how you have everything connected and describe the behavior of the LEDs on-board the Maestro?

- Amanda

Hello Amanda,
I don’t really understand how the Serial Monitor will show data from pins 19 (Rx), unless i write a program to receive data from the Serial Monitor via the USB interface, send it to pin 18 (Tx), read pin 19 (Rx) and send it back to the Serial Monitor. Am i right?
I’ll try to do that and let you know.

Hello Amanda,

I found how to get Rx working:

  • first i changed the Rx/Tx pins from 19/18 to 11/10 (according to examples from Arduino, pin 19 and others doesn’t handle interrupts)

  • then i added “maestroSerial.listen()” prior to call getMovingState() and i receive an answer from the Maestro board

Thank you again,

Thank you for letting us know that you resolved your issue.

It sounds like you are using software serial on pins 11 and 10 to communicate between your Maestro and Arduino Mega instead of using another hardware serial port. Since the Arduino Mega has 3 additional hardware serial ports, we recommend using one of them over software serial, because it has a higher processing overhead compared to hardware serial. You can find more information about the Arduino Mega’s hardware serial ports and the Arduino SoftwareSerial library on the Arduino website.

If you do decide to use a hardware serial port to communicate with the Maestro and are still having problems using Serial1 (pins 19 and 18) on your Arduino Mega, you might want to try using Serial2 instead. To do this, remove the 6-line block of code that defines maestroSerial, and replace it with #define maestroSerial Serial2. Then you could connect the Maestro’s RX and TX lines to pins 16 (TX2) and 17 (RX2) on the Arduino, respectively.

Regarding your earlier post, I apologize for the confusion. I mistook Serial1 (or serial port 1) for Serial (or serial port 0) on your Arduino Mega. Your description on how to go about reading pin 19 and writing it to the Serial Monitor is correct. You can use the example code for the Arduino Mega near the bottom of the Serial available() page on the Arduino website to verify that RX1 (pin 19) is working.

- Amanda

Hello Amanda,

I apologize for this late answer but i was without Internet and on the way between France and Belgium.
I’ll modify my test-program according to your recommandations and let you know, but i’m quite busy with other things for the moment.


Hello Amanda,

I have changed my program to follow your recommandation (Serial2) and it now works fine.

Thanks a lot,

1 Like