Sending G-Code from arduino to 3018 CNC control board

Hi All,
I'm working on a project where I would like to send G-Code from an Arduino Mega 2560 to the control board of a 3018 CNC running GRBL 1.1. This board has an 8 pin connector to an offline controller and I'm attempting to send G-code via these pins.
I have found the rx and tx pins on the control board and wired up the Arduino to those pins using SoftwareSerial. Once all is powered up , I get a message on the serial monitor saying "Grbl 1.1f ['$' for help]", so assume the rx bit is woking fine, however I can't seem to get anything I send to work, I've tried sending $, no response , $\n $\r $\n\r also some simple G-code G00 X1 Y1 Z0, nothing. (no "ok", no movment, no error message)
As a sanity check I connected to the grbl board via usb using PuTTy and was able to run typed commands. If I connect the offline controller to the 8 pin connector , it works fine.
I'm confused. The machine works using usb , offine controller, I get output when connected to the rx/tx pins, but can't make it execute commands, what am I missing here?

Control board and rx/tx pins I'm trying to use:

image

Full pinout of board:

Code used to connect:

#include<SoftwareSerial.h>

int txPin = 47;//this is the output pin of arduino and goes to rx pin of cnc board
int rxPin = 51;// this is the input pin of arduino and goes tp tx pin of cnc board


SoftwareSerial CNCSerial(rxPin, txPin);

String CNCOutput ="";
String SerialOutput = "";
char CNCCharData = '0';
char serialData = '0';

void setup() {
  
  pinMode(txPin,OUTPUT);
  pinMode(rxPin,INPUT);
  
  CNCSerial.begin(115200);//Start CNC serial 
  Serial.begin(9600);  
}

void loop() {  
  
  while(CNCSerial.available()>0){
    char CNCCharData = (char) CNCSerial.read();
       CNCOutput+= CNCCharData;
    delay(10);
    }    
  
    while(Serial.available()>0){
    char serialData = (char) Serial.read();
    SerialOutput += serialData;    
    delay(10);    
    }

    if(SerialOutput.length()>0){
      Serial.print(">");
      Serial.print(SerialOutput);
      CNCSerial.print(SerialOutput);
      //CNCSerial.print('\n');

      SerialOutput="";
    }
    
    if(CNCOutput.length()!=0)  {
      Serial.print("Data from CNC :"); 
      Serial.print(CNCOutput); 
      Serial.print("\n");
      CNCOutput = "";
    }
  }

Pin 47 connected to rx pin on CNC control board while pin 51 connected to tx pin on CNC control board.

Software serial is never going to work at 115200.
Find a board with multiple hardware UARTs.

he already got it- Mega2560 have 4 UARTs


@nss1024 use one of marked ports

Thank you , I have amended the code and rewired the Arduino to use Rx/Tx 1 of the mega (pins 18 and 19). I still get the output from the grbl controller board "Grbl 1.1f ['$' for help]" and my input is echoed (for my serial input of $ I get a Serial1 output of $) , but no further reply .

Do you have an extra TTL-to-USB-converter that you could use to listen to the serial communication if you have connected the device which is able to communicate with the 3018 CNC-controller?

Or do you have a 24 MHz 8 channel logic analyser that could record the bitbanging on Rx/Tx ?
With the software SiRok-Pulseview you can analyse the recorded LOW/HIGHs to see each and every single byte that is sended / received.

One difference might be to send only carriagle return
or new line and carriage return or
only new line
or any other start / end-marking character

can putty be configured to print all characters in hexadecimal?
This This will eventually reveal whether non-printable characters are being sent

best regards Stefan

show

See below:

#include<SoftwareSerial.h>

String CNCOutput ="";
String SerialOutput = "";
char CNCCharData = '0';
char serialData = '0';

void setup() {  

  Serial1.begin(115200);
  Serial.begin(9600);  
}

void loop() {  
  
  while(Serial1.available()>0){
    char CNCCharData = (char) Serial1.read();
       CNCOutput+= CNCCharData;
    delay(10);
    }    
  
    while(Serial.available()>0){
    char serialData = (char) Serial.read();
    SerialOutput += serialData;    
    delay(10);    
    }

    if(SerialOutput.length()>0){
      Serial.print(">");
      Serial.print(SerialOutput);
      Serial1.print(SerialOutput);
      //Serial1.print('\n');
      delay(500);
      SerialOutput="";
    }
    
    if(CNCOutput.length()!=0)  {
      Serial.print("Data from CNC :"); 
      Serial.print(CNCOutput); 
      Serial.print("\n");
      CNCOutput = "";
    }
  }

Result as:
Data from CNC :

Grbl 1.1f ['$' for help] <-Printed on connection (rx/tx connected, cnc on)

$Data from CNC :blush: <- Typed $ into serial monitor, and see $ coming back

$\nData from CNC :$\n

$\rData from CNC :$\r

$/nData from CNC :$/n

$/rData from CNC :$/r

Hi,
Thank you for the reply, I don't have such equipment unfortunately.
Don't think PuTTy can print hex from communications, but I did try to capture USB data using Wireshark (USB Pcap) , but couldn't make much of it, granted I didn't spend a lot of time on it.

#define CNC_UART Serial1
#define PC_USB Serial

void setup() {
  CNC_UART.begin(115200);
  PC_USB.begin(115200);
}

void loop() {

  while (CNC_UART.available() > 0) {
    char CNCCharData = (char) CNC_UART.read();
    PC_USB.print(CNCCharData);
  }

  while (PC_USB.available() > 0) {
    char serialData = (char) PC_USB.read();
    CNC_UART.print(serialData);
  }
}

Perhaps the page on interfacing with grbl will help.

At 115200 bps each character takes 86 microseconds to receive, you add 10 milliseconds of delay.
In that time, more than 100 characters can be received, many of which will be lost due to reception buffer overflow.

At 9600 bps each character takes just over 1 millisecond to receive, you add 10 milliseconds of delay.
In that time 9 characters can be received and several can be lost quickly.

Why do you put those delays?
And what is the reason of having one side of the communication more than 10 times slower than the other (9600 vs 115200)?

Hi, Thank you for the amended code, appreciate your time and help. I tried running it and got the same results as before unfortunately.
The annoying thing is that I can control the darn thing every other way (using usb via G-code sender software and by connecting with PuTTy so no G-code sender, just manually typed commands, also the offline controller that came with the machine works fine using the same pins I'm trying to use) ... Also, I've seen that others have done a similar project successfully using a nano. See link https://www.instructables.com/GRBL-Offline-Controller/ . I don't need an lcd or keypad input as is shown in the link, ultimately, I would send G-code to the Arduino via Bluetooth, that I can do currently, and forward the instructions to the CNC. I thought I would develop the CNC communications part separately before introducing the BT into the mix to keep it simpler, but as it turns out I'm having trouble sending typed instructions to the CNC .....

Thank you for the reply, I had a read on GRBL interfacing on their github page. I can send grbl commands to the machine if I connect to it using PuTTy and it reacts as it's supposed to.

Thank you for the reply, there is no reason for the delays other than me getting desperate and thinking they would help. Thank you for the information though, it is helpful.

it can't be
anyway, you should spare Mega and using USB-UART converter,

Hi, thank you for the help. I'll try and figure something out.
See image below with your code. Again, I get a response form the CNC but entering "$" on its own or by adding NL/CR or NL+CR, I don't get anything back. I'm probably missing something simple here, not sure what though.

This picture delivers not much information.

You are using an arduino-mega 2560
You use a laptop
you use provisorical wiring.
That's all.

This does not help to analyse or narrow down the problem.

Do you at least understand what
listening in parallel
to your laptop running putty directly connected to the 3018-control means?

You might not have the equipment for parallel listening but do you understand what it means?

Do you have another microcontroller? Yes / No
Do you have a 24 MHz 8 channel logic analyser? Yes/ No
Do you have an extra TTL-to-USB-COM-port adapter? Yes / No

For further narrowing down the problem you will need to analyse what the differencies between putty sending the commands
and
your arduino Mega is sending the commands
and this requires some kind of equipment like asked above

Another option might be to send a grbl-command using putty
and looking at the answer that comes back.
and then
connect your arduino-mega directly with putty and then to use putty to send the exact same character-sequence that putty received from the 3018-control

Just to explain the principle:

  1. step putty send request to 3018-control
    putty ---->--->--->----3018-control

putty receives an answer

putty ----<----<---<---3018-control-ANSWER

example:
3018-control-ANSWER might be "ABC987 "

step 2.
Now connect putty with your arduino-mega
putty -->---->----ABC987 --->-----Arduino-mega
and then print the received characters to the serial monitor

best regards Stefan

Hi StefanL38, thank you for the reply, lots of questions and info in there, I'll try and answer all:
The picture - only meant to show that I'm trying to use the code provided by kolaha and the response, nothing more, otherwise I would have provided closeups, but in summary, yest those are the things I'm using.

Do I understand what parallel listening is, well vaguely, I only got into this a few months ago.

Equipment:
Do I have another microcontroller? -> No
Do I have a logic analyser? -> No
Do I have a TTL to USB adapter? -> No

This is why I tried to use Wireshark with USBPcap, it can listen into USB communication.

In terms of analysing the problem, I understand the principle, and that is why I have used putty to send commands. Unlike a G-Code sender software which may add padding to the typed commands (like NL or CR), putty will only send what I type, so I know exactly what I'm sending.
I do the same with the Arduino, enter characters and wait for the reply.
The results thus far, both the Arduino and putty get the standard greeting from grbl "Grbl 1.1f ['$' for help]", however, while I am able to send commands via putty and they are executed, this is not the case with the Arduino. I type the command into serial monitor, hit enter and nothing, well actually I get an echo, but no reaction from the machine.
I will keep at it , I'm sure it's some oddball of a thing. :slight_smile:

You have to connect GND, too, otherwise this will never work. And it could be that your GRBL board 5V line comes from USB, not from the powersupply, so you might want to check that, too.

You have to write code that the arduino-code will send the data over a different serial interface that is directly connected to your 3018-controller.

Typing into the serial monitor means that your arduino is receiving the serial data on IO-pin 0.

Typing data into the serial monitor does NOT send data to your 3018-controller.

The only way this would happen would be if you forward the from serial-monitor-received data to the second serial interface.

Arduino-IDE-Serial-monitor-->--->--Arduino-IO-pin-0-->----Arduino-code-Serial.read()--into-variable-->---Serial1.print(variable)--->----Arduino-IO-pin-18-(Tx)-->>>---3018-controller

With coding this forwarding you add a new possability that things can go wrong.
This is the reason why I recommended to

This way you check what does your arduino really receive.
After having checked this receiving works.

Write a small testcode that sends the hardcoded request-string to the 3018-control

Directly print a character-sequence that is hardcoded into your arduino-code.

Doing it this way you minimise possible bugs

best regards Stefan