GRBL communication

Hi, during the past months i built a CNC router with an Arduino Nano and GRBL.
I decided to make a jogger to easily move the router without having to get mad with CAD drawings for simple things.
The jogger use another Arduino which communicates with GRBL trough the Serial port. (RX to TX with a 1Kohms resistor, and vice-versa).
The only problem i got is that the communication between the two Arduinos doesn’t seem to work, i tried to run a simple sketch that just send to GRBL a “?” command and get the response printed to a LCD, but nothing appears on the LCD. The strange thing is that it works if i send the message with the serial monitor on the pc.
I’ve never really understood some things in the Serial objects, so maybe the problem lies within the use of Serial.write.
Any help would be greatly appreciated. :smiley:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {
  lcd.begin(16, 2);
  lcd.clear();
  Serial.begin(115200);
}

void loop() {
  Serial.write("?");
  Serial.write("\n");
  lcd.setCursor(0, 0);
  lcd.print(Serial.readString());
  Serial.flush();
  delay(1000);
  lcd.clear();
}

Do you know what Serial.flush() does? If not, why are you calling it? If you (think you) do, why are you calling it AFTER expecting to have gotten a response?

What code is running on the other Arduino?

I misunderstood the reference page for Serial.flush(), I thought it might be used to empty the Serial RX buffer, but this was before 1.0 version of arduino. Well, however I don't think it's going to change something. On the other Arduino the software is GRBL v0.9 (https://github.com/grbl/grbl)

You don't have any code to prove that the LCD works.

Add this line in setup()

lcd.print("Program Starting");

...R

LCD works fine, i know because with the main jogger sketch it works. What i'm basically trying to do is writing a GRBL interface following these guidelines

Your program code sends a newline character. Maybe you should be sending a carriage-return or both?

...R

GRBL needs:

Make sure you change the "No line ending" drop-down menu to "Carriage return". If you are using any other serial port program, you must do the same.

Quote from here.

Mars96: Hi, during the past months i built a CNC router with an Arduino Nano and GRBL. I decided to make a jogger...The jogger use another Arduino which communicates with GRBL trough the Serial port.

Forget worrying about your code right now,

If I understand correctly:

1) you have one GRBL flashed Arduino connected via USB to something with Serial Monitor, perhaps a PC 2) you have another Arduino connected to the GRBL Arduino via the hardware serial

I don't think you can do this, although I may be wrong... and surely others can answer definitively.

I believe this is like trying to have a two party conversation between three parties. Or as I see it, GRBL is trying to maintain a conversation with a PC and another Arduino at the exact same time. I would expect this not possible, or at least not without errors. The PC USB and the additional Arduino are ultimately tied to the same RX/TX pins on the GRBL Arduino

Mars96: I decided to make a jogger to easily move the router without having to get mad with CAD drawings for simple things.

And this is the most puzzling part... Why don't you just use "Universal Gcode Sender" or one of the other available softwares to communicate with the GRBL Arduino, as they have provisions for 'jogging' to move the router without getting all mad with CAD and what not.

If you have an Android phone, you could even use the app I put on the play store, I do all the time:

Android app for 'jogging' without angry CAD drawings >:(

for this, you'll just need to ditch the PC and extra Arduino, and pick up one of the inexpensive HC-06 Bluetooth modules:HC-06 Bluetooth Module :) :)

billcat: Forget worrying about your code right now,

If I understand correctly:

1) you have one GRBL flashed Arduino connected via USB to something with Serial Monitor, perhaps a PC 2) you have another Arduino connected to the GRBL Arduino via the hardware serial

I don't think you can do this, although I may be wrong... and surely others can answer definitively.

I believe this is like trying to have a two party conversation between three parties. Or as I see it, GRBL is trying to maintain a conversation with a PC and another Arduino at the exact same time. I would expect this not possible, or at least not without errors. The PC USB and the additional Arduino are ultimately tied to the same RX/TX pins on the GRBL Arduino

And this is the most puzzling part... Why don't you just use "Universal Gcode Sender" or one of the other available softwares to communicate with the GRBL Arduino, as they have provisions for 'jogging' to move the router without getting all mad with CAD and what not.

If you have an Android phone, you could even use the app I put on the play store, I do all the time:

Android app for 'jogging' without angry CAD drawings >:(

for this, you'll just need to ditch the PC and extra Arduino, and pick up one of the inexpensive HC-06 Bluetooth modules:HC-06 Bluetooth Module :) :)

No, the connection is either from GRBL to pc OR from GRBL to the Arduino Jogger.. However, i meant that i want to use the router without having the MacBook laying around, and i don't have an Android phone :P

Robin2: Your program code sends a newline character. Maybe you should be sending a carriage-return or both?

...R

rpt007: GRBL needs:

Quote from here.

What's the code for the carriage-return? I've never understood the difference between new line, carriage-return and other serial things. I tried with \r instead of \n but nothing changes. Also i forgot to mention that the connection works, as I see the TX and RX blinking on the two Arduinos. Thank you all :D

I wonder if this

Serial.write("\n")

should use single quotes as you only want to send a single character. Likewise for '\r'

And why not use Serial.print() ?

...R

Robin2: I wonder if this

Serial.write("\n")

should use single quotes as you only want to send a single character. Likewise for '\r'

And why not use Serial.print() ?

...R

I tried all the 4 different combinations (print and ', print and ", write and ', write and ") but none of it works. Maybe the problem lies within the method i'm using to receive data from GRBL. What got me thinking about it is the fact that GRBL sends a start up message everytime it boots, but it doesn't appear on the LCD.

Mars96: Maybe the problem lies within the method i'm using to receive data from GRBL. What got me thinking about it is the fact that GRBL sends a start up message everytime it boots, but it doesn't appear on the LCD.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

How are you causing GRBL to boot?

...R

Robin2:
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

How are you causing GRBL to boot?

…R

Thanks, i’m going to read it… GRBL is booted up by a switch that cuts the 5 volts line between the two Arduino, since one of them is powering the other.

Mars96: No, the connection is either from GRBL to pc OR from GRBL to the Arduino Jogger.. However, i meant that i want to use the router without having the MacBook laying around, and i don't have an Android phone :P

I see, sorry I misundetstood. This may be silly...did you try " both newline and cr " I think that's what is required

billcat: I see, sorry I misundetstood. This may be silly...did you try " both newline and cr " I think that's what is required

Yes, i tried it but still nothing. However i found a Python code from the bCNC project on GitHub, the source is Sender.py on the main repository (https://github.com/vlachoudis/bCNC): At row 469 there's this code:

def sendGCode(self, cmd):
 if self.serial and not self.running:
 self.queue.put(cmd)

and from what I can comprehend every time a function need to send chunks of g-code it refers to this function, what i can't understand is the self.queue.put thing.. At row 494 i found the serial.write function but i don't have enough Python experience to tell if it's different from the arduino serial.write.

def softReset(self):
 if self.serial:
 # if self.controller == Utils.GRBL:
 self.serial.write(b"\030")
 # elif self.controller == Utils.SMOOTHIE:
 # self.serial.write(b"reset\n")
 self.stopProbe()
 self._alarm = False