i want to ask whether uno can serial.print strings while receiving strings through tx rx. i use one uno send "aaa"to the other in the loop, when the second receiving "a",it will send "bbb"to the first one. when i disconnect the second uno tx to the first uno rx,i find the second send "bbb"correctly through monitor,but when i connect the second uno tx to the first rx, it will mess up in the monitor.what's wrong with it? thanks.
Show a diagram (no Fritzing mess) how it's connected and show you're program.
Also, which Arduino(s)?
Tip! You're keyboard comes with a shift key
(deleted)
You really need to post your programs so we can see exactly what you are doing.
An Arduino works very much faster than Serial data is transmitted so it can appear to do two things at once.
And, for the future, give a little thought to how your writing appears to the reader. The text in your Original Post is much easier to understand with a bit of white space - like this
i want to ask whether uno can serial.print strings while receiving strings through tx rx.
i use one uno send "aaa"to the other in the loop,
when the second receiving "a",it will send "bbb"to the first one.
when i disconnect the second uno tx to the first uno rx,i find the second send "bbb"correctly through monitor,
but when i connect the second uno tx to the first rx, it will mess up in the monitor.what's wrong with it?
thanks.
...R
Serial Input Basics
Sorry,i'm a newbee .
Thanks everyone a lot.
The problems like that :
the first uno send "?"to the second uno ,the second one has grbl
when i wiring first tx to the second rx,(gnd are com)
display correctly:
<Idle|MPos:0.000,0.000,0.000|FS:0,0|Ov:100,100,100>
ok
ok
<Idle|MPos:0.000,0.000,0.000|FS:0,0>
ok
ok
<Idle|MPos:0.000,0.000,0.000|FS:0,0>
ok
ok
<Idle|MPos:0.000,0.000,0.000|FS:0,0>
ok
ok
<Idle|MPos:0.000,0.000,0.000|FS:0,0>
ok
ok
but when i also wiring first rx to second tx, it mess up:
error:2
ok
error:1
ok
error:1
ok
<Idle|MPos:0.000,0.000,0.000|FS:0,0>
ok
ok
error:2
ok
error:1
ok
error:1
ok
<Idle|MPos:0.000,0.000,0.000|FS:0,0>
ok
ok
ok
ok
error:1
ok
error:1
ok
Don't bother posting the GRBL program but you do need to post the program you have on the other Arduino.
Also, as requested in Reply #1, post a diagram showing how you have everything connected.
...R
void setup(){
ini_serial();
}
void loop() {
requestPosition();
// Parse the string when a newline arrives:
if (stringComplete) {
parse_and_store();
// clear the string:
line = "";
stringComplete = false;
delay(100);
}
delay(30);
}
void ini_serial(){
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
line.reserve(64);//reserve at least 64 bytes for the incoming string
}
//Request position to GRBL
void requestPosition(){
Serial.println("?");
}
void serialEvent() {
while (Serial.available()>0) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
line += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
void parse_and_store(){
int parseState = line.indexOf('<');
int parseState1 = line.indexOf('|');
Serial.println(line.substring(parseState+1,parseState1));
State = line.substring(parseState + 1,parseState1);
int parseMPos = line.indexOf('MPos:');
Serial.println(parseMPos);
int xparseMPos = line.indexOf(',');
int yparseMPos = line.indexOf(',',xparseMPos + 1);
int z_parseMPos = line.indexOf('|');
int zparseMPos = line.indexOf('|',z_parseMPos + 1);
x_Value = line.substring(parseMPos+1,xparseMPos);
y_Value = line.substring(xparseMPos+1,yparseMPos);
z_Value = line.substring(yparseMPos+1,zparseMPos);
/*Serial.println( line.substring(parseMPos+1,xparseMPos));
Serial.println( line.substring(xparseMPos+1,yparseMPos));
Serial.println( line.substring(yparseMPos+1,zparseMPos));*/
int parseWPos = line.indexOf('WCO'); //find WCO
Serial.println(parseWPos);
if ( parseWPos != -1 ){
wline = line.substring(parseWPos); //get the string after WCO: O:0.000,0.000,0.000>
Serial.println(wline);
int wparseWPos = wline.indexOf(':');
//Serial.println(wparseWPos);
int xparseWPos = wline.indexOf(',');
int yparseWPos = wline.indexOf(',',xparseWPos + 1);
int zparseWPos = wline.indexOf('>');
X_WCO = (wline.substring(wparseWPos + 1,xparseWPos));
Y_WCO = (wline.substring(xparseWPos + 1,yparseWPos));
Z_WCO = (wline.substring(yparseWPos + 1,zparseWPos));
/*Serial.println(wline.substring(wparseWPos + 1,xparseWPos));
Serial.println(wline.substring(xparseWPos + 1,yparseWPos));
Serial.println(wline.substring(yparseWPos + 1,zparseWPos));*/
if ( wline.indexOf('Ov') == -1)
{
Fx_Value = x_Value.toFloat(); //change x_Value from string to float
Fy_Value = y_Value.toFloat();
Fz_Value = z_Value.toFloat();
FX_WCO = X_WCO.toFloat();
FY_WCO = Y_WCO.toFloat();
FZ_WCO = Z_WCO.toFloat();
X_Value = Fx_Value - FX_WCO; // WPos = MPos - WCO;
Y_Value = Fy_Value - FY_WCO;
Z_Value = Fz_Value - FZ_WCO;
/* Serial.println(Fx_Value - FX_WCO,3);
Serial.println(Fy_Value - FY_WCO,3);
Serial.println(Fz_Value - FZ_WCO,3);*/ //debug
}
}
}
wiring diagram:
https://drive.google.com/file/d/0B5MJn_ytEg7lUUVtLWdDd2QyLU0/view?usp=sharing
display like this:
https://drive.google.com/file/d/0B5MJn_ytEg7lNW50T1BwMUltcjg/view?usp=sharing
https://drive.google.com/file/d/0B5MJn_ytEg7ldzNGV2V4dmVxQTQ/view?usp=sharing
Please post your images here so we can see them easily and at the same time as we are reading your text. See this Image Guide
From looking at your first image it seems that you have the ArduinoA with GRBL connected to your PC and your ArduinoB is connected to the GRBL ArduinoA. What on earth are you trying to do?
And your diagram does not show any of the Arduino pin numbers. If your ArduinoB is connected to the same Serial port on ArduinoA as the PC is using it is not surprising if things go wrong.
And if GRBL is getting commands from the PC I suspect it is going to be confused if it also gets commands from another source.
This is one the best examples I have seen of the XY Problem. You really need to explain what you want to achieve and not start with some detail question about how you think it might be done
...R
You are right.Thank you Robin.
I would like to display Wpos and Mpos on lcd while grbl connect with pc.
I have found shapeoko forum and study their's code,but i can't understand how to isolate pc with grbl while display on lcd.
I did actually download your image so I could read it properly - just because I was a little bit interested in the subject.
I can't say I understand it either. I assume GRBL is on some sort of Arduino - but it does not say what type.
I don't know why the commentary mentions the GRBL Arduino's USB connection because the Leonardo in the diagram is certainly not connecting to it.
It is certainly possible to connect two TXs to a single RX. Two problems need to be solved.
First is the technical problem that the idle state of a Tx line (from the Leonardo, and from the GRBL Arduino's USB-TTL converter) is HIGH and if there are a second signal pulling the line HIGH when the first one wants to pull it LOW it won't work. The 4066 is intended to solve that problem - but I wonder if it does it properly, because it cannot affect the signal line coming from the GRBL Arduino's USB-TTL converter.
The second problem seems to me to be more intractable. How can the Leonardo ensure that it never tries to communicate with the GRBL Arduino while the PC is trying to do so.
Assuming BOTH problems can be solved I guess there is no reason why the Leonardo should not send requests for data to the GRBL Arduino. However I have no idea whether that might interfere with GRBL's ability to smoothly move the stepper motors.
By the way there is no suggestion in all of this that the GRBL Arduino would be doing anything unusual at the level of its serial communication.
Also, I don't see anything to suggest that a Leonardo must be used but the Leonardo and Micro have the advantage of having a spare HardwareSerial port on pins 0 and 1 which would simplify the programming. A Mega has 3 spare HardwareSerial ports.
...R
When Leonardo communicate with grbl ,should isolate the rx line with pc. But i can't understand how to do that.
Leonardo should always send "?" so that grbl will response Wpos and Mpos.And it has no influence on stepper motion.
Leonardo is not must be used.
11512991203:
When Leonardo communicate with grbl ,should isolate the rx line with pc. But i can't understand how to do that.
I don't know either - because AFAIK the data from the PC to the Rx pin on the GRBL Arduino goes through the Arduino circuit board.
However, even if you could isolate that signal you have to ask yourself if it would be wise to do so. What would happen if the PC needed to send some data?
If other GRBL users are doing what you want to do then you should be asking questions of them. This Forum is primarily about writing your own Arduino programs.
Leonardo is not must be used.
I don't understand.
...R
Thank you very much, Robin.
I will go to shapeoko forum for help.