Last active
August 29, 2015 13:56
-
-
Save sisomm/9168921 to your computer and use it in GitHub Desktop.
Arduino side with Serial and SoftSerial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How it was with Serial: | |
// *** Receive *** | |
byteCount = -1; | |
byteCount = Serial.readBytesUntil('\n',buffer,bSize); | |
if (byteCount > 0) { // Really simple parsing | |
strcpy(command,strtok(buffer,",")); | |
/* | |
Then perform stuff... | |
*/ | |
// *** Send *** | |
} | |
Serial.println(theCommand); | |
// NOW THIS IS WHAT IT LOOKS LIKE | |
// *** Receive *** | |
SoftwareSerial mySerial(3, 2); // RX, TX | |
byteCount = 0; | |
int finished=0; | |
while(finished==0){ | |
char c = mySerial.read(); | |
if(c>=0){ | |
if((c=='|') || byteCount==(bSize-1)){ | |
finished=1; | |
buffer[byteCount]=0; | |
} else { | |
buffer[byteCount++]=c; | |
} | |
} | |
} | |
if (byteCount > 0) { // Really simple parsing | |
/* | |
Then perform stuff... | |
*/ | |
// *** Send **** | |
mySerial.print(theCommand); | |
mySerial.print('\n'); | |
mySerial.flush(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment