Arduino code for daisy chained Maestro's

Hi,

I am totally new to Maestro, but so far very impressed.
I’ve just managed to connect my Arduino to one Maestro. Currently the Arduino code reads the state of one button and then runs the script of the Maestro, while another button stops it.

[code]#include <PololuMaestro.h>

#ifdef SERIAL_PORT_HARDWARE_OPEN
#define maestroSerial SERIAL_PORT_HARDWARE_OPEN
#else
#include <SoftwareSerial.h>
SoftwareSerial maestroSerial(10, 11);
#endif

MicroMaestro maestro(maestroSerial);

const int buttonPin1 = A0;
const int buttonPin2 = A1;
int buttonState1 = 0;
int buttonState2 = 0;

void setup()
{
maestroSerial.begin(9600);

pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}

void loop()
{

buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);

if (buttonState1 == HIGH) {
maestro.restartScript(0);
}

if (buttonState2 == HIGH) {
maestro.stopScript();
}
}
[/code]

NOW, I would like to press those same buttons and run/stop the scripts of about 10 Maestro’s. I have gathered that daisy chaining the Maestro’s to the Arduino might be the best option. However, the Arduino code that then controls those actions are completely eluding me.

  1. What do I need to add to the above code to make those buttons run/stop the scripts of several daisy chained Maestro’s?
  2. Is there anything that will need to happen on the Maestro side? Do I first load the script that is associated to each Maestro onto each of them separately and then daisy chain them? Or how does this work?

I just need the simplest and most efficient way to control the playback of ‘recorded’ sequences that have been copied to the script of several Maestro’s via one Arduino.

Thanks for all the help so far!

Best
Nelmarie

Edit: Sorry, this post is incorrect, please see my post below.

Hello, Nelmarie.

If you want to individually control your Maestros, you would need to assign those Maestros different Device Numbers, which you can change under the “Serial Settings” tab of the Maestro Control Center. (You will need to keep track of the Device Numbers that you assign to each Maestro.) Then you would pass the Device Numbers of the Maestros you want to control to the restartScript and stopScript methods one at a time. For example:

// Restart scripts for Maestros with Device Numbers: 0, 1, and 12.
maestro.restartScript(0);
maestro.restartScript(1);
maestro.restartScript(12);

However, if you do not need individual control, you could assign the same Device Number to all of your Maestros so that they all respond. For example, when you call restartScript(0), all Maestros with the specified Device Number should respond to the signal. (Note that if you want to get a response from your Maestros without assigning unique Device Numbers, you will need a separate AND gate to ensure that you never have more than one transmitting at a time.)

You would need to program each Maestro with their associated scripts using the Control Center before daisy chaining them. Each of your Maestros needs to be configured to UART serial mode and connected as shown in the “Daisy chaining serial devices that have a TXIN input” wiring diagram in the Maestro’s user’s guide.

- Amanda

Hi Amanda,

I’ve been trying to get this to work, but I assume that my connections might be wrong.

I have tried to connect two MICRO Maestro’s and attempted your first suggestion to assign different device numbers and passing those numbers into the restartScript. When I press my button I get stack overflow/underflow and the first maestro’s LED turns red, whereas the second one just flashes Red and then goes back to Yellow (blinking). I also noticed that when I hold the button in, all the LED’s turn off

I have connected both Maestro’s RX pin’s to my Arduino Uno’s RX (receiving pin), which according to the example codes can be pin 10.
I have also connected both Maestro’s to ground.

When I have one Maestro connected to the Control Centre via USB I can observe that the script is Run when I press the button but then stops after a one loop to give the Stack Overflow/Underflow error. (I have also NOT inserted any quit commands).

I also noticed that when neither of the Maestro’s are connected via USB then one Maestro blinks yellow and the other has a static Yellow LED and a Red one that blinks lightly.

Do you have any idea what I might be doing wrong?

I will try to figure out how to build the AND gate as well to see if this will work better for me as I don’t really need individual control. (I have never built one… so another learning curve)

Best
Nelmarie

Sorry, my previous post is completely incorrect. What that code does is call different subroutines on the same Maestro, which could explain why you were getting stack overflow and underflow problems.

Each Maestro object can only command a specific device number (you can set the device number of the Maestro using the Control Center). If you don’t specify the device number when constructing a Maestro object, it talks to all of the Maestros on the daisy chain.

Here is an example for controlling 3 different Maestros on the same daisy chain:

// The reset pin's default value is 255, indicating no reset pin is used.
// Creating MicroMaestro objects for Maestros assigned Device Numbers 0, 1, and 12.
MicroMaestro maestro0(maestroSerial,255,0);
MicroMaestro maestro1(maestroSerial,255,1);
MicroMaestro maestro12(maestroSerial,255,12);

// Restart scripts for Maestros with Device Numbers: 0, 1, and 12.
maestro0.restartScript(0); // restart device number 0's script at subroutine 0
maestro1.restartScript(0); // restart device number 1's script at subroutine 0
maestro12.restartScript(2); // restart device number 12's script at subroutine 2
maestro1.stopScript(); // stop script for device number 1

You do not need to wire up the receiving side of a daisy chain unless you want to receive responses from the Maestros, so I would recommend you avoid dealing with AND gates and receiving from the Maestros until you get transmitting working well.

If you are still having problems, can you post a wiring diagram, your Maestro script and Arduino sketch, and pictures of your setup that shows all your connections clearly?

- Amanda

Hi Amanda,

Thanks SO much for your help! I had a feeling that this could be an issue, but didn’t have the confidence I guess to test it.
It is working perfectly now! However, I had to make one more connection that I had missed. I also had to connect the VPIN of each Maestro to the VPIN of the Arduino.

I still have two buttons. One running the scripts and one for stopping… This can obviously be changed. I was more after figuring out how to connect/control the Maestro’s - so now I can focus on the arduino side, as I want to add all kinds of sensors to trigger scripts.

Here’s a pic of the three Maestro’s connected to the Arduino:


A quick crappy Fritzing diagram (unfortuantely no time to make a Maestro part):


The Arduino Code:

[code]#include <PololuMaestro.h>

/* On 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). */
#ifdef SERIAL_PORT_HARDWARE_OPEN
#define maestroSerial SERIAL_PORT_HARDWARE_OPEN
#else
#include <SoftwareSerial.h>
SoftwareSerial maestroSerial(10, 11);
#endif

// The reset pin’s default value is 255, indicating no reset pin is used.
// Creating MicroMaestro objects for Maestros assigned Device Numbers 0, 1, and 12.
MicroMaestro maestro0(maestroSerial,255,0);
MicroMaestro maestro1(maestroSerial,255,1);

const int buttonPin1 = A0;
const int buttonPin2 = A1;
int buttonState1 = 0;
int buttonState2 = 0;

void setup()
{
maestroSerial.begin(9600);

pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}

void loop()
{

buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);

if (buttonState1 == HIGH) {
maestro0.restartScript(0);
maestro1.restartScript(0);

}

if (buttonState2 == HIGH) {
maestro0.stopScript();
maestro1.stopScript();

}

}

[/code]

Again, thanks so much for your quick help! You have saved me invaluable time!
I will post the final project here, once it is completed.

Best
Nelmarie

Great! I am glad you got it working; thank you for letting us know.

Good luck on your project!

- Amanda