Serial port problems between Unity3d and Arduino

Discussion in 'UDOO X86' started by Gidi2Go, Mar 2, 2018.

  1. Gidi2Go

    Gidi2Go New Member

    Joined:
    Feb 10, 2016
    Messages:
    5
    Likes Received:
    1
    Hi,

    I have a Udoo X86 running Windows 10. On this platform I run a Unity 2017.3 program, communicating with the onboard Arduino (Intel Genuino) via the SerialPort.
    The problem is, that communication from Unity to Arduino is working flawlessly, but Unity is not receiving any data from the Arduino. I get
    TimeoutException [..] at System.IO.Ports.WinSerialStream.Read

    (no matter how long I set the timeout value).
    Strangely, if I test the setup with RealTerm, I do get the correct values from the Arduino. (And needless to say, when I run the Unity program on my PC with an Arduino Uno connected, it works without any problems).

    I have tested with baud rates 9600 and 115200, but to no avail.

    Any ideas on what might be the problem?
     
  2. ccs_hello

    ccs_hello UDOOer

    Joined:
    Apr 15, 2017
    Messages:
    535
    Likes Received:
    194
    Did you put a level shifter in between to handle Braswell's 1.8V and Arduino's 3.3V I/O?
     
    Last edited: Mar 2, 2018
  3. Gidi2Go

    Gidi2Go New Member

    Joined:
    Feb 10, 2016
    Messages:
    5
    Likes Received:
    1
    ?? No. (how can I and why should I)? The Arduino is built-in, it handles its own inputs, and communicates with the PC part via a built-in serial port. I don't think I have to add a level shifter for this built-in port.
     
  4. ccs_hello

    ccs_hello UDOOer

    Joined:
    Apr 15, 2017
    Messages:
    535
    Likes Received:
    194
    Okay, now it's clearer. You are talking about the internal physically USB to USB connection.
    On x86 side, it's USB host and the Arduino 101 (Intel Curie) plays the USB device role where, (like Arduino Micro using ATmega32u4,) is using the chip's software stack to emulate a serial device.
    X86 side will detect it's a USB-serial device and install the driver and from that point on, it's a COM port.

    So you should be able to install Arduino IDE on x86 side, upload a sketch, and also open a terminal to monitor that (emulated) serial port activities, both in and out. If it works as described, it should be declared as okay, hardware wise, as well as x86 side USB-serial drive point of view.

    If you did something on the Arduino side making it only see one way traffic, that's most likely Arduino 101 sketch/Arduino 101 firmware issue.
     
  5. Gidi2Go

    Gidi2Go New Member

    Joined:
    Feb 10, 2016
    Messages:
    5
    Likes Received:
    1
    Yes, I did install the Arduino IDE on x86 side, uploaded a sketch to the Arduino 101, and I am not sure I tested the terminal in the IDE, but I guess that works (since it works in the Realterm application). I'll check to make sure!

    So there is definitely two-way traffic there, but not in the Unity - Arduino combination. Therefore,I think it is more likely that the error is on the Unity3d side, and you have given me another idea to test: I could attach a separate Arduino to the X86 via an external USB port and see if that works.
     
  6. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    I also think the source of the problem is on the Arduino 101 side as it has a completely different USB architecture as any other Arduino. Perhaps you have to look into the serial sending part of your Arduino sketch.
     
  7. Gidi2Go

    Gidi2Go New Member

    Joined:
    Feb 10, 2016
    Messages:
    5
    Likes Received:
    1
    Okay, I think I have established that indeed the problem is on the Arduino 101 side:
    • My Unity program in combination with an external Arduino (Uno) works great,
    • The same program in combination with the internal Arduino 101 works only one way (from Unity to Arduino)
    • However, the Arduino 101 sketch in combination with the Serial Monitor of the Arduino IDE (or a separate program like Realterm) works okay (communication both ways)
    I have attached the Arduino sketch (just to show that it is really simple).
    So, if the problem is with the Arduino 101, what is the way to solve it?
     

    Attached Files:

  8. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Good investigation. As a normal Serial Monitor/terminal is working OK then this looks like an issue for the Unity program not reading the serial device correctly in combination with the internal USB for Arduino 101.
    But it can also be that the "\n" is not being read somehow.

    https://github.com/dwilches/SerialCommUnity/issues/2
     
    deepshika1 and Gidi2Go like this.
  9. Gidi2Go

    Gidi2Go New Member

    Joined:
    Feb 10, 2016
    Messages:
    5
    Likes Received:
    1
    Thanks, based on your suggested link (https://github.com/dwilches/SerialCommUnity/issues/2) I managed to solve the problem: I added (in the Unity program) "DtrEnable = true" for the SerialPort before I opened it, and now it works okay! (Both on the internal and external Arduino).
     
    waltervl likes this.

Share This Page