wrmhl icon indicating copy to clipboard operation
wrmhl copied to clipboard

problem reading Unity from Arduino with any other method than Serial.read()

Open pr00thmatic opened this issue 5 years ago • 0 comments

Hi there! first of all... thanks for being so awesome!! your code works like a charm without fps drop :)

I am working on an Arduino Uno, under Windows 10 and Unity 2018.1.0f2 (64 bits).

There is a problem with the .send(message) method, it is easy to replicate:

open the scene WRMHLwrite and replace the loop method on the default arduino code on the ARDUINO.ino file with this code:

// Run forever
void loop() {
  sendData("Hello World!");

  if (Serial.available() > 0) {
    // int input = Serial.parseInt();
  }

  delay(20); // Choose your delay having in mind your ReadTimeout in Unity3D
}

This works OK, as the RX yellow light blinks when you play your unity game (unity is sending data from the update). But when you uncomment the line

int input = Serial.parseInt();

strange things begin to happen: when you play your game, both RX and TX lights blink once, and then the RX light turns off... the arduino stops receiving data!! also, weird things begin to happen with the data the arduino sends, and the serial port gets locked, not allowing you to upload new code to the arduino o.O (even when you stop your game on unity! o__O).

however, if you substitute that line for:

int input = Serial.read();

everything works just fine :)

I can't figure out where the error is on the code, but i'll keep searching, if I find something, i'll submit a pull request, but by now, I'll just leave this issue open over here...

sorry for my bad english :(

pr00thmatic avatar Aug 03 '18 23:08 pr00thmatic