ArduinoBT + Maestro Serial Protocol always producing error

Hello,

I’m trying to control a Maestro 12 channel Servo Controller from an AuduinoBT.
I’m not sure I have the boards wired correctly.
I have the RX wried to the TX on each board.

I can control the servos with a PC.

I have the board set to a fixed baud of 9600 and I want to use the compact message format.

This is the function I am using.

void moveMotorToTarget(int motor, int target)
{
  Serial.print("Move motor:");
  Serial.print(motor,DEC);
  Serial.print(" to target:");
  Serial.println(target,DEC);
  
  
  if (mySerial.available())
  {
    mySerial.print(0x84, BYTE);  // motor command  
    mySerial.print((byte)motor, BYTE);  
    mySerial.print(target & 0x7F, BYTE);
    mySerial.print((target >> 7) & 0x7F,BYTE);
  }
  else
  {
    Serial.println("serial not available");
  }
}

The serial is available but as soon as I start sending commands to the Maestro Board the red error led turns on and if I think connect via USB I see a Server Protocol error.

Any help would be appreciated.

thanks!

My guess is that you need to change this line:

if (mySerial.available())

to this:

if (mySerial.available() >= 4)

Since you didn’t actually post the code that defined mySerial, I don’t know what kind of object it is, so this is only a guess. If this guess doesn’t solve your problem then please simplify your code to the simplest possible thing that demonstrates the problem and then post ALL of it, and use Code tags this time so it is more easily readable.

–David

Please see this page for directions on how to wire a Maestro to a microcontroller for serial control:

pololu.com/docs/0J40/7.c

–David

Thanks for you input so far. It’s still not working. (red error led)

Here is the rest of the code.

#include "NewSoftSerial.h"

#define rxPin 0
#define txPin 1

NewSoftSerial mySerial(rxPin, txPin);

void setup() 
{
  Serial.begin(115200);
  mySerial.begin(9600);   
  delay(100);
  val = 4000;
}

void moveMotorToTarget(int motor, int target)
{
  Serial.print("Move motor:");
  Serial.print(motor,DEC);
  Serial.print(" to target:");
  Serial.println(target,DEC);
  
  if (mySerial.available()>4)
  {
    mySerial.print(0x84, BYTE);  // motor command  
    mySerial.print((byte)motor, BYTE);  
    mySerial.print(0, BYTE);
    mySerial.print(0,BYTE);
  }
  else
  {
     Serial.println("serial not available");
  }
}
void loop() 
{
   moveMotorToTarget(0,val);
   val+=1000; 
  if (val >8000)
    val =4000;
   delay(1000);
}

Hello.

Pins 0 and 1 are hardware serial pins on the Arduino, so using them as software serial pins creates a conflict. What happens if you try using different pins for your software serial, such as 2 and 3, and connect these to your Maestro instead?

- Ben

thanks! moving to pins 2 and 3 solved the issue.