Git Product home page Git Product logo

wrmhl's Introduction


Super fast communication between Unity and Arduino ☄ ⏱

Create an Arduino and Unity3D interactive experience with no latency ! ⏱

Arduino to Unity made simple

If you have ever wanted to transmit data from Arduino to Unity3D the main issue is INSANE LATENCY. We didn’t find any free, optimized, and customizable solutions to tackle this problem. So I built wrmhl. You can now connect any Arduino interface to Unity3D.

You can use the default protocol, or implement your own without having to deal with thread just by changing wrmhl/Assets/WRMHL/Scripts/Thread/wrmhlThread_Lines.cs.

Getting Started

How to Install

You can either install it using Git or direct Download. Or from the command line:

# Clone this repository
$ git clone https://github.com/relativty/wrmhl

Uploading to Arduino 🤖

Upload to the Arduino the following program:

Path: wrmhl/Arduino/Arduino.ino

On Unity3D ! 💻

Open the project either from wrmhl folder or wrmhl-master 🌈

Import the Package ! 📦

Assets, Import Package and Custom Package.. and you're good to GO ! ⚡️

Important ! ⚠ Change the .NET 2.0 Subset to .NET 2.0 ⚠

In order to do that : Go to Edit ➭ Then Project SettingsPlayer, and under Other Settings find an option that reads Api Compatibility Level and change it from ".NET 2.0 Subset" to ".NET 2.0".

Run it ! 🏁 🚗

Select Assets/WRMHL/DemoScenes and choose the demo of your choice !

Don't forget to leave some feedback, contributions and suggestions are always welcome ! 🤝

wrmhl's People

Contributors

maxim-perumal avatar penguindono avatar rmetzler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wrmhl's Issues

How do you send data from Unity to Arduino?

I can't seem to figure out how to read data sent from Unity to Arduino. I tried the Serial.read() and Serial.readString() but it's not doing what it's supposed to. What it's supposed to do is turn on an LED.

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

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 :(

IOException: No such file or directory

IOException: No such file or directory
System.IO.Ports.SerialPortStream.ThrowIOException ()
System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize)
(wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
System.IO.Ports.SerialPort.Open ()
(wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
wrmhlThread.openFlow () (at Assets/WRMHL/Scripts/Thread/Common/wrmhlThread.cs:74)
wrmhl.connect () (at Assets/WRMHL/Scripts/Manager/wrmhl.cs:53)
wrmhlWrite.Start () (at Assets/WRMHL/Scripts/wrmhlWrite.cs:29)

Null error after one successful sensorRead

My system details:
image

image

Serial monitor shows normal function:
image

I closed arduino and serial monitor

Works for the first couple, but then null:

image
The issue is on this line:

image

I'm preparing a biology experiment where the communication would be very useful. How do I remedy this?
thanks so much!
-Brian

Problems with WRMHL when trying to restart scene.

WRMHL is GREAT! Oh my god, wonderful. I'm using it with BLE to wirelessly communicate MPU9250 and potentiometer data from a toy to UNITY.

Everything has been great about your work except when I try to restart my scene. After restarting the scene with SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); my character being controlled by WRMHL will not move. I can see that I am still receiving serial data.

I assume I need to call the wrhml.close() function. However, when I try to call an instance of wrhml from my other script it stops loading the rest of the script. Is there a problem with calling an instance of wrhml from another script?

How would you go about closing/restarting wrhml from another script?

ReadLatest script cannot be found

In the release there is a Prefab called wrmhlReadLatest in the Unity project, but when adding that Prefab to a scene the "associated script can not be loaded". Is that something that was omitted from the commit by error? I'd love to have that script as I'm highly interested in getting the latest value and not concerned about data loss. Latency is my main worry.

Read string value from Arduino in Unity

@maxime-coutte @al-haruun

I'm trying to get data from more than one sensor.
I thought of putting everything on a string by separating the various values with a symbol.
It's possible?
Thanks in advance for your answers, and in any case, thanks for the great job!

SerialUSB was not declared in this scope

Hi
I am trying to run the Arduino code with my Arduino Uno and it seems that Serial USB is not declared in this scope. I followed the instructions for the libraries but still nothing.

Also I can not understand why does the code uses Serial USB and not just serial.If someone could help I would really appreciate it.
Thanks

NullReferenceException: Object reference not set to an instance of an object

NullReferenceException: Object reference not set to an instance of an object
wrmhlThread.writeThread (System.String dataToSend) (at Assets/WRMHL/Scripts/Thread/Common/wrmhlThread.cs:106)
wrmhl.send (System.String dataToSend) (at Assets/WRMHL/Scripts/Manager/wrmhl.cs:70)
wrmhlWrite.Update () (at Assets/WRMHL/Scripts/wrmhlWrite.cs:34)

Queu is Full droping

Hello !

First of all, i will explain you what i want to do : I have a plant connected to my arduino, and i have number which explain the distance between my hand and the plant with a capacitive touch sensor :)

Capture d’écran 2019-05-01 à 17 17 42

So as you saw in the first screen, its what i have on the Arduino's Serials Monitor when i start to listen with unity, and in the Debug Log, i lost a lot of data like this :

Capture d’écran 2019-05-01 à 18 09 25

And when i mean "It drops a lot of times", i mean that i lost a lot of time data like have nothing, or have a half of the number ...

Thank you for your help and to be available to helping me

Proper Documentation Required

Hey thats a lot of good work ! But i seriously recommend a proper documentation so that this is friendly to people who are new to Unity as well as Arduino.. like using wrmhl in untiy script and further ...
Thanks

TimeOutException

Good morning from Spain!
We have been using this repository since 2 weeks without any problem, whereas right now we are finding some problems with Unity and TimeOutException.
The real problem is:
TimeoutException: The operation has timed out.
System.IO.Ports.WinSerialStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) (at <3845a180c26b4889bc2d47593a665814>:0)
System.IO.Ports.SerialPort.read_byte () (at <3845a180c26b4889bc2d47593a665814>:0)
System.IO.Ports.SerialPort.ReadTo (System.String value) (at <3845a180c26b4889bc2d47593a665814>:0)
System.IO.Ports.SerialPort.ReadLine () (at <3845a180c26b4889bc2d47593a665814>:0)
(wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort.ReadLine()
wrmhlThread_Lines.ReadProtocol () (at Assets/WRMHL/Scripts/Thread/wrmhlThread_Lines.cs:40)
wrmhlThread.ThreadLoop () (at Assets/WRMHL/Scripts/Thread/Common/wrmhlThread.cs:114)

Could some one help us with this?
Thank you very much in advance.

Messages loss

Hi,

I just found your awesome project and now I'm trying to use it with my arduino project, but I'm not sure to use it correctly.

If i use the following arduino code : https://gist.github.com/Ldoppea/5ae1ef4f6fce579cd00238687b9e86c5
And run the Unity WRMHLread demo project,
Then the unity console will display the following :

  • value : 100
  • value : 66
  • value : 32
  • value : 215
  • value : 183
    etc

A lot of messages are not received. What I would like is to receive:

  • value : 100
  • value : 99
  • value : 98
  • value : 97
  • value : 96
    etc

It seems like WRMHL only ensures the last message before an update to be received but does not ensure ALL messages to be received. Am I correct?

Is there a way to receive ALL messages?

Thanks

Android

Dosent work on unity android build because of mono ports.io not working and advice?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.