I am currently trying to make a multicopter, for that i have a board with a gyro and an accelerometer on but my arduino is to small to run the entire rest of me program for the steering so I want to send the data from the gyro and accelerometer to an other arduino to run my program there. But sending the date through tx-rx is pretty hard, I tried a lot of things to send the string but it doesn't work. Does anyone know a solution (a simple program to send a string through tx-rx).
I believe from what you wrote that you are not able to accummulate all the needed chars/bytes you are throwing off the UART alley so I would suggest reading the input into a variable using a IF condition till you encounter a /n or similar element(for this you need to send the strip with an /n at the last so you read it finally till the /n into the variable)
another possible way is to use the "<> " where you programme knows that the string is there on the rx channel and < this tell the arduino when to start reading and adding into a variable and > this tell when to stop.
In simple terms the message to be sent is packaged between special start and end markers and the receiving device ignores everything before the start marker and then saves everything until the end marker is detected.
If you are talking about sending a string from one arduino to another arduino, you need to connect the tx pin of the sender to the rx pin of the receiver, and have both boards grounds connected together. Below is some simple code I've used to send from the serial monitor to the tx arduino, then the tx arduino sends the string to the rx arduino.
//zoomkat 3-5-12 simple delimited ',' string tx/rx
//from serial port input (via serial monitor)
//and print result out serial port
//Connect the sending arduino rx pin to the receiving arduino rx pin.
//Connect the arduino grounds together.
//What is sent to the tx arduino is received on the rx arduino.
//Open serial monitor on both arduinos to test
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop() {
//expect a string like wer,qwe rty,123 456,hyre kjhg,
//or like hello world,who are you?,bye!,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ',') {
if (readString.length() >1) {
Serial.print(readString); //prints string to serial port out
Serial.println(','); //prints delimiting ","
//do stuff with the captured readString
readString=""; //clears variable for new input
}
}
else {
readString += c; //makes the string readString
}
}
}
Steven1994:
I am currently trying to make a multicopter, for that i have a board with a gyro and an accelerometer on but my arduino is to small to run the entire rest of me program for the steering so I want to send the data from the gyro and accelerometer to an other arduino to run my program there.
That's probably a mistake. Dividing your solution between two platforms is going to make both of them a lot more complicated. You would be far better off choosing a single platform that has enough resources to run the whole thing, and people do manage to run quite sophisticated autopilots on an Arduino so it should be possible if you code it efficiently enough.