[FREE] ArduinoKit - Cross Platform Arduino Plugin for UE4

New version available!

Hello all,

I’m working in some 4D projects that we need to interact with arduino to control external hardware… So, I made this plugin to help in my projects based on the serial library by Teunis van Beelen (RS-232 for Linux and Windows)

Its serial communication works in Windows, OSX and Linux.

The code is available at: Bitbucket

Just clone the repo and copy the “ArduinoKit” folder inside “Plugins” to your own “Plugins” folder.

I hope that it can be useful for some people.

Here are the nodes available:

For the port name, you need to write the full path, for example:

Windows: “COM3”
OSX: “/dev/cu.usbmodem1421”
Linux: “/dev/ttyS0”

Windows users only:
ports higher than “COM9” need to be on this format: “\.\COM10”, “\.\COM11”, “\.\COM12” and so on…

Info:

  • The Read Text Node pops the last string that was read from arduino. If nothing is found, it will return a blank string.

  • The Get All Available Texts Node will return the whole stack of strings that was read from arduino. The last one is the most recent. After you call this node, the stack is cleared.

  • All strings sent from arduino **must **have the ending character “/n” or use Serial.println () instead of Serial.print().

  • The Open Node now tries to close any previously opened connection.

  • The Open Node have a new input parameter that is the size of the stack that will hold all strings read from arduino. If it is filled, it will discard the oldest one and push the new one on the top of the stack.

Cheers

Hi!
I tested it and it basically works! Thanks. But I found a strange behaviour. If I print the String from the “Read Text” Node it looks alright, but as soon, as I try to convert this string to a float or int, the Values start to strangly jump around. Maybe the string is not correctly formated as it should be in unreal. I tried some conversions, but nothing fixed it.
Can you tell me how I can get a simple float send with the an arduino code like

float variable;
Serial.println(variable);

to be correctly stored into a float variable inside the unreal engine?

Thank you very much!

P.S: In the UE4Duino Plugin this woked without any problems. I am using win10 Unreal and Engine 4.12.5

Hello [MENTION=64722]Appsite GmbH[/MENTION],

the way my plugin works is a bit different. You will need to create a buffer holding the bytes until you have the whole string built. I just pushed a new code to the git repo actually removing the function ReadText() and adding the StringFromByteArray() to prevent others to try the samething you tried. The correct way using my plugin should be like this blueprint:

You create a array of bytes variable and use it as the buffer. Whenever you find a endingline character (byte = 10) you build the string and clear the buffer.

On the arduino side you can use this:

float variable = 123.45;
Serial.println(variable);

or

float variable = 123.45;
Serial.print(variable);
Serial.print("
");

The buffer example node is in the level blueprint on git repo.

I hope it helps!

PS: I’ll try to automate this step to read text whenever I get some free time :wink:

Cheers!

Fantastic! That works like a charm now. :slight_smile:

Really Great job !!
I need help, i have a problem with read Bytes !! i used your example to print the readBytes but no msg !!
(Im using 4.12.5 and win10 )

@brownoo, can you post your code?

If you could get this to support Android as well that would be amazing

this is my Code!! even my arduino not connected the wire from readbytes still red :frowning: nothing print on my screen !

Very strange. That should work… can you send me how are you printing into the serial from arduino?

@darthviper107 I’ll take a look on that! =)

Thanks alot ^^ !!

Try your blueprint with this code on arduino:


void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Serial.begin(115200);
  blink();
}
void loop() {
  delay(100);
  blink();
}

void blink() {
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);

  float variable = 123.45;
  Serial.println(variable);
}

Let me know if it works!

Cheers

@brownoo

I tried a few things here… the Editor keeps the connection opened after you stop the game execution. If you disconnect the arduino and connect again without closing the Editor or manually calling Close node, you will not be able to Open a new connection (the plugin is not detecting that you disconnected the arduino). Try to force a Close before you Open on BeginPlay.

Will check that bug later!

Cheers

I tried to force the close but same problem still reading with or without arduino any other solution ?

@brownoo I see that you port number is COM10+… try using this string: “\.\COM12”

Should look like this:

Open.PNG

Let me know if it works!

Unfortunatly, same problem :frowning: still reading !!

The read is called but it is returning a TArray<uint8> with size 0. It returns with size 0 when it’s not finding anything on the buffer or is not opened.

Can you show the arduino side?

Because using this code on arduino:


void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Serial.begin(115200);
  blink();
}
void loop() {
  delay(100);
  blink();
}

void blink() {
  digitalWrite(13, HIGH);
  delay(200);
  digitalWrite(13, LOW);
  delay(200);

  float variable = 123.45;
  Serial.println(variable);
}

And using the same node setup (and port “\.\COM12”) that you are using… everything works fine on my machine (win 10 + Unreal 4.12.5).

Can you also show your console log to see if you get:


LogTemp:Warning: UArduinoKitBP::Open -> Success

or


LogTemp:Warning: UArduinoKitBP::Open -> Failed

during the Open attempt

I tried your arduino code still same problem, i tested the serial communication with realtern it works !! even with the UE 4.9.2 :frowning:

LogTemp:Warning: UArduinoKitBP::Open -> Failed
PIE: Info Play in editor start time for /Game/UEDPIE_0_ExampleMap 1.09
LogBlueprintUserMessages: Late PlayInEditor Detection: Level ‘/Game/ExampleMap.ExampleMap:PersistentLevel’ has LevelScriptBlueprint ‘/Game/ExampleMap.ExampleMap:PersistentLevel.ExampleMap’ with GeneratedClass ‘/Game/ExampleMap.ExampleMap_C’ with ClassGeneratedBy ‘/Game/ExampleMap.ExampleMap:PersistentLevel.ExampleMap’

Yeah… its not opening the port with the arduino.

My last attempt is to change the associated port with your arduino in device manager…

Select your arduino and go to properties

Port settings

2.png

Advanced Button and change the port to a number lower than COM10 and use the regular string like “COM3” in unreal Open node

3.png

than disconnect and connect your arduino, check if it’s found and assigned to the right port and try the code inside Unreal.

If this doesnt work… I’m sorry… I have no clue why it’s not connecting =(