Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[RELEASED] Uduino - The easiest Arduino-Unity communication

Discussion in 'Assets and Asset Store' started by marcteys, Dec 1, 2016.

  1. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12


    Uduino
    is a Unity plugin which allows to communicate easily between Arduino and Unity.

    Uduino aims to be a comprehensive and easy to setup solution for your Arduino/Unity projects, allowing you to communicate in both side (Arduino->Unity and Unity->Arduino).
    It works efficiently across all operating systems, with a reliable serial connection and features exemples and a simple API.

    Control your Arduino board directly with editor (even in pause mode !), with an advanced inspector panel. This Asset is made both for Designers, Hobbyist who wants to have things done quickly or professional who wants to have an advanced, stable and reliable connection.

    Get it now !




    Features
    • An easy and fast way to read and write data from Unity <-> Arduino
    • Advanced Inspector panel, allowing you to debug even in pause mode !
    • More than 10 Examples with the package
    • Arduino Library for an optimized and advanced use
    • Convert your existing Arduino code to be compatible with Uduino in few lines
    • Compatible with different Arduino board
    • Optimized serial connection to not drop the frame rate (Threads)
    Purpose & Target
    This project was created after too much frustration on how to properly connected Unity & Arduino. During past past experiences I was facing some problems: frame rate drop when communicating with serial ports, freeze and crash, difficulties to detect a specific Arduino board when several are connected, and many more.

    All existing projects mixing Arduino and Unity where either not cross-platform, too complex and complicated (using Firmata to control a LED !? Hell no! ), not compatible with other libraries libraries or simply not stable enough. What we really need is a simple Arduino file and simple c# functions to read analog pin or write instructions.

    How simple ?
    1. Upload the Arduino Code
    2. Press Discover Ports
    3. That's it ! you can now control your Arduino from the panel

    How extensible?
    1. Use Uduino library on your Arduino code
    2. Add any Read and Write commands
    3. Calls them from Unity !

    Get Uduino on the Asset Store : https://www.assetstore.unity3d.com/en/#!/content/78402


    Know more

    Visit our website and you will find :
    - Explained examples
    - Documentation of the API
    - FAQ
     
    Last edited: Jul 6, 2017
    one_one and MS80 like this.
  2. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    This looks very interesting, thanks for sharing!
    I will test it as soon as possible.
     
  3. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    As I told in the first message, I need some testers and feedback.
    I could test this program only on 4 computers, which is not enough to be sure it's stable. I also tried with few arduino boards, but not all of them.
     
  4. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    Hi marcteys,

    after importing "uduino.unitypackage" I got an error:
    "Assets/Uduino/Scripts/UduinoManager.cs(19,17): error CS0234: The type or namespace name `Ports' does not exist in the namespace `System.IO'. Are you missing an assembly reference"

    But Uduino-master project from GitHub works just great! :)

    So far I have tested 2 different workstations (both Windows10 64bit) and 2 arduinos together (2 x simple read: UNO + MEGA). It was very easy to get 2 inputs from 2 different arduino boards, uduino found the correct ports automatically without any issue !!

    Also I wanted to test Arduino DUE but it seems uduino library has a errors and cannot uploaded on the Due:

    "In file included from C:\Users\Martin\Desktop\sketch_dec01da\sketch_dec01da.ino:1:0:
    E:\Programme\Arduino\libraries\Uduino/Uduino.h:51:30: fatal error: SoftwareSerial.h: No such file or directory
    #include <SoftwareSerial.h>
    ^
    compilation terminated.
    exit status 1
    Fehler beim Kompilieren für das Board Arduino Due (Programming Port)."
     
  5. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    Great, I'm happy that it's working well.

    For the error The type or namespace name `Ports' does not exist in the namespace `System.IO', it's a known issue which can be solved easily: You need to change your project API compatibility (Located under Edit\Project Settings\Player )from .NET 2.0 Subset to .NET 2.0. I added this on the github page.

    I tried on arduino DUE and it seems to work here. Does you Arduino IDE is updated ? There was a issue with SoftwareSerial on previous Arduino version.
     
  6. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    Hi @marcteys ,
    I have a problem with reading and writing from/to one arduino at the same time. It seems writing disables the read function?! If only read or only write function (C# script inside unity) is active everything works just fine (read: sensor A0, write: pin13 onboard LED). If both functions are active, reading does not work anymore.

    ReadWriteSensor.ino:
    #include<Uduino.h>
    Uduino uduino("myArduinoName"); // Declare and name your object

    void setup()
    {
    Serial.begin(9600);
    pinMode (13, OUTPUT);
    uduino.addCommand("mySensor", GetVariable); // Link your sensor reading (called "mySensor") to a function
    uduino.addCommand("SetLight", SetLightValue); // The function to be executed when we receive the value from Unity
    }
    void GetVariable() {
    Serial.println(analogRead(A0));
    }
    void SetLightValue() {
    char *arg;
    arg = uduino.next(); // The arg char buffer is read and stored
    uduino.readSerial(); // ...then process Uduino. /!\ This part is mandatory
    }
    void loop()
    {
    // if (Serial.available() > 0) // verify if the serial is available...
    uduino.readSerial(); // ...then process Uduino. /!\ This part is mandatory
    }


    Probably I'm doing something wrong, could you please give me some hints to get it to work?! Any ideas how to read and write at the same time or after each other?

    Maybe you already have a simple example to show how to use read and write to the serial port?!
     

    Attached Files:

    Last edited: Feb 7, 2017
  7. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    I am doing quite a big refactor of the project those days, so be sure you updated your code to the last version, available on Github. I think your problem have been resolved, if not PM me.

    For the final release on the play store I am also writing a full documentation with clear examples, new features and maybe video tutorial ! Everything will come in the next few days/weeks
     
  8. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    That sounds great! Where should I throw my money??
    Looking forward for the release!
     
  9. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    zyzyx likes this.
  10. Edahsrevlis

    Edahsrevlis

    Joined:
    Jul 20, 2017
    Posts:
    2
    I have an Android build that runs through an Android TV box that gets inputs from a table hockey game. I want to connect the Android box to an Arduino and send all the outputs and inputs to and from Unity with the Arduino. Will Uduino work in an Android build?
     
  11. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    I didn't tested with Android support , but it might work. Let me try it first, before getting Uduino.
    In the next version I planned to have Android support and wireless (esp8266) support.

    Edit: It is not working currently and requires more work, but it will be working at some point soon.
     
    Last edited: Aug 10, 2017
  12. tanoshimi

    tanoshimi

    Joined:
    May 21, 2013
    Posts:
    297
    Any progress to report on Android <-> Arduino support?
     
  13. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    Yes, soon to be released !

    I refactor most of the code and it took me a lot of time. Now Uduino can support "extensions". You'll be able to develop seamlessly on your desktop and android. These extensions include:
    - Arduino to Android communication via Serial
    - Arduino to Android communication via Bluetooth LE
    - Playmaker support

    I'm still finishing some Interface elements and completing the documentation before releasing it publicly, however I might consider doing a beta-test soon.
     
    wersw73 likes this.
  14. tanoshimi

    tanoshimi

    Joined:
    May 21, 2013
    Posts:
    297
    Ah great, that's good to hear. I'm not personally bothered about PlayMaker, but reliable read/writing between Android and Arduino is giving me way more headaches than I anticipated! Doing it using PC was trivial, but enumerating the available serial ports on Android seems to require a rooted device from what I've researched so far - have you managed to write a plugin in such a way to avoid this? :(

    Do please keep me informed when you're closer to release or if you need any testers for the beta!
     
  15. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    Uduino for Android will automatically find the board connected to your phone.
    I am currently beta-testing Uduino for Android (both Bluetooth and OTG), let me know if you want to be part of it !
     
  16. Hazime

    Hazime

    Joined:
    May 30, 2016
    Posts:
    1
    Hey marcteys, I just bought your asset and I want to do things on Android. How is it going? can I be part of the tests?
     
  17. tanoshimi

    tanoshimi

    Joined:
    May 21, 2013
    Posts:
    297
    I'm still happy to be part of that test myself too!
     
  18. DAEW

    DAEW

    Joined:
    Jun 16, 2018
    Posts:
    1
    I want to connect android to arduino.
    I want to build andrioid.
    It is possible?
    Can I use bluetooth connection this application?
     
  19. Ava42

    Ava42

    Joined:
    Aug 4, 2012
    Posts:
    32
    so it works with OTG connection?
     
  20. juank-f

    juank-f

    Joined:
    Sep 17, 2019
    Posts:
    1
    Podrías subir un video de una conexión con esp8266 y android, ya compré el producto, pero tengo varios errores, por favor
     
  21. MonkeyKasai

    MonkeyKasai

    Joined:
    Jan 4, 2014
    Posts:
    40
    Does this work with arduino emulators for testing?
     
  22. Tubbritt

    Tubbritt

    Joined:
    Nov 30, 2015
    Posts:
    46
    The very first screen shot on the asset store clearly shows this is Android Compatible, but the version being sold does not contain this feature? Building to android also completely fails. I sent you an email but I got no reply. Just trying to make contact with you some other means now.

    Hope you can help.

    Regards
    James.
     
  23. Malveka

    Malveka

    Joined:
    Nov 6, 2009
    Posts:
    191
    Hello,

    I've been using Uduino with great success over the last couple of years. Thank you for making and maintaining this extremely useful asset!

    I've just noticed that if I set the Log level to Debug on the UduinoManager component that I gets lots of the following message. Wondering if this expected behavior or if I should be concerned? I haven't noticed this affecting the behavior of my project. Perhaps this is an expected result of polling the IO port?

    Thanks for any insights.

    ==========================================

    ReadTimeout. Are you sure something is written in the Serial of the board?
    System.TimeoutException: The operation has timed out.
    at System.IO.Ports.WinSerialStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x000a9] in <14e3453b740b4bd690e8d4e5a013a715>:0
    at System.IO.Ports.SerialPort.read_byte () [0x00007] in <14e3453b740b4bd690e8d4e5a013a715>:0
    at System.IO.Ports.SerialPort.ReadTo (System.String value) [0x0003c] in <14e3453b740b4bd690e8d4e5a013a715>:0
    at System.IO.Ports.SerialPort.ReadLine () [0x00000] in <14e3453b740b4bd690e8d4e5a013a715>:0
    at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort.ReadLine()
    at Uduino.UduinoDevice_DesktopSerial.ReadFromArduinoLoop (System.Boolean forceReading) [0x00042] in D:\Documents\**removed client info**\URP_Test2\Assets\Uduino\Scripts\Boards\DesktopSerial\UduinoDevice_DesktopSerial.cs:213
    UnityEngine.Debug:Log(Object)
    Uduino.Log:Debug(Object, Boolean) (at Assets/Uduino/Scripts/Extra/UduinoDebug.cs:47)
    Uduino.UduinoDevice_DesktopSerial:ReadFromArduinoLoop(Boolean) (at
    Assets/Uduino/Scripts/Extra/UduinoDebug.cs:47)
    Uduino.UduinoDevice_DesktopSerial:ReadFromArduinoLoop(Boolean) (at Assets/Uduino/Scripts/Boards/DesktopSerial/UduinoDevice_DesktopSerial.cs:250)
    Uduino.UduinoManager:ReadPorts() (at Assets/Uduino/Scripts/UduinoManager.cs:1564)
    System.Threading.ThreadHelper:ThreadStart()
     
  24. the_cerberus

    the_cerberus

    Joined:
    Aug 20, 2019
    Posts:
    10
    Hello,
    i use Uduino with my Arduino Uno.
    What is the essential code to let unity access the Arduino?
    I have an example, but wenn i use the DISCOVER button in unity, the Arduino starts working (led is blinking for a short time) but no connection is made?!
     

    Attached Files:

  25. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    Hello,

    You need to add the basic Uduino commands in the loop to maintain the connection :


    Code (CSharp):
    1. void loop()
    2. {
    3.   uduino.update();
    4.   delay(10); // Delay of your choice or to match Unity's Read Timout
    5. }
    Don't hesitate to go to the website https://marcteyssier.com/uduino/ to find more information
     
  26. the_cerberus

    the_cerberus

    Joined:
    Aug 20, 2019
    Posts:
    10
    Problem solved. Thanks.
    Next Problem. Arduino Uno works. ESP8266 NodeMCU doesnt. I use the example "Uduino" and switched in Unity Board type to NodeMCU and i tested ESP8266 - when i click DISCOVER PORTS - The ESP is blinking short time an then...nothing.
    When i use my sketch (picture below) it works. I dont know the difference between the two sketches. Help.
     

    Attached Files:

  27. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    It should work with esp8266. I tried here and it's working alright. Can you try with another pin ? Pin D0 is a bit tricky with the NodeMCU. Maybe try with LED_BUILTIN or D2

    (Also, having a shorter board name , replacing "Batis Arduino Uno" by "Batis" saves few milliseconds at the beginning )
     
  28. the_cerberus

    the_cerberus

    Joined:
    Aug 20, 2019
    Posts:
    10
    Do not get me wrong. The sketch that I posted works fine. The Uduino example in the Arduino IDE
    (exampel -> uduino -> uduino) does not work with the ESP8266, but with the Arduino Uno. What could that be?
    upload_2021-2-24_19-27-17.png
     
  29. marcteys

    marcteys

    Joined:
    Mar 8, 2013
    Posts:
    12
    What is the exact ref of your ESP8266 ?
     
  30. the_cerberus

    the_cerberus

    Joined:
    Aug 20, 2019
    Posts:
    10
    Its a: Lolin V3 Module with ESP8266 12F

    AmazonLink

    Next Question: The Uduino stuff works very good. I would like to buy the Wifi-Addon. But im not shure if this works like expected.
    Project 1: Arduino RC-Car controlle by smartphone via wifi.
    Project 2: Upgrade Nerf-lasertec - smartphone can count score, activate abilitys etc. Wifi also needed.
    Do you have any experience with Unuino and smartphone wifi?
     
    Last edited: Feb 25, 2021
  31. unity_1os17zxMyCQmHA

    unity_1os17zxMyCQmHA

    Joined:
    May 8, 2020
    Posts:
    2
    Hello, Can I used with android ??
     
  32. FiaKun

    FiaKun

    Joined:
    Sep 20, 2020
    Posts:
    3
    hi... i did the IMU example but instead of mpu6050 we use mpu9250, we worked around it and run for a couple sec then it's went offline. we see it have potential. so we take a step further by adding multiplexer and 2 other IMU9250 we tried some codes but it just wont run.. and it always gave us impossible to get name this port/board.

    it would be really helpful if you guys can give us walkthrough/tutorial/guide on using multiplexer with Uduino.
    great plugin, keep up the good work!

    here's an example on .ino and .cs we currently work on.
     
  33. davexps

    davexps

    Joined:
    Nov 8, 2020
    Posts:
    2
    Hello, getting "No Arduino Connected" on 2022.3.12f1 <Metal> on Mac 14.0 (23A344). The Arduino IDE connects ok. Tried on a Uno R3 and Mega 2560, getting the same issue on both. Any ideas? I have quick the Arduino IDE before trying again. Thank you.