Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:06 30 Jul 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Problem with SERVO

Author Message
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 1146
Posted: 11:44am 28 Jul 2026
Copy link to clipboard 
Print this post

Hello,

can someone please help me with the servo command? Unfortunately, I can't find any examples, and I'm not sure how to use the command correctly.
I have a model-building micro servo (S18JST) connected to GP0.
The servo should be able to move through an angle of about 170°.

I use PicoMiteRP2040V6.03.00.uf2

Why do I get a syntax error when I enter values greater than 120 and less than -20?
But my servo still only moves a little more than 90°.
I'd probably need values even lower than -20 to cover the entire range. At values greater than 110, the servo stops moving - that seems to be the upper limit.

Here is my test program:
Option explicit

SetPin 1, PWM0A

Dim Zaehler Integer

Do While 1
Links
Rechts
Loop

Sub Links
For Zaehler=-20 To 110 Step 5
 Servo 0, Zaehler
 Pause 50
Next Zaehler
End Sub

Sub Rechts
For Zaehler=110 To -20 Step -5
 Servo 0, Zaehler
 Pause 50
Next Zaehler
End Sub


Would it be better to use the PWM command?

Frank

P.S.: I use GFXterm Linux-64, and [?7h] always appears when I'm outside the editor?!?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11678
Posted: 11:54am 28 Jul 2026
Copy link to clipboard 
Print this post

  Quote  SERVO channel [positionA]
[,positionB]
Control a standard servo.
‘positionA’ and ‘positionB’ can be between -20 and 120 and will generate a
50Hz signal between 800uSec and 2.2mSec
As with the PWM command the pins must be set up with SETPIN n,PWM
To use just channel B use the syntax: SERVO channel,,position.
Note the two commas to indicate that channel A is not being set.
Refer to the pinout to give the channel and sub-channel (A or B) for each pin.
Examples:
90° servo: 0 = 0° and 90 = 90°
180° servo: 0 = 0° and 90 = 180°
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11678
Posted: 12:16pm 28 Jul 2026
Copy link to clipboard 
Print this post

Note you can test it is working by connecting the servo output pin to a count pin and checking the frequency and duty cycle (pulsin)
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 1146
Posted: 12:23pm 28 Jul 2026
Copy link to clipboard 
Print this post

Okay, I missed the part about -20 and 120. Unfortunately, that doesn't cover the entire range the servo is capable of. I'll try the PWM command.

Frank
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11678
Posted: 01:36pm 28 Jul 2026
Copy link to clipboard 
Print this post

Frank: something is not right. I'm not aware of any servos that won't run their full range when given 1-2mSec. That is the spec for a servo. Even allowing the +/- 20-% that I do isn't really correct.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 10005
Posted: 10:53pm 28 Jul 2026
Copy link to clipboard 
Print this post

Cheap nasty servo units perhaps?
Where did you get your ones from, Frank?

AliExpress and eBay are flooded with super-cheap servo units, and many of the REALLY cheap ones(one or two bucks or so each) are just junk.

Slightly more expensive ones would probably work fine, if you happen to be using some of the  really cheap ones.

I've used servos before, and I also never had any issue with getting them to do full travel using the standard SERVO command.

But you do have to have a servo that is at least minimum spec compliant.
Smoke makes things work. When the smoke gets out, it stops!
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3329
Posted: 11:19pm 28 Jul 2026
Copy link to clipboard 
Print this post

Looked up the specs of "micro servo (S18JST)" and they indicate it is a 60° unit.
  Quote  Size: 13.5 x 16 x 6 mm, Voltage: 3.5 - 6 V, Speed: 0.15 sec / 60 degrees, Weight: 1.8 grams
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 1146
Posted: 05:42am 29 Jul 2026
Copy link to clipboard 
Print this post

@Grogster:

It is a micro-servo from a well-known distributor in Germany.
It measures just 13.5 x 16 x 6 mm.

@phil99:

Good point! If you can read, you have a clear advantage!  


Even so, it covers a range of about 135° when I control it using PWM. Unfortunately, that doesn't work with the SERVO command...

Frank
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 10005
Posted: 06:23am 29 Jul 2026
Copy link to clipboard 
Print this post

  Frank N. Furter said  @Grogster:

It is a micro-servo from a well-known distributor in Germany.
It measures just 13.5 x 16 x 6 mm.


OK.
Smoke makes things work. When the smoke gets out, it stops!
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6004
Posted: 06:23am 29 Jul 2026
Copy link to clipboard 
Print this post

1/ the servo travel of 60 degrees in above servo is the standard way uou specify the speed (60 degrees in xx ms). Same as for cars 0-60mph in 9 seconds. Does not say the car cant go over 60 mph.

2/ in my rc days I have come accross so many cheap and expensive servo's, and they all do +/-60 degrees from mid position. With luck +/- 90. Unless it is a cont.rotation servo.

3/ the 0 to 90 spec in the servo command does not match my thinking of +/-. So I use the PWM command to drive servo's.

4/ the limits 800us and 2.2ms are correct. You hardly get below 700us and above 2.4ms without limit.

Volhout
P.s. high end servo s are digital interface. Not pwm anymore. And they are configurable (pid).
Edited 2026-07-29 17:22 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8986
Posted: 08:09am 29 Jul 2026
Copy link to clipboard 
Print this post

First, I have no experience of servos, so I have no preconceptions about them. I've come to look at the SERVO command and the examples and, to be quite honest, I can't figure it out at all. I assume that Position A and Position B are the start and end angles required, in which case you can't set a servo for 0-180 degrees or -90 to +90. You are limited to -20 to +120 degrees, surely? The examples aren't clear for a newcomer at all.

Could someone enlighten me please, and maybe suggest some more meaningful examples for the manual?
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3329
Posted: 08:31am 29 Jul 2026
Copy link to clipboard 
Print this post

The way I read it the SERVO command just outputs pulses of 0.8mS to 2.2 mS at a 50Hz rate. What angle that represents is up to each servo manufacturer.

1 to 2mS for full travel appears to be the standard but apparently some manufacturers don't stick to it.

Maybe if the manual read "nominal percentage of full travel" it might be more obvious.

The above has been edited.
Edited 2026-07-29 18:43 by phil99
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8986
Posted: 11:55am 29 Jul 2026
Copy link to clipboard 
Print this post

Ah, thanks Phil. That makes a lot more sense to me now. So, SERVO can operate from -21% to 120% of what a "standard" servo would expect over its full end to end travel, giving room to maneuver a bit. How does the <position> value work? I assume that 0 woll be at Position 1, but is it in degrees or % of rotation to Position 2?
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11678
Posted: 11:58am 29 Jul 2026
Copy link to clipboard 
Print this post

The number is the percentage of "normal" 1-2msec
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6004
Posted: 01:10pm 29 Jul 2026
Copy link to clipboard 
Print this post

If you throttle a motor, then 0 and 100% make sense. When you do elevation, pitch,  roll eveything focusses around mid position, which is 50 % in the servo command.

So there is no good or bad, one way or the other you have to do some math.

I personally use PWM since the math is not more complex, and it transfers nicely to other hardware.

Volhout
P.s. don't forget there is always center trim. The arm can be mounted in few discrete angles to the servo.
Edited 2026-07-29 23:13 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6004
Posted: 01:25pm 29 Jul 2026
Copy link to clipboard 
Print this post

Also: software limits at 0.8 and 2.2ms are VERY smart. When you run a servo into its mechanical limits, it will eithe burn out, or it will drain your battery in minutes.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8986
Posted: 02:14pm 29 Jul 2026
Copy link to clipboard 
Print this post

Thanks everyone. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026