Maximum number of servos per processor

Danielpbt

New Member
Is it possible to operate more than 8 servomotors with a single Picaxe processor? (I currently use picaxe 28 X2 and axe 020 board, with blockly for Picaxe software)

Regards
 

hippy

Technical Support
Staff member
A servo pulse is usually between 1ms and 2ms, 1.5ms centred, and with a frame rate of 20ms. So you could in theory control 10 servos sequentially in that time, even more if you are prepared to stretch the frame time a bit at times, which is usually okay.

There are other tricks for running multiple servo pulses in parallel as well as sequentially but they aren't that easy to implement with a PICAXE.

But SERVO commands can only support 8 servos maximum. You would have to go to a hand-crafted timing loop to control more than 8 and that would probably be recommended any way if wanting to control a number of servos and desire jitter free operation.

You could create that timing loop using Blockly but it will likely be much easier to do in PICAXE Basic. That might sound daunting but it's really not that bad and there are plenty of people who can help you with that.
 

inglewoodpete

Senior Member
The question is possibly not so much "how many servos?" but "what else does the PICAXE have to do to control the servos?". For PICAXEs, you may be better off using distributed processing - dedicated servo driver PICAXE slaves with a master PICAXE calling the shots. This may be a little beyond the skill level of your students. I've run up to 5 servos on a slave PICAXE in a coin-operated machine (still bring the money in 10 years later :)).
 

mikeyBoo

Senior Member
hi Daniel,
The cool thing about technology is there’s thousands of solutions for any given problem. If I needed a lot of servos for a project, I would use a PCA9685 (Adafruit has ‘em on a ready-to-go board). This gives you 16 channels at 12-bit resolution & it’s I2C so it works with most processors. It’s a "set it & forget it" device so there’s not much burden on a Picaxe.

I used a PCA9685 on my first Picaxe project to control lighting effects on fishing kayaks. However the PCA9685 also works great for servos. Take a look at this post if you’re interested:
https://picaxeforum.co.uk/threads/pca9685-to-picaxe-18m2.31201/#post-322691

One thing to watch out for when using servos: The stall current on servos can be way more than you might think, so it’s best to use a dedicated power supply just for the servos. The PCA9685 allows offset timing so you don’t bang the power supply so hard when moving several servos in tandem (e.g. robotics stuff).

Good luck with your project & most importantly have fun!
 

Danielpbt

New Member
A servo pulse is usually between 1ms and 2ms, 1.5ms centred, and with a frame rate of 20ms. So you could in theory control 10 servos sequentially in that time, even more if you are prepared to stretch the frame time a bit at times, which is usually okay.

There are other tricks for running multiple servo pulses in parallel as well as sequentially but they aren't that easy to implement with a PICAXE.

But SERVO commands can only support 8 servos maximum. You would have to go to a hand-crafted timing loop to control more than 8 and that would probably be recommended any way if wanting to control a number of servos and desire jitter free operation.

You could create that timing loop using Blockly but it will likely be much easier to do in PICAXE Basic. That might sound daunting but it's really not that bad and there are plenty of people who can help you with that.

Hello again Hippy, first of all thank you very much for helping me again.
I would like to learn how the structures of these time loops could be to control more than 8 servos. Do you know any link where you can go informing me?
I have nothing against learning Basic, but it is true that everything I use with my students is Blockly for Picaxe, and my ultimate goal will be to use that program, as long as it does not become unintelligible to them. In my country, programming with languages (python, ..) only appears in the last years of Bachillerato, but since the project we do is so big, programming in this way is much slower. They learn in a very intuitive way the concepts of programming using Blockly, and so far I am satisfied with the result. Anyway, I always accept suggestions, if you have them.
 

Danielpbt

New Member
Thank you very much for your answer,
Very interesting 21 Channel Servo Controller, I did not know it. Without a doubt it is also an interesting solution to the problem. I think that Blockly for Picaxe does not include so many Servos and that it will have to be programmed using Basic, right? maybe it could be used with Blockly pointing to the same solution that Hippy indicated?
 

Danielpbt

New Member
The question is possibly not so much "how many servos?" but "what else does the PICAXE have to do to control the servos?". For PICAXEs, you may be better off using distributed processing - dedicated servo driver PICAXE slaves with a master PICAXE calling the shots. This may be a little beyond the skill level of your students. I've run up to 5 servos on a slave PICAXE in a coin-operated machine (still bring the money in 10 years later :)).
It's great that your coin machine still works, it sure is a job worth studying :)
I have never used a picaxe as a master and another as a slave. If I have handled two boards from the same Bluetooth. You know a link where you can see how to work that way.
Thank you very much
 

hippy

Technical Support
Staff member
I would like to learn how the structures of these time loops could be to control more than 8 servos. Do you know any link where you can go informing me?
Probably the best explanation is with an example -

https://picaxeforum.co.uk/threads/help-with-servo-and-servopos-commands.29377/#post-303412

The PULSOUT's each generate a servo pulses, the PAUSEUS is used to pad the timing to a fixed(ish) frame rate.

In theory that scheme can be extended as far as the servos will handle an extended frame rate. Most will, are more finnicky about the pulse widths and the PULSOUT's pretty much nail them rick solid.

It actually, might not be too hard to do that in Blockly if you put that in a Procedure.
 

Danielpbt

New Member
hi Daniel,
The cool thing about technology is there’s thousands of solutions for any given problem. If I needed a lot of servos for a project, I would use a PCA9685 (Adafruit has ‘em on a ready-to-go board). This gives you 16 channels at 12-bit resolution & it’s I2C so it works with most processors. It’s a "set it & forget it" device so there’s not much burden on a Picaxe.

I used a PCA9685 on my first Picaxe project to control lighting effects on fishing kayaks. However the PCA9685 also works great for servos. Take a look at this post if you’re interested:
https://picaxeforum.co.uk/threads/pca9685-to-picaxe-18m2.31201/#post-322691

One thing to watch out for when using servos: The stall current on servos can be way more than you might think, so it’s best to use a dedicated power supply just for the servos. The PCA9685 allows offset timing so you don’t bang the power supply so hard when moving several servos in tandem (e.g. robotics stuff).

Good luck with your project & most importantly have fun!
How cheap the PCA9685 plate. I already asked for it. I will undoubtedly have to work hard to understand and do all this well. Thank you very much for helping me, and I will write if when I get all this I have a problem.
Thank you so much for everything
 

depeet

New Member
As inglewoodpete wrote, what else has the processor to perform (inputs, measurements etc... ) When I played around with Arduino I used a dedicated Servo-board that communicated with my arduino through a I2C-bus. It was able to control 16 servo's. This is the one I used and altough I didn't try it with picaxe, I'm sure it will do the task, https://www.adafruit.com/product/815 .
 

hippy

Technical Support
Staff member
It should be possible to use a PICAXE as a servo controller peripheral. X2's would make that easier because they have background receive. Serial bytes sent can for example be 0-31 for which servo to control, anything above that being a servo position for the last servo selected.

One would then only need to update SERVO commands to SERTXD(which, position).

Untested and unoptinised, but something like -
Code:
#Picaxe 20X2

Symbol FRAME_TIME = 2000

Symbol reserveW0  = w0 ; b1:b0
Symbol totalTime  = w1 ; b3:b2
Symbol servoPtr   = b4

Symbol SERVO_Bxx  =  10
Symbol servo0     = b10
Symbol servo1     = b11
Symbol servo2     = b12

HSerSetup B9600_8, %001
Gosub InitServos
Do
  Gosub CheckReceived
  Gosub UpdateServos
Loop

InitServos:
  bPtr = SERVO_Bxx + 31
  Do
    @bPtrDec = 150
  Loop While bPtr >= SERVO_Bxx
  Return

CheckReceived:
  Do While ptr <> hSerPtr
    b0 = @ptrInc
    If b0 <= 31 Then
      servoPtr = b0 + SERVO_Bxx
    Else If servoPtr > 0 Then
      bPtr = servoPtr
      @bPtr = b0
    End If 
  Loop
  Return

#Macro ServoPulse( pin, position )
  w0 = position
  PulsOut pin, w0
  totalTime = totalTime + w0
#EndMacro

UpdateServos:
  totalTime = 0
  ServoPulse( C.0, servo0 ) ; Servo 0
  ServoPulse( C.1, servo1 ) ; Servo 1
  ServoPulse( C.2, servo2 ) ; Servo 2
  w0 = FRAME_TIME Min totalTime - totalTime
  PauseUs w0
  Return
 

Danielpbt

New Member
[QUOTE = "depeet, post: 326281, miembro: 73558"] Como [USER = 29578] inglewoodpete [/ USER] escribió , qué más tiene que hacer el procesador (entradas, medidas, etc.) Cuando jugué con Arduino Usé un Servo-board dedicado que se comunicaba con mi arduino a través de un bus I2C. Fue capaz de controlar 16 servos. Este es el que usé y aunque no lo probé con picaxe, estoy seguro de que hará la tarea, https://www.adafruit.com/product/815 . [/ QUOTE]
I'm going to try it, no doubt because I think it's an interesting topic
I will try this solution again in the forum, I do not think it will come out the first time, :(
Thank you very much
 

Danielpbt

New Member
It should be possible to use a PICAXE as a servo controller peripheral. X2's would make that easier because they have background receive. Serial bytes sent can for example be 0-31 for which servo to control, anything above that being a servo position for the last servo selected.

One would then only need to update SERVO commands to SERTXD(which, position).

Untested and unoptinised, but something like -
Code:
#Picaxe 20X2

Symbol FRAME_TIME = 2000

Symbol reserveW0  = w0 ; b1:b0
Symbol totalTime  = w1 ; b3:b2
Symbol servoPtr   = b4

Symbol SERVO_Bxx  =  10
Symbol servo0     = b10
Symbol servo1     = b11
Symbol servo2     = b12

HSerSetup B9600_8, %001
Gosub InitServos
Do
  Gosub CheckReceived
  Gosub UpdateServos
Loop

InitServos:
  bPtr = SERVO_Bxx + 31
  Do
    @bPtrDec = 150
  Loop While bPtr >= SERVO_Bxx
  Return

CheckReceived:
  Do While ptr <> hSerPtr
    b0 = @ptrInc
    If b0 <= 31 Then
      servoPtr = b0 + SERVO_Bxx
    Else If servoPtr > 0 Then
      bPtr = servoPtr
      @bPtr = b0
    End If
  Loop
  Return

#Macro ServoPulse( pin, position )
  w0 = position
  PulsOut pin, w0
  totalTime = totalTime + w0
#EndMacro

UpdateServos:
  totalTime = 0
  ServoPulse( C.0, servo0 ) ; Servo 0
  ServoPulse( C.1, servo1 ) ; Servo 1
  ServoPulse( C.2, servo2 ) ; Servo 2
  w0 = FRAME_TIME Min totalTime - totalTime
  PauseUs w0
  Return
Tomorrow I will analyze and understand your Basic code, and I will try to pass it to Blockly. If I have any questions, I'll put it in this thread
Thank you very much Hippy
 

depeet

New Member
I forgot to tell that you can connect multiple servo-boards on the I2C-bus. With every extra board you can control 16 extra servo.
 

Danielpbt

New Member
I'm sorry I did not answer you before, I've been tremendously busy
Thanks again for your answer. It's great that there are all those possibilities.
 

Danielpbt

New Member
I get new work options and improvement of my project thanks to all of you who have helped me here.
I am deeply grateful
Regards
 
Top