Skip to content

Instantly share code, notes, and snippets.

@chrwei
Last active November 15, 2015 18:58
Show Gist options
  • Save chrwei/26fda439d8198f1c2a28 to your computer and use it in GitHub Desktop.
Save chrwei/26fda439d8198f1c2a28 to your computer and use it in GitHub Desktop.
/*
* Serial echo for verifying communication with a PC based program
* On Galileo or Edison this can talk to a process on the host
* if you setup socat to create some devices.
*/
#if defined(__ARDUINO_X86__)
//Galileo or Edison, setup ring buffer and TTYUARTClass
RingBuffer rx_buffer_S1;
TTYUARTClass mySerial(&rx_buffer_S1, 3, false);
#elif
//all other configuration use the first serial UART
#define mySerial Serial
#endif
void setup() {
#if defined(__ARDUINO_X86__)
//for Galileo or Edison specify the host TTY to connect to
mySerial.init_tty("/root/tty0");
#endif
//now the mySerial instance can be treated just like any Serial instance
mySerial.begin(115200);
}
void loop()
{
mySerial.write("A");
if(mySerial.available()) {
char in = mySerial.read();
if(in == 'A') {
mySerial.write("$");
} else {
mySerial.write("!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment