Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sisomm
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sisomm/9168921 to your computer and use it in GitHub Desktop.
Save sisomm/9168921 to your computer and use it in GitHub Desktop.
Arduino side with Serial and SoftSerial
// 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