#include #include #include #include #include #include #define SERIAL_PORT "/dev/ttyACM0" // Change this to match your Arduino's serial port int main() { int serial_port = open(SERIAL_PORT, O_RDWR); // Open the serial port // Error handling for opening serial port if (serial_port < 0) { perror("Error opening serial port"); return 1; } // Configure serial port settings struct termios tty; memset(&tty, 0, sizeof(tty)); if (tcgetattr(serial_port, &tty) != 0) { perror("Error from tcgetattr"); return 1; } cfsetospeed(&tty, B9600); // Set baud rate cfsetispeed(&tty, B9600); tty.c_cflag &= ~PARENB; // 8N1 (8 data bits, no parity, 1 stop bit) tty.c_cflag &= ~CSTOPB; tty.c_cflag &= ~CSIZE; tty.c_cflag |= CS8; tty.c_cflag &= ~CRTSCTS; // Disable hardware flow control tty.c_cc[VMIN] = 1; // Read at least 1 character tty.c_cc[VTIME] = 5; // Wait up to 0.5 seconds (5 deciseconds) // Apply settings if (tcsetattr(serial_port, TCSANOW, &tty) != 0) { perror("Error from tcsetattr"); return 1; } char buf[5]; // Buffer to store received string (+1 for null terminator) ssize_t n; //TODO: Read from Arduino negative Temperature value in the form of n = read(serial_port, &buf, 4); close(serial_port); // Close the serial port return 0; }