Created
January 16, 2020 13:16
-
-
Save wojciech-zurek/61ca70473bdb06d084f3457d62bf17a4 to your computer and use it in GitHub Desktop.
Serial I/O on Arduino + serial I/O on Linux
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
//Arduino: | |
#include <Arduino.h> | |
#define LF 0x0A | |
char buffer[11]; | |
int idx = 0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.print("Echo start\r\n"); | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) | |
{ | |
buffer[idx] = Serial.read(); | |
if (buffer[idx] == LF || idx >= 9) | |
{ | |
buffer[idx + 1] = 0; | |
Serial.print("Received message: "); | |
Serial.println(buffer); | |
idx = -1; | |
} | |
idx++; | |
} | |
} | |
//Linux: | |
stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts | |
tail -f /dev/ttyUSB0 | |
echo "1233333333333333" > /dev/ttyUSB0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment