Can one Arduino resent serial com to another Arduino?

 

Can one Arduino receive serial communication via USB and then resent it to another Arduino via tx rx pins?


 

Sorry - I did not research

Sorry - I did not research before asking. I found the answer.

Not by tx rx pins but other pins can be assigned using SoftwareSerial.

Yes.

Regular serial going in to your Arduino (via usb) and soft serial out.

You can also buy a Mega and I think you have 3 or 4 “hardwire” serials.

I can’t make my Arduinos

I can’t make my Arduinos talk to each other. This is the parts of my code, which should do the job. What I sent from my PC is shown at the LCD. And the initial “Ready …” arrives at my PC. So the loop is runing OK.

#include <SoftwareSerial.h>
#define rxPin 7
#define txPin 8

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void serialRepeater(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(“Serial repeater”);
  Serial.begin(9600);
  Serial.println(“Ready …”);
  while (!Serial) 
  mySerial.begin(9600);
  mySerial.println("$");
  while (mode==3) {    
    if (mySerial.available()>0){
      serData=mySerial.read();
      Serial.write(serData);
      lcd.print(serData);
    }
    if (Serial.available()) {
      serData=Serial.read();
      mySerial.write(serData);
      lcd.print(serData);
      Serial.write(serData);
    }
    if (Button(btnReverse)) {
      while (Button(btnReverse)) {}
      mode=0;
    }
  }  
  lcd.clear();
  mainmenu();
}
 
void loop() {
   mode=3; 
   serialRepeater();
}

Here’s pin 7 (rx) and 8 (tx) on my control arduino

rxtx1.png

And tx and rx pin on my grbl arduino:

rxtx2.png

And the wiring in between:

rxtx3.png

But nothing seems to get thrue.

Forgot to mention, that I

Forgot to mention, that I set pinmode in setup:

 

void setup() {

  pinMode(rxPin, INPUT);

  pinMode(txPin, OUTPUT);

 }

Lets assume the hardware is correct

Lets assume the hardware is correct and take a quick sec to see what we are sending…   …What are we sending?

The first thing I would check is to see if anything is getting through. When something is sent, see if the RX LED on the GRBL Arduino blinks. If it does, it means something is coming through. This does not mean it is being dealt with when it gets there though.

First off, I have no idea as to the GRBL serial protocol. I have used “terminal style” g-code feeders and they all seem to be fairly straight-forward: “X100 Y100” as a string, and maybe a CR or LF at the end. This is only what I assume, mind you --I have no idea. GRBL may need some kinda qualifier at the start and quite possibly a checksum at the end. You could be sending the “X10” (but not the CR) and the GRBL would never do anything (appearing as if your serial info is not coming through).

Personally, I would recode the GRBL arduino with the following code:

Setup serial stuff
if (serial is available)
 var= read the serial
if  (var == ‘A’)
{
   blink a led a few times

 

Then I would program your other arduino to send out an “A” every 5 seconds, at the same time blinking its own LED. Once you get your LED’s on both boards blinking together, you would then know they are communicating properly. You can zap your GRBL back in and this time focus on how each line of g-code is sent, knowing the nuts-and-bolts of your serial stuff work.

Got a hole thru

Thank you for your reply Chris. I really appreciate it. I have been trying everything.

I peeled the code down to an absolute minimum. And finally I got a hole through.

The code now looks like this:

void serialRepeater(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(“Serial repeater”);
  Serial.begin(9600);
  Serial.println(“Ready …”);
  mySerial.begin(9600);
  mySerial.listen();
  while (mode==3) {    
    while (mySerial.available()){
      Serial.write(mySerial.read());
    }
    if (Serial.available()>0) {
      mySerial.write(Serial.read());
    }
    if (Button(btnReverse)) {
      while (Button(btnReverse)) {}
      mode=0;
    }
  }  
  lcd.clear();
  mainmenu();
}

Now I can send the $ command and get at result back. But the longer the result is the more erroneous it become.

This is an example:

 

$0 = 200.000 (steps/mm x)
$1 = 200.000 (steps/mm y)
$2 = 200.000 (steps/mm z)
$3 = 50 (microseconds step pulse)
$4 = 250.000 (mm/min default feed rate)
$ = 5000 (m/indeaul sekrae)
$ =0.00(m/ac sgmnt
7  20 ste prtiner msk bnay  100100
8  1.00 aceleatoninmmse^2
9  005 (crnrig untin dvitin n m)
‘x=vlu’ o etpaamte o jst’$'todup uren sttigs
o

Should look more like https://github.com/grbl/grbl/wiki/Configuring-Grbl 

 

 

 

@Mr Chris and @Mr Allan :

@Mr Chris and @Mr Allan : i’ve cases with my arduino (grbl) how to recode the grbl for connect the other arduino for additional part?

 

#Arduino grbl connect to other arduino

@Mr Chris and @Mr Allan : i’ve a project arduino cnc, my cases how to recode the arduino grbl to connect the other arduino cause i want to additional part fromthe other arduino?

do you have an idea? or source code for my cases :slight_smile:

thanks you