Is this possible?

Hi all, I’m new to all of this, so please be easy on me :wink: In a nutshell, I’m searching for a relatively uncomplicated way to fabricate a flip up door/panel in the dashboard of my car. I would like to control one servo, movement will be limited to about 90 degrees. I would like to use a rocker switch whereby ‘on’ would move the servo 90 degrees, and ‘off’ would return the servo to zero degrees. Would this be possible with a Pololu servo controller and servo? If so, could you recommend an appropriate controller and servo?

Thanks

Hello.

Yes, it is possible. I would recommend the Micro Maestro 6-Channel USB Servo Controller. The user’s guide has sections on how to connect a switch/button and write a script for the Maestro that does something based on the input.

- Ryan

Thanks Ryan, appreciate the response, cheers!

Hey Ryan, I ordered the controller and a couple of servos, thanks. One other quick question. When looking over the users guide, it states that to use a button, you must “wire a pull-up resistor (1–100 kilo-ohms) between the signal line of that channel and 5 V so that the input is high (5 V) when the switch is open.” Can you give me a link to such resistor as I’m not familiar with the pull up type and I don’t want to order the wrong thing.

Thanks

Hello.

The term “pull-up” doesn’t describe the type of resistor, it describes how it is used. A pull-up resistor is just a normal resistor that is used to weakly pull a floating pin to a voltage that represents a logic-level high (e.g. 5V in a 5V system). If you use the resistor to pull the pin to ground (logic-level low), you call it a pull-down resistor.

- Ben

Ah, gotcha Ben, thanks for the explanation, that makes sense. So when it calls for a 1-100 kilo ohm resistor(pardon the seemingly dumb question) what ohm rating should I use? I’m assuming it has to be in between 1-100, or is the 1 denoting the number of resistors? Will this work, linky:
radioshack.com/product/index … 107594276#

It means you should use a resistor with a value between 1 kOhm and 100 kOhm. The resistor you linked to will work, but it’s got a much higher power rating than you will need, so you could probably save a few cents (or get a few more resistors for that $1) if you get 1/8 or 1/4 W resistors. If your pull-up resistor is dissipating 1/2 W, something is going wrong! 5V across a 1k resistor will dissipate P=V^2/R=25/1000, or a mere 0.025 W.

I also recommend you use a higher-value resistor, such as 10k. Small (low-resistance) pull-up resistors are strong pull-ups. They cause the voltage on the node to rise more quickly and to settle closer to the voltage you’re trying to pull up to. However, the down side is that strong pull-ups cause more current to flow from VCC to GND when the node is being driven low, which means lost power.

Unless you have very specific requirements for your system’s performance or something weird in your circuit, you usually don’t need to give much thought to the specific value of the pull-up. 1k to 100k will generally work just fine.

- Ben

sorry to high-jack the thread but will this resistor work?

cgi.ebay.com/6-Resistors-1-4-Wat … _783wt_905

Wow, that is a terrible picture! Yes, those resistors will work. As I said in my previous post, 1k resistors make fairly strong pull-up/pull-down resistors and waste more power than weaker ones when the pin is driven to the opposite voltage, so I typically suggest something closer to around 10k. However, if an extra 5 mA of current draw in your circuit isn’t a big deal to you, 1k resistors are fine.

Note that 1k resistors make good current-limiting resistors for LEDs, so it’s still useful to have them around, even if you don’t use them for pull-ups.

- Ben

Hey ben, appreciate your time and the great info, thanks! I’m also assuming that i will need a step down regulator for use with my cars 12v system-set to output 6v. Will this be sufficient pololu.com/catalog/product/2103, in between the cars system and the servo controller? I will be powering the controller and servo from the same power source.

I don’t think that regulator will be sufficient to power your servos, but it really depends on the specific servos you are using and how many. A good rule of thumb is to budget around an amp per standard servo you have in your system, though it can be less if you know you will never have a situation where all of your servos are straining at the same time. Beefier servos and digital servos will typically draw more, and smaller servos will typically draw less. I don’t know enough about your system to make a strong recommendation, but I think something like our D15V35F5S3 or D15V70F5S3 step-down regulators would be much more appropriate.

- Ben

Ok Ben, thanks again for the tips. I’ll order the one you suggested. In the meantime, I’m playing around with scripting, this thing is really cool!:slight_smile: So my dumb question for the day is, once I get the script the way I want it, how do I load that into the controller so it runs independent from the usb/software control center?

I’m glad to hear you like it! You can find the answer to your question in the Maestro Control Center portion of the user’s guide.

- Ben

Hi Ben, wondering if you can give me a hand here. I am still trying to write the script for my project. I have a switch connected to the controller and it works fine. I am trying to have the servo move to a specific spot when the switch is flipped on. When the switch is flipped off, I would like there to be about an 8 second delay before returning to the original position. I can get the servo to cycle, but I’m having to cycle to the off position every time I want to change the servo movement and I"m not having any luck with the delay, and most probably, I suck at coding:) I am just using the example provided:

goto main_loop    # Run the main loop when the script starts (see below).
 
# This subroutine returns 1 if the button is pressed, 0 otherwise.
# To convert the input value (0-1023) to a digital value (0 or 1) representing
# the state of the button, we make a comparison to an arbitrary threshold (500).
# This subroutine puts a logical value of 1 or a 0 on the stack, depending
# on whether the button is pressed or not.
sub button
  0 get_position 500 less_than
  return
 
# This subroutine uses the BUTTON subroutine above to wait for a button press,
# including a small delay to eliminate noise or bounces on the input.
sub wait_for_button_press
  wait_for_button_open_10ms
  wait_for_button_closed_10ms
  return
 
# Wait for the button to be NOT pressed for at least 10 ms.
sub wait_for_button_open_10ms
  get_ms # put the current time on the stack
  begin
    # reset the time on the stack if it is pressed
    button
    if
      drop get_ms
    else
      get_ms over minus 10 greater_than
      if drop return endif
    endif
  repeat
 
# Wait for the button to be pressed for at least 10 ms.
sub wait_for_button_closed_10ms
  get_ms
  begin
    # reset the time on the stack if it is not pressed
    button
    if
      get_ms over minus 10 greater_than
      if drop return endif
    else
      drop get_ms
    endif
  repeat
 
# An example of how to use wait_for_button_press is shown below:
 
# Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
# a sequence of positions on servo 1.
main_loop:
begin
  4000 frame
  8000 frame
repeat
 
sub frame
  wait_for_button_press
  1 servo
  return

Hello,

In the future, please use the “Code” button to format your code to be more readable.

Anyway, it looks like you just copied our example of how to detect a button press and release, even though that is not what you want to do.

What you want is actually much simpler - the example above that, where it says “…you might want the servo to go to discrete positions depending on the input value…” is much closer to what you want. If you can understand that script, you should be able to put an 8 second delay in an appropriate place and get the behavior you described.

-Paul

Actually, on second thought, it would be much better to write something like

begin
  4000 1 servo # start at position 4000
  begin button logical_not while repeat # wait for the button to be pressed
  8000 1 servo # go to position 8000
  begin button while repeat # wait for the button to not be pressed
  8000 delay # wait 8 seconds
repeat

sub button
0 get_position 500 less_than
return

(I did not test that.) If you have trouble getting the code to work or understanding it, I recommend stepping through it using the Control Center so that you can see exactly what each line does.

-Paul

Awesome PauL!!! Works like a charm! I appreciate your help on this. I do really want to learn this though,and this will give me a great start;)
Cheers!

Great, I am glad that it worked for you! (Usually when I post untested code it does not work right away.)

-Paul

I’ll post a little vid when I’m done to show you what I’ve been up to;)

Thanks again for everyones help. Here is a short vid of what I have been up to. You can see your script in action here Paul, thx:)