GRBL 1.1 cprezzi servo Z axis + Laser

Can anyone help me?
I want to use the z axis on servomotors e to focus the laser on GRBL X Y Core software.
Servo and PWM laser use the same D11 pin how can it be bypassed?

My CNC drawing
https://drive.google.com/file/d/1FLdE1gcUif-V3gG8qpacfc4B5ikwyQal/view?usp=sharing

The axis in grbl can only handle stepper drivers (step/dir). What I made is I adapted the spindle PWM output for the use of rc servos which can be used to upper/lower a pen on a pen plotter.

To lower the pen, you just send M3 S1000 (S value depending on $30 setting) and to upper it M3 S0 (or M5).

1 Like

Thank you for your response. Grbl servo works perfectly as a pen plotter … My problem is that from time to time I would like to connect a 3.5W laser module instead of a pen. Every time I want to burn something with a laser, do I have to upload a standard GRBL to arduino?
On the GRBL Servo, the M3S1 command turns on the laser but the M5 command does not turn it off …
$30 = 100
$ 32 = 1

Is there a way to compile GRBL so that you can simultaneously use the servo mechanism and the laser module?
Now I have the D11 PIN in use and I have to upload different GRBL versions every time. I have two working axes X and Y. Maybe it is possible to use Stepstik or step or dir Z axis signal to control the servo mechanism and thus release Pin D11 to which the laser module driver could be connected.
Thank you in advance for any help !
Regards !

Unfortunately you have to change the firmware for switching between servo and laser. GRBL was perfectly optimized for running on the limited Arduino ressources (memory, timers, ports). There isn’t any ressource left for additional features.

Servos need a PWM frequency of about 50-60Hz and only the middle range of PWM values, but a laser needs about 5000 Hz and the full range from 0 to 100%. These changes need to be compiled into the firmware. Adittionaly the servo firmware needs to send the minimum PWM value for servos on M5, instead of just switching the pwm off (which would not do anithing on a servo).

If you don’t need grayscales on the laser, you probably could use the Spindle enble signal to just switch the laser on and off.

I also see a way to use the normal firmware with PWM signal connected to the laser and use the spindle enable signal for an external electronic (i.e. second arduino or ne555) that generates the PWM for the servo, because you only need the two endpoints (UP/DOWN).

2 Likes

An Arduino Beetle would be a nice device to convert between spindle enable/disable to servo up/down.
https://www.dfrobot.com/product-1075.html

Thank you for the advice. I draw more. I use the laser module sporadically. I will exchange software.

All N555 schematics found in the network control the servo by changing the resistance by potentiometer. How to do it on N555 so that the control was voltage 0-5V? (Spindle signal ON OFF)

I can’t program arduino … I need to load the arduino nano so that the input is a 0 or 5v signal. The servo should react accordingly
0V- 0 degrees
5V- 30 degrees

Can anyone write a program for me?

How to change this code so that the PIN13 spindle ON-OFF signal starts the servo?

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-button-servo-motor
 */

#include <Servo.h>

// constants won't change
const int BUTTON_PIN = 7; // Arduino pin connected to button's pin
const int SERVO_PIN  = 9; // Arduino pin connected to servo motor's pin

Servo servo; // create servo object to control a servo

// variables will change:
int angle = 0;          // the current angle of servo motor
int lastButtonState;    // the previous state of button
int currentButtonState; // the current state of button

void setup() {
  Serial.begin(9600);                // initialize serial
  pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
  servo.attach(SERVO_PIN);           // attaches the servo on pin 9 to the servo object

  servo.write(angle);
  currentButtonState = digitalRead(BUTTON_PIN);
}

void loop() {
  lastButtonState    = currentButtonState;      // save the last state
  currentButtonState = digitalRead(BUTTON_PIN); // read new state

  if(lastButtonState == HIGH && currentButtonState == LOW) {
    Serial.println("The button is pressed");

    // change angle of servo motor
    if(angle == 0)
      angle = 90;
    else
    if(angle == 90)
      angle = 0;

    // control servo motor arccoding to the angle
    servo.write(angle);
  }
}

You can make a servo toggle like this:

/*
 * Created by C. Prezzi (COMsulting GmbH)
 *
 * Servo Toggle: 
 * - When input pin is 0, the servo is set to ANGLE_OFF
 * - When input pin is 1, the servo is set to ANGLE_ON
 */

#include <Servo.h>

// constants
const int BUTTON_PIN = 7; // Arduino pin connected to button's pin
const int SERVO_PIN  = 9; // Arduino pin connected to servo motor's pin
const int ANGLE_OFF  = 0; // Angle for the off position
const int ANGLE_ON  = 30; // Angle for the on position

Servo servo; // create servo object to control a servo

// variables:
bool lastButtonState;    // the previous state of button
bool currentButtonState; // the previous state of button

void setup() {
  Serial.begin(9600);                // initialize serial
  pinMode(BUTTON_PIN, INPUT);        // set button pin to input
  servo.attach(SERVO_PIN);           // attaches the servo on defined pin to the servo object

  lastButtonState = 0;               // set initial state
  servo.write(ANGLE_OFF);            // initializes the servo at off position
}

void loop() {
  currentButtonState = digitalRead(BUTTON_PIN); // read new state

  if(lastButtonState != currentButtonState) {
    Serial.print("Input state has changed to ");
    Serial.println(currentButtonState);

    // change angle of servo motor
    if(currentButtonState == 1)
      servo.write(ANGLE_ON);
    else
      servo.write(ANGLE_OFF);

    lastButtonState = currentButtonState;
  }
  delay(100); // pause the loop for 100ms
}

You need to connect the GNDs of both arduinos and spindle enable pin of GRBL Arduino to Pin 7 of second Arduino.

Thank you for sharing the code.
IT WORKS!!! the servo position changes on M3 and M4. Cprezzi you are a GREAT MAN.
I wish you much health in these hard times!
I PUT VIRTUAL BEER!

You are welcome. I’m happy I could help.