Coding difference between digital and analog servo?

Hi All,

I'm not a coder myself (a friend of mine has been helping me with that part) and I'm new to Arduino and servos. So my hunch is that the problem I'm running into is something simple, but for the life of me my researches on Google and on this forum haven't enabled me to figure it out yet. Hence this post.

PROJECT OVERVIEW
I am building a machine that helps to speed up one of the processes in our new, small business. We have small tubes that are filled with a specific volume of small vegetable seeds, and I have created a small machine that will speed this process up by about 3x when it is up and running. It uses a high torque digital servo (20kg-cm). I've linked to several videos below, as well as to the tech specs for the servo we are using, and the foot pedal we would like to use. **Please note, in the first video I have a Raspberry Pi hooked up to the servo, but I've since switched to an Arduino Uno (along this line, I still need to figure out whether the USB of the foot pedal can be hooked up to the Arduino, and how, to allow me to step on the pedal to command the servo to move).

SEED FILLING MACHINE VIDEO 1: Dropbox - IMG_6613.MOV - Simplify your life
SEED FILLING MACHINE VIDEO 2: Dropbox - IMG_6855.MOV - Simplify your life
SEED FILLING MACHINE VIDEO 3: Dropbox - IMG_6857.MOV - Simplify your life

20kg-cm SERVO SPECS LINK: Amazon.com

SERVO TESTER LINK: Amazon.com

ARDUINO MODEL: Amazon.com

LINK TO SETUP (note that we are now using the Arduino Uno and not the pictured Raspberry Pi--but that the servo issue/phenomenon is exactly the same when connected to either one): Dropbox - IMG_6794.jpg - Simplify your life

ISSUE ENCOUNTERED
As you can see in the video, the servo operates perfectly when connected to the servo testing board and controlled using the built in manual testing/control knob. I need the servo to swing, in total, 119 degrees, from seed loading position (a) to seed dumping position (b).

When we connect the servo to the arduino all we get is erratic jittering that appears to have no pattern at all, though it does stay within the 180 degree motion range of the servo. (I don't have the code that she is using available to me currently, but I can have her send it to me so I can post it, if that helps.)

I would normally think the issue to be code related (and it may very well be), but when we then connect a smaller servo the arduino and run the same exact code, this smaller servo works perfectly and follows the code commands. If it helps, I believe that this code is simply the stock arduino code that can be found online for 'servo sweep'.

This leads me to believe that my digital, high torque servo requires a different kind of code to operate correctly? Or that digital servos require different code from smaller, analog servos (the one we were using is a common, cheap servo called the SG-90 and I believe it is made by Tower Pro).

The high torque servo is powered externally, using a dedicated 6V/2A plugged in power source. The low torque (SG-90) servo is powered from the board directly as it does not have a significant power draw.

Here is a link to a photo of the setup we are using. This photo is from when we were using the Raspberry Pi, but we are now using the Arduino Uno and we are using the exact same setup. I'll also note that we had the exact same servo phenomenon (random jittering the moment you plug the servo signal wire in to the PWM port) when we were using the RPi vs the Arduino Uno.

Lastly, in case this helps, I've used 4 separate servos and they all have behaved this way when connected as described above.

I'd love any help that this forum can offer. Thanks to everyone in advance, I appreciate it!

EDITED
I've pasted (below) the code that was being run on successfully on the SG-90 analog servo but that fails to run the listed high-torque digital servo above. Also attached a photo of the setup to this thread.

#include <Servo.h> //include servo library

Servo myservo; //create servo

int z = 0; //create variable that can be incremented to position servo

void setup() {

myservo.attach(5); //attach servo to pin 5 of the Arduino

}

void loop() {

for (z=0;z<=90;z++) { //increment z from 0 to 90, setting the servo to each value as it goes
myservo.write(z);
delay(5);
}

delay(1000);

for (z=90;z>=0;z--) { //decrement z from 90 back to 0, setting the servo to each value as it goes
myservo.write(z);
delay(5);
}

//full program should spin motor 90 degrees and then return to 0, pause for one second, then repeat

}

It would be useful to see the code but in general there is no coding difference between analog and digital servos.

So the two things different between the working SG90 system and the non-working larger LD-20 system are the servo itself and the servo power. The problem sounds like inadequate power or possibly an unregulated power supply or perhaps the servo power supply negative is not connected to the Arduino GND. Can you provide details of the power supply used?

Steve

Thanks Steve. I can have her send me the code, I'll reach out to her now and will add that to the post as soon as I get it from her.

As for the power supply, here is the unit that we're using. It seems to work fine as it connects to the servo test board, and it shows a stable 6.2V output (the servo test board has a digital voltage display built in to it). Plus the servo runs perfectly smoothly (as shown in the videos) when connected to that servo test board.

LINK: Amazon.com

The power supply steps from 6V to 7.5V and the servo shows a maximum voltage tolerance of 7.4V. I realize that this is a 0.1V difference but seeing as I have no experience in the electronics area I am just playing it safe and using 6V, which is within the working voltage parameters given (6-7.4V).

On one of my setups yesterday we forgot to attach the servo power supply negative to the Arduino GND. Could this have damaged the servo? I'm sorry, I don't quite understand what affect that could/would have on the servo. The servo is still working perfectly, but I'm wondering if that may have caused a strange jittery motion to occur?

If you mean that the servo works normally when used with the servo tester board and exactly the same power supply then they would both seem to be o.k. The code is probably also o.k.

I've only just got round to looking at your pictures (posting them off-site without even clickable links makes them really inconvenient to access) so I now see that the most likely explanation for your problems is bad wiring. Connecting a high powered servo through a breadboard is always bad news. Breadboards are only designed for very low currents. Try making more direct connections (soldered or directly plugged) between the servo and its power supply.

Steve

Hi Steve,

Thanks very much for that info, I'm going to try soldering direct connections from the power supply to the servo and ditching the breadboard entirely, we'll see if that gets me where I want to go.

Sorry about the lack of direct links, I completely spaced linking those. I decided to link to them on our dropbox account only because my internet connection here (rural) is terrible and uploading them as attachments would have taken the better part of the day.

Lastly, if I were to search for what hardware I would need to solder this all together, what would I look for (what are the names of the items I should search for online and purchase)? Is a header pin set something that would be a good start, and then just wire one row of the pins together to make it a ground, one row of pins to make it the positive power terminal, and then the last row for signal possibly? This is all pretty new to me. Thanks in advance.

Jeff

Just wanted to chime back in here and let you know that the servo is working perfectly now--thanks very much for your help!

spadetofork:
Just wanted to chime back in here and let you know that the servo is working perfectly now--thanks very much for your help!

I'm glad to hear that and I'm pleased I was able to have helped.

Steve

Your assistance was perfect, thanks again, Steve and have a great rest of your week!

I did just think of one additional question. The foot pedal I had purchased has a USB end to it, because I had originally planned on using a Raspberry Pi 3 for this project. Is there a way to still use this USB foot pedal with my Arduino Uno (I was unable to find a resource directing me on how to connect a USB device to an Arduino to behave as a momentary switch)?

Or, is there another foot pedal that would be better suited for this project and that can connect directly to my Arduino UNO in one or more of the input slot/ports? Here is one pedal that I found, but I do not know how to modify the end of this cable to plug it in to the Arduino.

Foot Pedal Switch Link: Foot Pedal Switch - COM-11192 - SparkFun Electronics

Foot Pedal Switch Link 2: Amazon.com

If anyone has some input on this element I'd love to know. Thanks in advance.

You'll need a USB host controller - there is a USB host shield you can use like this one.

Two important notes:

1.) You might have to do a bit of work trying to find out how to use the USB shield to extract the data you want from it - manuals and readme docs will be your best friend for a while

2.) If you get one of those USB shields, you'll need to do some soldering on it to get it to work, apparently. Check this out: USB Shield Manual

Obviously it would be much easier and cheaper to use either of the two other pedals you've linked since they work like a normal pushbutton (either open or closed).

Thanks, Power_Broker,

Gotcha on the USB shield route.

What if I purchased a simple, 3-wire momentary switch--something super simple. Maybe, instead of complicating things with a USB device, I could use a very basic momentary switch somehow? By something simple, I mean something with the same basic function as one of these push button switches (LINK: Tactile Switch Buttons (6mm tall) x 10 pack : ID 1490 : $2.50 : Adafruit Industries, Unique & fun DIY electronics and kits) but connected to the arduino with a long enough cable to be pressed with the foot?

spadetofork:
What if I purchased a simple, 3-wire momentary switch--something super simple.

The other pedals should act like that - it's whatever is easiest for you (pedal vs switch vs button). I imagine a pedal is the easiest and the switch is the next easiest - but that's entirely up to you

Ok great, well here is the foot pedal that I ended up buying. I'm hoping that I can learn how to hook up the 3 wires that are on this food pedal to the Arduino somehow, and then have my friend code appropriately so the seed filling mechanism goes from position A to position B when the pedal is pressed, and then when it's pressed again goes back from position B to position A.

LINK: Amazon.com

That is a SPDT (Single Pole Double Throw) switch pedal. It also seems that the green striped wire is the pole lead and the white and black are the normally closed and normally open leads (not sure which is which though, - easy to tell with a multimeter and testing the pedal physically)

Thanks again, Power_Broker. Do you happen to know of a resource (ideally one with a few photos) for how to wire a SPDT switch pedal to an Arduino Uno?

This is how you would wire it up with one slight change. Instead of using an external 10K Ohm pullup resistor, I'd use the Arduino digital input pin's internal pullup resistor - making the wiring and circuit easier.

COM would be the green wire and NO (Normally OPEN) would be either the black or white wire (like I said before, not sure which)

Here's a good educational link on switches: https://learn.sparkfun.com/tutorials/switch-basics/all

Perfect thanks again!