Welcome! Log In Create A New Profile

Advanced

Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4

Posted by jezZu 
Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4
September 27, 2021 10:42AM
Good afternoon, im building a system with marlin firmware and i want to connect more than 4 servos.

The board i have is the MKS GEN L V1.0 wich has RAMPS 1.4 built in, this one has 4 connectors for servo and they work properly.

The question is that the 4 extra servos that i want to connect, my idea was to take other digital pins from the auxiliary sectors that mks gen has and rename them to servos.

I rename them through the pins files and configuration.h file i put max 8 servos.

I had to remove security from "sanitycheck.h" because if not, it wouldnt me compile it says this board doesnt support that number of servos but i had other digital pins built in pcb. But the case that when i connect the fifth servo through pronterface it let me send the command M280 P5 S90 but the servo does absolutely nothing.

Some help?

Thanks!

Edited 1 time(s). Last edit at 09/28/2021 02:18AM by jezZu.
Re: Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4
September 27, 2021 07:30PM
PP5 is wrong, its just P5

servos requires a PWM capable pins ie pins 0-13,44-46 but many of these pins already have a alternative function, eg 0,1 are serial port 0 TX and RX so cannot be used.
Also PWM uses up timers, but if the timer is already allocated to some other function, ie marlin, the PWM pin will not work.

Edited 2 time(s). Last edit at 09/27/2021 08:48PM by Dust.
Re: Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4
September 28, 2021 02:10AM
Oh yeah sry i wrote it here incorrectly i send the correct command.
Should i search for other free PWM pins? In mks gen l pinout servo pines are Digital, 5V, GND so..

I tried to turn on a led with other Digital Aux pin with M42 command and it works great.

The other thing i tried is changing servo default pin "11" to D49 in aux and it worked, but not fot the fifth servo.

Edited 2 time(s). Last edit at 09/28/2021 02:22AM by jezZu.
Re: Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4
September 28, 2021 04:53AM
Looking at marlin, there is no provision for more than 4 servos

You need to edit Marlin/src/HAL/AVR/HAL.cpp and extend the following

void HAL_init() {
  // Init Servo Pins
  #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
  #if HAS_SERVO_0
    INIT_SERVO(0);
  #endif
  #if HAS_SERVO_1
    INIT_SERVO(1);
  #endif
  #if HAS_SERVO_2
    INIT_SERVO(2);
  #endif
  #if HAS_SERVO_3
    INIT_SERVO(3);
  #endif
}

And extend Marlin/src/inc/Conditionals_post.h
// Servos
#if PIN_EXISTS(SERVO0) && NUM_SERVOS > 0
  #define HAS_SERVO_0 1
#endif
#if PIN_EXISTS(SERVO1) && NUM_SERVOS > 1
  #define HAS_SERVO_1 1
#endif
#if PIN_EXISTS(SERVO2) && NUM_SERVOS > 2
  #define HAS_SERVO_2 1
#endif
#if PIN_EXISTS(SERVO3) && NUM_SERVOS > 3
  #define HAS_SERVO_3 1
#endif

And Marlin/src/module/servo.cpp
void servo_init() {
  #if NUM_SERVOS >= 1 && HAS_SERVO_0
    servo[0].attach(SERVO0_PIN);
    DETACH_SERVO(0); // Just set up the pin. We don't have a position yet. Don't move to a random position.
  #endif
  #if NUM_SERVOS >= 2 && HAS_SERVO_1
    servo[1].attach(SERVO1_PIN);
    DETACH_SERVO(1);
  #endif
  #if NUM_SERVOS >= 3 && HAS_SERVO_2
    servo[2].attach(SERVO2_PIN);
    DETACH_SERVO(2);
  #endif
  #if NUM_SERVOS >= 4 && HAS_SERVO_3
    servo[3].attach(SERVO3_PIN);
    DETACH_SERVO(3);
  #endif
}
Re: Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4
September 28, 2021 10:36AM
Woaa! That worked perfectly!! Where did u find the information to know wich files need to change?

Also many thanks for the help!
Re: Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4
September 28, 2021 09:36PM
I didn't find it, I looked at the code and worked out what needed to be done

Once I found the HAS_SERVO_{0|1|2|3|} define I searched for all files that used that define to point the way.

Edited 1 time(s). Last edit at 09/28/2021 09:42PM by Dust.
Re: Add more than 4 servos MKS GEN L v1.0 RAMPS 1.4
September 29, 2021 05:23AM
Got it!!

Many thanks for the help!
Sorry, only registered users may post in this forum.

Click here to login