Hi. I am trying to recieve serial data from an Arduino Uno and display it in a TextMeshPro element. However, upon running my program I get the error in this post’s title. Does anyone know why this is happening?
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.IO.Ports;
public class Clock : MonoBehaviour
{
SerialPort stream = new SerialPort("COM5", 19200);
public string recievedString;
public TMP_Text words;
int buttonState = 0;
void Start()
{
stream.Open();
}
// Update is called once per frame
void Update() {
string value = stream.ReadLine();
buttonState = int.Parse(value);
words.text = buttonState.ToString();
}
}
Arduino Code:
int button = 13;
int buttonState;
void setup() {
// put your setup code here, to run once:
pinMode(button, INPUT);
Serial.begin(19200);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(button);
if (buttonState == 1) {
Serial.flush();
Serial.println("hello ");
delay(200);
}
}