Mini 12 as master, mini12 slave. TTL

I have gotten my hands on a couple of these 12 ch mini controllers.
and i`m really impressed of hardware.

Now i do have a project:
Id like to use one as a master, using buttons and pots to control servos and ESC`s at the slave.

I do have some questions. but first i think i must make a picture.

lets say that i have 1 pot, and 2 buttons. now i could wire these so i only use 2 channels.
The pot will set the speed of the ESC, the 2 buttons will control the position of one servo (one of 3 positions).
the switch will be NO, and it will be closed aslong i press it.

Im trying to crunch away at the commands. but i find it little confusing.
Ive been programming some in VB. i should have the logical

So first question, what command line should i use to set slave servo 0 to a function of master 0 input?
Secondly, what range can i get max on the TTL line from one to another??

Hello.

Assuming that your intention is to use internal scripting on the master Mini Maestro 12, you could write a script like this on the master:

begin
  0 get_position    # get the value of the pot, 0-1023
  4 times 4000 plus # scale it to 4000-8092, approximately 1-2 ms
  0 slave_servo     # set slave servo 0 based to the value
repeat

sub slave_servo
  0x84 serial_send_byte # Send "Set Target" command byte
  serial_send_byte      # Send channel byte
  dup
  0x7F bitwise_and serial_send_byte    # Send first target byte
  7 shift_right 0x7F bitwise_and serial_send_byte   # Send second target byte
  return

You should set both Maestro’s serial modes to “UART, fixed baud rate” and configure them to have the same baud rate (e.g. 9600). You would connect the GNDs of the two boards and connect the master’s TX line to the slave’s RX line. You should also check the “Run script at startup” button on the master.

The master will be sending a constant stream of Set Target commands to the slave.

I have successfully sent serial signals through 2-foot test cables many times. If you want more than 5 feet or so you’ll probably need additional hardware on the line to buffer the signal. If you want really long distances you might want RS-485 transceivers.

–David

1 Like

Thank you for answering.
Il probably need some time decoding that, into something i understand. still learning.

about the range… i was looking at a min of 330 feet. wireless is probably out of the question (though wireless signas can be transmitted using wire as “air”

i can give you a hint… subsea.

Hi David and Lobster2b,

I apologize for resurrecting a very old thread. Although it was exactly what I was looking for and I think the example code you provided will work for my application. I will be using 5 analog inputs on a master mini 12 and then have a slave micro maestro 6 receiving serial commands from the master mini 12 to move the servos on the slaved micro maestro 6.

Just for my own knowledge could you go into a little more detail on this section of the code.

sub slave_servo
  0x84 serial_send_byte 
  serial_send_byte     
  dup
  0x7F bitwise_and serial_send_byte   
  7 shift_right 0x7F bitwise_and serial_send_byte 
return

I would like to know what the purpose of each line is. The annotations give some idea but a little more detail would help me understand a little better. I have read the maestro manual, but realized that documentation on the Serial Output section was limited.

Also do you think running a TTL line 4 feet will be problematic or do you recommend staying within 2 feet? :slight_smile:

Hello, Trevor.

I would not expect 4 feet to cause too much of a problem, but it could depend on the particular wire you use (e.g. shielded or not, as well as the wire gauge). You might want to do a quick test with your setup.

The “Set Target” serial command is composed of the following bytes:

  • “Set Target” command byte (0x84).
  • Servo channel number
  • low bits of target value
  • high bits of target value

Note, as described by the entry for “Set Target” in the “Serial Servo Commands” section of the Maestro user’s guide, the target value needs to get broken up into two bytes: one holding the lower 7 bits of the target and one holding bits 7-13 of the target.

The way the slave_servo subroutine is set up in David’s code, it is expecting to be called after 2 values are placed on the stack: the target position followed by the servo channel number. The first line of the subroutine (0x84 serial_send_byte) simply sends the “Set Target” command byte. The second line (serial_send_byte) is going to send whatever value is on top of the stack, which should be the channel number. Note that this removes the channel number from the stack, leaving just the target position. The dup command is then called to copy the target position value, since we are going to need to break it into parts. 0x7F bitwise_and serial_send_byte masks the target value on top of the stack with 0x7F, leaving only the first byte, and sends that value (this removes the duplicate target value). Then, 7 shift_right 0x7F bitwise_and serial_send_byte bit-shifts the target value left on the stack by 7, effectively leaving you with what you need for the second target byte.

If you are still uncertain about how it works, please let me know which specific part is unclear and I would be happy to try to break it down more.

Brandon

1 Like

Hey Brandon,

Thanks for your reply. That is exactly the info I was looking for. So lets say I wanted to control 3 servos via 3 analog inputs. Would the below code be sufficient for that?

begin
  0 get_position    # get the value of the pot, 0-1023
  4 times 4000 plus # scale it to 4000-8092, approximately 1-2 ms
  0 slave_servo     # set slave servo 0 based to the value

  1 get_position    # get the value of the pot, 0-1023
  4 times 4000 plus # scale it to 4000-8092, approximately 1-2 ms
  1 slave_servo     # set slave servo 0 based to the value

  2 get_position    # get the value of the pot, 0-1023
  4 times 4000 plus # scale it to 4000-8092, approximately 1-2 ms
  2 slave_servo     # set slave servo 0 based to the value
repeat

sub slave_servo
  0x84 serial_send_byte # Send "Set Target" command byte
  serial_send_byte      # Send channel byte
  dup
  0x7F bitwise_and serial_send_byte    # Send first target byte
  7 shift_right 0x7F bitwise_and serial_send_byte   # Send second target byte
  return

Yes, that code should work for controlling servos on channels 0, 1, and 2 on your secondary Maestro from analog inputs on channels 0, 1, and 2 on your primary Maestro (respectively).

Brandon

Hey Brandon,

I’m getting a bit of noise on the servos from the serial line.

I saw this example code in the manual, But how do I combine this to work with sending out via serial?

# Set the servo to 4000, 6000, or 8000 depending on an analog input, with hysteresis.
begin
  4000 0 300 servo_range
  6000 300 600 servo_range
  8000 600 1023 servo_range
repeat
 
# usage: <pos> <low> <high> servo_range
# If the pot is in the range specified by low and high,
# keeps servo 0 at pos until the pot moves out of this
# range, with hysteresis.
sub servo_range
  pot 2 pick less_than logical_not    # >= low
  pot 2 pick greater_than logical_not # <= high
  logical_and
  if
    begin
      pot 2 pick 10 minus less_than logical_not   # >= low - 10
      pot 2 pick 10 plus greater_than logical_not # <= high + 10
      logical_and
    while
      2 pick 0 servo
    repeat
  endif
  drop drop drop
  return
 
sub pot
  1 get_position
  return

Hello.

I would be surprised if the serial is causing the noise you are seeing. I suspect it is just noise in your analog input. You might be able to smooth it out by taking the reading multiple times and getting an average.

If you still want to adapt that example of setting the servos to specific predetermined positions based on the analog input, you would need to modify the subroutines since they are not set up in a way to be used with multiple inputs and servos. To modify them to accept the servo channel and input channel as inputs (like they do right now for the position, low, and high settings) you could modify them to look like this:

sub servo_range
  pot 4 pick less_than logical_not    # >= low
  pot 4 pick greater_than logical_not # <= high
  logical_and
  if
    begin
      pot 4 pick 10 minus less_than logical_not   # >= low - 10
      pot 4 pick 10 plus greater_than logical_not # <= high + 10
      logical_and
    while
      4 pick 2 pick servo
    repeat
  endif
  drop drop drop drop drop
  return
 
sub pot
  dup get_position
  return

To call that modified servo_range subroutine, you would need to put the desired values on the stack in the following order: . For example, to set the servo on channel 0 to 4000, 6000, or 8000 depending on an analog input on channel 1, with hysteresis, your loop would look like this:

begin
#  <pos> <low> <high> <servo ch.> <input ch>
  4000 0 300 0 1 servo_range
  6000 300 600 0 1 servo_range
  8000 600 1023 0 1 servo_range
repeat

If you want to combine the two scripts and send the servo positions through serial to another Maestro, you can keep the slave_servo subroutine in your script and call that instead of the servo command in the servo_range subroutine. So, the 4 pick 2 pick servo line in my modified servo_range subroutine above would change to 4 pick 2 pick slave_servo

Brandon