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.
Thank you very much for your answer,
It's great that your coin machine still works, it sure is a job worth studyingThe 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 ).
Probably the best explanation is with an example -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?
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.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!
#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 threadIt 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