Micro Maestro 12ch + Xbee Pro, COM port connection problems

Hello guys,

I recently purchased one Micro Maestro 12ch servo controller and two Xbee pro 60 mw wireless antennas (http://www.sparkfun.com/products/8742) together with two Xbee Explorer USB (http://www.sparkfun.com/products/8687). Our aim was to attain wireless communication with Micro Maestro through the two Xbee pro’s which communicate through Serial COM Ports. The picture bellow shows the working setup with direct connection to PC and everything went smoothly using the Pololu Maestro control Center.

But once we switch to wireless communication through the 2 Xbee Pro Modules, the Pololu Maestro control Center just doesn’t detect that the Micro Maestro is connected. ( Before hand, we tested the 2 Xbee Pro’s separately by connecting each of them to a different computer, we were able to achieve serial port communication between the two computers using Xbee’s X-CTU program.)

Now we don’t understand why it doesn’t work at all… I was browsing through the forums and came across this thread: Micro Maestro and Arduino FIO for 3 Servos and an ESC where it was mentioned that it is possible to “connect the XBee’s ground to the Maestro’s GND and connect the XBee’s TX to the Maestro’s RX” then it would work.

Much help and advice would be gladly appreciated!

-Joshua

Hello, Joshua.

The Maestro Control Center only works with the Maestro’s native USB connection, not its TTL serial connection. You should still be able to control the Maestro through the Xbees with serial commands (see section 5 of the Maestro user’s guide).

- Kevin

Thanks so much for the prompt reply! I have used your Pololu Serial Transmitter and my whole setup works! Thanks! I have begun trying to program something similar to your program, and I am having difficulties trying to write the data onto the COM ports. Here’s the code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;


namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        static SerialPort _serialPort3;

        int channelNumber, target, realTarget, offset, count;

        int[] serialBytes = int[4];

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string a = textBox1.Text; // channel number in string

            channelNumber= Convert.ToInt32(a);
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            string b = textBox2.Text; // target number in string

            realTarget = Convert.ToInt32(b);

            target = (realTarget*4);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            offset=0;
            count=4;
 
            
            serialBytes[0] = 0x84;
            serialBytes[1] = channelNumber; // First data byte holds channel number.
            serialBytes[2] = target & 0x7F; // Second byte holds the lower 7 bits of target.
            serialBytes[3] = (target >> 7) & 0x7F; // Third data byte holds the bits 7-13 of target.

            _serialPort3 = new SerialPort("COM3");

            _serialPort3.Open();

            _serialPort3.Write(serialBytes, offset, count);


        }

       
    }
}

Basically, Once you enter the Target (in integer) in textBox2 and the channel in textBox1, it will save it to the array. But now, I am not sure about the datatype of the array.I read the serial servo commands section of the PDF guide and it say’s Target and Channel are both integers…

Could you advise me on how I would be able to continue from here? I am a newbie to C# and programming in general.

Thanks so much!

Hello, Joshua.

What happens when you try to compile and run the C# code?

I think one problem is that serialBytes is an array of ints instead of an array of bytes, as required by the SerialPort.Write method.

You should try just hardcoding the serialBytes for now. Once you get that working, then add the interface for changing the target and channel.

–David

I haven’t ran the code as “_serialPort3.Write(serialBytes, offset, count);” gets underlined in red and it says it has invalid arguments…

Thanks once again!

-Joshua

done some hardcoding, still got the same error (“serialPort3.Write(serialBytes, 0, 4)” gets underlined…).

Here’s the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;

namespace test
{
    class Program
    {
        static SerialPort _serialPort3;

        static void Main(string[] args)
        {
         

            int[] serialBytes = new int[4];

            serialBytes[0] = 0x84;
            serialBytes[1] = 0x00; // First data byte holds channel number.
            serialBytes[2] = 0x70; // Second byte holds the lower 7 bits of target.
            serialBytes[3] = 0x2E; // Third data byte holds the bits 7-13 of target.

            _serialPort3 = new SerialPort("COM3");

            _serialPort3.Open();

            _serialPort3.Write(serialBytes, 0, 4);
        }
    }
}

I think one problem is that serialBytes is an array of ints instead of an array of bytes, as required by the SerialPort.Write method. Also I recommend reading the error messages you get from Visual Studio because they are usually useful.

–David

Hi thanks for the advice! At least now the “_serialPort3.Write(serialBytes, offset, count);” problem has been solved. I have been reading the error messages and sometimes I don’t understand what they mean. I have changed the array datatype to bytes now. Now in my Form program, it underlines the variable channel and target:

        serialBytes[0] = 0x84;
        serialBytes[1] = [u]channelNumber[/u]; // First data byte holds channel number.
        serialBytes[2] = [u]target & 0x7F[/u]; // Second byte holds the lower 7 bits of target.
        serialBytes[3] = [u](target >> 7) & 0x7F[/u]; // Third data byte holds the bits 7-13 of target.

It says “cannot implicitly convert int to byte…” but in the maestro PDF guide the sample code says the datatype of target and channelNumber are suppose to be int? I’m very confused :frowning:

Thanks for all the help!!!

Joshua

Consider the following simple C# code:

int x = 4000;
byte y = x;    // error: cannot implicitly convert int to byte

The C# compiler is warning you about this because you are trying to set an 8-bit int (y) equal to a 32-bit int (x). It’s possible that data will be lost when you do this, because y has fewer bits than x. You have to explicitly tell the compiler that you are OK with losing data. The way to do this is to use a cast:

int x = 4000;
byte y = (byte)(x);    // no error

Now apply that to your code and it should fix that compiler error.

–David