Controlling servo with VB

Sorry for the vague subject, it seemed hard to summerise what I am trying to overcome.

I have an Arduino Duemilanove And a GWS S125 Servo.

For those of you that dont know the S125 is a 360 degree servo (Note: limited 360 not continueos).

I have spent the last week getting to grips with Fimata VB.

I want to be able to do the following:

-Use one of the PWM to directly replace a pot. That is, use the PWM output instead of the sweeping pin on the pot.

-Use 3 outputs to controll relays.

-Use another one of the PWM outputs to control the position of the servo. It will be set to 1 of three locations (o degrees, 100 degrees and 250 degrees)

Now I have managed to use the FirmataVB!.Digitalwrite(Pin,Status) To control the pins for the Relay, and allthough I've yet to try the analogue.write I assume thats as easy to use.

The problems starts with the servo. Because it is a 360degree servo it seems to be causing problems. I have found a sketch on here that allows you to controll the position using the serial monitor, but that requires me to remove the Firmata sletch first.

(The sketch is here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1264208980/3)

Is there any way to combine these two sketches.

Im not asking anyone to do the hard work, but would someone please be able to help as this is really bugging me.

Thank you so much for reading and any help.

Thanks again, Phil.

The problem I have at the moment is that I also want to be able to control the postition

A couple f things here:

I don't think you use PMW to control servos, i think you use ordinary digital pins. Check some of the samples around.

Also you say you want to replace a potentiometer with PWM, this might not be possible.

A petentiometer can be wired as either a variable resistor (two terminals used) or a variable voltage divider (all 3 terminas used).

If its wired a a variable resistor you can probably not replace it with PWM. If its a voltage divider you might be able to but don't count on it.

PWM is not really a variable voltage, its a pulse width modulated squarewave swinging between o and 5 Volts all the time. You only control the duty cycle of the squarewave (on time vs. off time). Some circuits might interpret this as a variable voltage (a DC motor for instance), but others will not. It might be possible to smooth the PWM signal with a simple RC lowpasfilter to simulate a variable voltage, but it doesen't allways work.

What MikMo said - don't use PWM to control an R/C servo, use the servo libraries.

Use one of the PWM to directly replace a pot

"analogWrite" is something of a misnomer - you can't use PWM to directly replace a pot.
You could low-pass filter PWM to give a varying voltage, but this may not necessarily be a potentiometer replacement.

The pot is set up as a voltage devider. If I replace the output fron the voltage diveder with a transister with base to the pwm, collector to positive and use emmiter as the output woulld this not serve the same purpose. I understand the principle of pulse width modulation and duty cycle.

Thanks.

woulld this not serve the same purpose

No, it would simply follow the digital signal.

I understand the principle of pulse width modulation

Note then that PWM != PPM

But they all work on the same principle of data transmition.

Why then does: 0% duty cycle not meen 5 volts
and 100% not meen 5v

I will probably use an rc circuit to smooth the signal.

Btw. Ppm does not have varying duty circles. It's duty cycle stays the se it is it's position in the normaly multiplexed time that is what is uses with ppm.p

But they all work on the same principle of data transmition

No.
A potentiometer will produce and infinitely (in theory) variable voltage between zero and five volts (assuming that's what's on the ends of the post).

PWM at any given instant is either HIGH (5V) or LOW (0V) (not taking into account rise and fall times).

Ppm does not have varying duty c[y]cles. It[']s duty cycle stays the s[am]e

Well, of course, in practice, it doesn't, but that's usually an implementation detail.

Yes but the dc voltage that is produced from the pwm is a variable one.

I understand modulation very well. There's no need to be pedantic. I understand ppm, PCM, and pwm. All methods of data transfer.

Thanks, Phil.

the dc voltage that is produced from the pwm is a variable one

No, it isn't.

If you connect the pwm to a scope you can visualy see the duty cycle. This duty cycle has a direct correlation a sum voltage.

It is known fact that increasing the duty cycle will inevitably increase a voltage. As said at any given time it will be 0 or 1.

Come to think of it I will run it into the inverting input of an op amp with a gain of -1 for other reasons.

I will run it into the inverting input of an op amp

Without filtering, all that's going to do is follow the digital signal.

There's no need to be pedantic

I'm a professional engineer - pedantry pays the bills. :wink:

I too am an electrical engineer by trade.

I don't meen to rub any one up the wrong way. But I was taught, and understand that pwm will make an average voltage between the two power rails equal to the duty cycle.

Thanks.

I tinker a lot with servos, but haven't connected one to my arduino yet. That being said, there seems to be fuzzy knowledge floating about confusing PWM and generating the pulse duration that the servo apparently looks for. Below is a good link for basic info. As to controlling the 360 deg servo, it should use the same commands as a standard 180 deg servo. In stead of rotating 180 deg, the output shaft will rotate 360 deg. For programming, It still should use ~500us to ~2500 for full rotation range. If one is using the 0-180 deg servo control option, divide the 360 deg possible rotation range by 2 to generate the 0-180 deg servo control signal needed.

http://www.lynxmotion.com/images/html/servo01.htm

there seems to be fuzzy knowledge floating about confusing PWM and generating the pulse duration that the servo apparently looks for

I disagree.

If you feed a servo a 50Hz PWM signal, with a duty cycle in the range of about 5 - 10% it will be happy (1 to 2ms out of 20ms).

If you feed the the servo an Arduino-default 490Hz PWM signal with a similar 5 - 10% duty cycle, it will be fairly unhappy.
It may look like it is working, but it may overheat though excessive current consumption.

I disagree.

With what? Driving servos should be done with the purpose written servo libraries.

If you feed a servo a 50Hz PWM signal, with a duty cycle in the range of about 5 - 10% it will be happy (1 to 2ms out of 20ms).

This will work but it's big disadvantage is that you end up with a very poor digital count resolution of what 13-25 counts? not very good compaired to the PPM resolution counts that the servo library can supply.

If you feed the the servo an Arduino-default 490Hz PWM signal with a similar 5 - 10% duty cycle, it will be fairly unhappy.
It may look like it is working, but it may overheat though excessive current consumption.

Agreed, but still moot as the various servo libraries should be used as they are already optimized for driving standard servos.

Lefty

I disagree.

If you feed a servo a 50Hz PWM signal, with a duty cycle in the range of about 5 - 10% it will be happy (1 to 2ms out of 20ms).

I can't speak to how "happy" the servo will be, but it may well work if it falls into the range of electrical characteristics that the servo internals expect to see. The below link has some info on the internals of the typical analog hobby servo.

http://www.seattlerobotics.org/encoder/200009/S3003C.html

@lefty and zoomkat - I think you've misunderstood what I was saying.

I was disagreeing with the assertion that there's a lot of fuzzy knowledge about how servos work - there's a lot of very good information.

This will work but it's big disadvantage is that you end up with a very poor digital count resolution of what 13-25 counts?

That's true if you assume an eight bit PWM controller.
I made no such assumption.

(for the record, I've been connecting R/C servos to microcontrollers (or "microprocessors" as we called them back then) for somewhat over thirty years)

Im still not too sure on how to controll the 360 degree servo correctly. I would like to continue using the FirmataVB library in VB, however im finding it hard to controll servos.

Please, any help would be greatly appriciated.

(I would like to keep the FirmataVB Sketch on the arduino as this is code that I am begining to understand).

Thanks so much in advance, Phil.

Hey Phil,

I'm a bit of a newb and this is actually my first post on the forums but I think I can help although not sure if you haven't already figured something out. In any case I think it will be helpful for others in the future. I'm just finishing up my own project using a Duemilanove and a handful of the GWS S125 1T servo. I'm not sure what VB is (visual basic?) My project was made in the arduino alpha development environment.

I'm not sure what you mean in your first post about not using the pot inside for positioning control (so maybe my help is useless) but I did figure out how to use the GWS S123 1T servo to accurately position throughout its full range. The trick is the length of the max and min pulse values. I believe they are different than your average servo.