Maestro & Arduino Button control

Hello all!
I’ve been going back and forth banging my head against the wall trying to figure out what the issue is. Hopefully someone can help.
I have 2 servos powered by a iMah Ryme B39 6volt 2amp
I have 2 subsequences loaded on maestro servo controller
and an Arduino that is triggering each sequence with 2 separate button presses- button 1 triggers sequence 0 and button 2 triggers sequence1
Everything works as it should when the maestro is connected via usb to the computer. However, once I unplug from the computer and run off the battery it starts to work incorrectly. When I press button2 sequence 0 triggers, as opposed to trigger 1. So basically no matter which button I press only sequence 0 runs. Both sequences use the same servos with different frames.

I am getting a red flashing on the maestro led when I press both buttons and the usb is not plugged in. But when it’s plugged into the computer I do not get the flashing. It is set to run on startup and the weird thing is it still works as intended even when it’s not connected to the maestro control center (but still physically connected to the computer). But if I try to plug the USB into a different power source it does not work, it only works connected to the computer.

My instinct says it has to be an issue in the wiring. I’m using 2 SPST normally open push buttons and a 10k pull down resistor going to Arduino ground for both(maestro is also connected to ground). and the other end going into the Arduino Vin on both. Please someone help me!


### Sequence subroutines: ###

# Sequence 0
sub Sequence_0
  500 5044 6238 3968 3968 3968 5749 
  8000 6571 0 0 0 0 frame_0..11 # Frame 0
  500 3968 frame_6 # Frame 1
  quit
# Sequence 1
sub Sequence_1
  500 5044 6238 3968 3968 3968 5749 
  3968 3968 0 0 0 0 frame_0..11 # Frame 0
  500 5083 frame_6 # Frame 1
  500 3968 frame_6 # Frame 2
  500 5318 frame_6 # Frame 3
  500 3968 frame_6 # Frame 4
  quit

sub frame_0..11
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_6
  6 servo
  delay
  return

#include <PololuMaestro.h>

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


MicroMaestro maestro(maestroSerial);
//MiniMaestro maestro(maestroSerial);
const int buttonPin = 2;
const int buttonPin2 = 3;
int buttonState = 0;
int buttonState2 = 0;
int MotorControl = 5;  

void setup()
{
  maestroSerial.begin(9600);
  pinMode(buttonPin, INPUT);
   pinMode(MotorControl, OUTPUT);
}

void loop()
{
  
  buttonState = digitalRead(buttonPin);
  buttonState2 = digitalRead(buttonPin2);
   if (buttonState == HIGH) {
  maestro.restartScript(01);
  digitalWrite(MotorControl,HIGH);
  //delay(4000);
 } 
 else{
  digitalWrite(MotorControl,LOW);
 }

 // maestro.restartScript(01);
 

if (buttonState2 == HIGH) {
  maestro.restartScript(00);
  //digitalWrite(MotorControl,HIGH);
  //delay(4000);
}
  
}

Hello.

Typically, to use a button with an Arduino, you would connect one side of the button to GND and the other side to the GPIO pin you’re using to read the button input. Then, you can use an internal pull-up on the Arduino by calling pinMode(buttonPin, INPUT_PULLUP); in your setup() function (you should not be connecting them to VIN). This way, the input should read low when the button is pressed, and high otherwise, so you will need to adjust your IF statements accordingly. Additionally, please note that you will need a separate pinMode() declaration for each of your inputs (it looks like you only have one right now).

If that continues to give you trouble, could you post pictures of your setup that show all of your connections? Also, could you post more details about the servos you’re using and how you’re powering the Maestro when it is not connected via USB?

Brandon

Thank you so much for the reply. I changed the code to include an internal pull up. But unfortunately it is doing the same thing.

#include <PololuMaestro.h>

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


MicroMaestro maestro(maestroSerial);
//MiniMaestro maestro(maestroSerial);
const int buttonPin = 2;
const int buttonPin2 = 3;
int buttonState = 0;
int buttonState2 = 0;
int MotorControl = 5;  

void setup()
{
  maestroSerial.begin(9600);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
   pinMode(MotorControl, OUTPUT);
}

void loop()
{
  
  buttonState = digitalRead(buttonPin);
  buttonState2 = digitalRead(buttonPin2);
   if (buttonState == LOW) {
  maestro.restartScript(01);
  digitalWrite(MotorControl,HIGH);
  //delay(4000);
 } 
 else{
  digitalWrite(MotorControl,LOW);
 }

 // maestro.restartScript(01);
 

if (buttonState2 == LOW) {
  maestro.restartScript(00);
  //digitalWrite(MotorControl,HIGH);
  //delay(4000);
}
  
}

Here is the updated wiring




White is going from Arduino TX to Maestro RX
Black connecting Arduino and Maestro Ground
Green to ground and yellow and orange to pins 2 & 3

I’m using Tower Power SG-5010 but I was using Miuzei micro servo MS18 with the same results. I’m powering everything (except the Arduino) with the iMah Ryme B39 Rechargeable Battery pasck 6 volt 2000mAh

Hello.

I tried replicating your setup here and everything seemed to work fine. Do you still get some flashing behavior on the Maestro’s indicator LEDs when you try to run it powered from your battery? If so, could you describe the flashing behavior in more detail? Just to clarify, if you connect the Maestro to your PC via USB and run the program on your Arduino, does it work as expected?

Also, it looks like you might be using an Arduino Uno; is that the case? If so, it’s a little unusual to use pins 0 and 1 for software serial, since those pins are the same pins the Uno uses for hardware serial (and they could have some unpredictable activity when programming or booting up). I would generally recommend avoiding those pins for anything other than hardware serial, so you might consider switching those to some other pins like 10 and 11 (although I don’t think it will fix your problem).

Brandon

Yes, when it is solely running off the battery I get 4 red flashes every time either button is pressed. And yes everything works as expected when plugged into the PC and no red led.
I did try to switch to 10 and 11 but still got the same result.
Just to clarify the only connections to arduino should be ground and arduino tx connected to maestro rx correct?

Yes, for the code you’re running (which isn’t expecting any information back from the Maestro), you should only need to connect the Arduino’s TX pin to the Maestro’s RX pin and a common ground.

When you power the Maestro from only the battery, are you doing so by installing the VSRV=VIN jumper near the BAT pins?

You can find an explanation of the LED behavior in the “Indicator LEDs” section of the Maestro user’s guide. From your description, it sounds like you are probably running into a power issue that’s causing the Maestro to brown-out and reset. Could you try making sure your battery is fully charged and seeing if that makes any difference? Ideally, if you have access to an oscilloscope, you could take a look at the battery voltage and get a better understanding of the problem. Are your servos under any load? If so, I recommend removing that for now. You can also try disconnecting your servos entirely (since they are drawing a large majority of the current compared to the Maestro) and seeing if it still happens.

Brandon

I’ve been attaching the battery to the BAT section that runs in line with the servos + and - connectors. Should I be using the VSRV=VIN instead?

Okay I see what I was doing wrong. I didn’t realize that the blue jumper needs to connect VSRV = VIN. Somehow I must’ve missed that. Connecting them seems to have solved the problem

1 Like