noiasca:
Da verweise ich gern auf das Tutorial von Robin2:
Schönes Beispiel, habe ich gleich mal probiert:
// Mega2560
// Example 2 - Receive with an end-marker
// Quelle: http://forum.arduino.cc/index.php?topic=396450
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
Serial3.begin(9600);
}
void loop() {
recvWithEndMarker();
showNewData();
}
void recvWithEndMarker() {
static byte ndx = 0;
char startMarker = '\x02';
char endMarker = '\x03';
char rc;
while (Serial3.available() > 0 && newData == false) {
rc = Serial3.read();
if (rc != endMarker && rc != startMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
if (rc == endMarker) newData = true;
}
}
}
void showNewData() {
byte hh = 0, mm = 0, ss = 0; // Hier sollen die Zahlenwerte landen
if (newData == true) {
sscanf(receivedChars, "D:%*u.%*u.%*u;T:%*u;U:%hhu.%hhu.%hhu;uvxy", &hh, &mm, &ss);
Serial.print("Empfangen: ");
Serial.print(receivedChars);
Serial.print('\t');
Serial.print(hh); Serial.print(" ");
Serial.print(mm); Serial.print(" ");
Serial.print(ss); Serial.println();
newData = false;
}
}