// Program for attiny1614 send sensor data to esp32 via uart // created by Jans Hendry // Universitas Gadjah Mada, Indonesia // Kamakura Node, Japan // fab academy MIT - 2022 String msg = ""; // temporaray variable that stores integer to string const int readMag = 6; void setup() { Serial.begin(9600); // serial pinMode(readMag, INPUT); } void loop() { int dt = digitalRead(readMag); // sensor read out msg = String(dt); // convert to string if (!dt) { msg = msg + " - on path"; } else { msg = msg + " - out of path"; } // Send one by one of the string to ESP32. We cannot send them altogether, as it will // change to different character recognized by C for (int i = 0; i < msg.length(); i++) { Serial.write(msg[i]); // send via UART } Serial.write('\0'); // special character to say that transmission is complete delay(100); // delay should be used, otherwise, the data received in some cases will be cutted or not completed }