Need coding help!

Hi everyone. I have no coding experience I am have been doing a lot of reading, but with no luck. I have a Micro Maestro 6 and a switch with a continuous servo. I put a 100k resistor on the switch and that shows it is working in the status menu along with my servo. What I am trying to do is I would think would be relatively simple, but I have no clue. I want to simply hit the switch one time and tell the servo to go “x” amount and stop. Then, hit the switch again and it will go another “x” amount of distance and so forth. Please help with coding and any questions please ask. Thank you, very much.

Hello.

I suggest reading through the “Example Scripts” section of the Maestro user’s guide. In particular, the “Using a button or switch to control servos” example should be helpful for doing what you described. Since you are new to Maestro scripts, you might find the “Step Script” button in the “Script” tab of the Maestro Control Center useful for slowly progressing through your script and making sure it does what you expect it to do. If you try writing a script and have problems or questions, you can post your script here, and I would be happy to take a look.

By the way, since continuous rotation servos typically do not have position control like standard servos, in order to move the servo a specific distance, you will probably have to do it based on timing unless you implement some kind of limit switch. A method based on timing like this might not be very accurate, which could be a problem for some applications.

-Brandon

Ok, thank you Brandon. I have setup a script setup below. I can make the switch hit something to stop the servo each time. So it would start with the switch closed and when it opens and hits a mark and closes the switch the servo stops. Is there a way to have two switches? I could start and stop it using two switches. I just have no clue on how to do it. The script I have now, it starts by hitting the switch and then stops when I hit it again.
ScriptMos.txt (2.3 KB)

It is possible to control a servo using two switches/buttons like you described. There are many ways you might go about doing something like that. You could make duplicate subroutines for the other switch (e.g. you could create a button2 subroutine that does a get_position command to check the status of a switch on a different channel). Doing it like this would either require separate wait_for_button_open_10ms and wait_for_button_closed_10ms subroutines for each button, or some modifications to how they work.

Another way of accomplishing two button control could be to modify the button subroutine to check the state of the servo and use it to decide which channel it should use to look for the button. For example, if you had your button inputs on channels 0 and 1, and your servo on channel 2, your modified button subroutine might look like this:

sub button
   2 get_position 6000 equals if        #if the servo (channel 2) is stopped
     0 				  #set the channel to be checked to 0
   else				  #else (servo is moving)
     1				  #set the channel to be checked to 1
   endif
   get_position 500 less_than	  #check the state of the specified input channel
return

If you used something like the modified button subroutine above, the rest of your code would probably not need to change.

-Brandon

Ok, Brandon. I have hooked up two switches and they are on servo 0 and 1. I have made them inputs, but the problem I am having is when I press one switch the other one does the exact same movements and vice versa. How do I get them to work independently in the status screen? Thank you.

It sounds like you might have your buttons wired incorrectly. Can you try double checking that your buttons are connected as described under the “Button or switch” heading in the “Attaching Servos and Peripherals” section of the Maestro user’s guide, using a separate resistor for each channel? If you still get the same result, you can post some pictures of your setup, and I would be happy to take a look.

-Brandon

It all is working perfectly!! Thank you so much. Another question that I have is instead of using the second switch is it possible to use my Spektrum DX7 as a switch? I assigned on my transmitter a switch and plugged in a servo to confirm it was working and it does. However, when I plug it into my maestro I get nothing in either input or servo. Actually in input it makes everything go crazy. I even took the signal wire and put it on a 100k resistor with no luck. Is there a way to do this from my transmitter? Thank you, Brandon.

I am glad you were able to get it working with two separate switches.

The Maestro does not directly accept hobby RC signals like the ones from your Spektrum DX7 as an input. However, you could use something like our RC Switch with Digital Output, which can accept an RC signal and output a digital signal that can be read by a Maestro channel configured as an input.

-Brandon

Hi Brandon.

I received the RC switch yesterday and I hooked it up. Before I had two manual switches I pressed and they would both work individually and my code worked great. I wanted to get rid of one of the switches and you recommended the RC switch. It works great in the status menu as input open and closing. Now though when I press my original manual switch it makes the RC switch also (follows it) go in the same direction. How can I get them to move by themselves like before? Again, the RC switch works and the manual switch stays where it is in the Status Menu. As soon as I press the manual switch the RC switch goes with it to the same side in the Status Menu. When I had the two manual switches on they worked beautifully independently. I am not running any scripts just trying to get them to work in the Status Screen. Please help, thank you.

Hi Brandon.

Never mind as I figured it out. I did not realize that I had to also hook the signal wire to the resistor. Works great.

I am glad you were able to get it working; however, I do not see why you would need a resistor for the connection from the RC switch to the Maestro. Could you post some pictures of your setup that show all of your connections?

-Brandon

Hi guys,

Sorry to piggy back onto another guy’s post, but I have a similar problem to dd4485 at one point. As best I can read from this thread, he never did actually clarify how he managed to get two input switches suddenly working, and it’s not entirely clear that he did properly.

When I activate a 2nd channel as an “input” on the control center, it simply mirrors the previous input channel. That is, they both show as activating when I press a button. The same problem that dd4485 had.

The wiring is incredibly simple. 5v line, through resistor, to the signal line (leftmost pin column when the micro is aligned with the battery input at the top-right), and then a “button” simply shorts the signal line to gnd (right most pin column)

Again, I can’t actually read with any clear certainty that he got two channels working as independent inputs, yet did at one point have the same problem that I’m having. Is it confirmed that the micro can handle more than 1 input button? Beyond wiring, what could possibly be causing this?

*** EDIT *** Well like dd4485, suddenly mine started working fine. I can only assume I had a short somewhere, despite being really careful. :frowning: The other channels set as input lines do subsequently all drop a little when one is shorted, so the sample code with values of ~512 may or may not work correctly with more than 1 input. I dropped my if/then value to ~200 to ensure only the intended, and fully shorted line was handled when executing code. **** /EDIT ****

Hello, Mashee.

I would not expect the input lines on other channels to drop when you push a button connected to a different channel, especially when the drop sounds so significant (over 2.5V). I suspect something might be wrong with the way you have it wired. To connect multiple buttons, you can use the information under the “Button or switch” heading in the “Attaching Servos and Peripherals” section of the Maestro user’s guide. Please note that for multiple buttons, you should have a pull-up resistor on each signal pin that a button is connected to.

If you continue having problems with this, could you start a separate thread about your problem and include details such as the resistor values you are using and pictures of your setup that show all of your connections?

-Brandon