[Free][Windows only] UE4Duino 2 - Arduino (COM port) communication

Use this plugin to communicate with Arduino or other COM port devices on Windows.

The GitHub page contains the source code and binaries. I try to keep it always updated with latest Engine Launcher version.

UE 4.16 binaries download
UE 4.17 binaries download
UE 4.18 binaries download
UE 4.19.2 binaries download
UE 4.20.3 binaries download
UE 4.21.1 binaries download
UE 4.22.0 binaries download
UE 4.23.1 binaries download
UE 4.24.1 binaries download
All releases here.

How to use it
Create a Plugins folder in your project directory. Place the folder UE4Duino (the one that contains Source, Resources etc) in the Plugins folder.

You can use the Open Serial Port function and store the result in a variable

https://raw.githubusercontent.com//UE4Duino/master/UE4Duino/Example.jpg

Or create the Serial object yourself and open the port afterwards

https://raw.githubusercontent.com//UE4Duino/master/UE4Duino/Example2.jpg

Either way, never forget to call ClosePort on the Serial instance before quitting the game. EndPlayEvent is a good place for that. If you forget to do it, you’ll have to unplug the Arduino (or other COM device) from the PC and plug it back.

You can set the type of line endings used with the WriteLine function.

https://raw.githubusercontent.com//UE4Duino/master/UE4Duino/Example3.JPG

There’s an example Arduino script in UE4Duino/ArduinoTypesExample. It demonstrates how to send floats, ints and strings to Unreal.

https://raw.githubusercontent.com//UE4Duino/master/UE4Duino/Example4.JPG

https://raw.githubusercontent.com//UE4Duino/master/UE4Duino/Example5.JPG

Credits
Original version of the plugin was created by @gryzly32
Thread for first version here.

2 Likes

This is absolutely neat stuff. I love microcontroller, psd’s, and fpga’s. Well done.

Thanks! Me too! :smiley:
It’s awesome when you make your game control real life electronics, lights etc.

Hey, really cool project! I’m having trouble using it though. I’ve installed it by placing it in a Plugins folder and everything. My problem is, when I go to add nodes in a blueprint, it seems that I only have “Open Serial Port.” I can’t find a Close Port, Read, or Write. New to Arduino and UE4, so I would be grateful if someone could walk me through this. Thanks!

Promote it to variable and drag from that.

Look at the first example image. Promote the return value from OpenSerialPort to a variable. Than call the other functions from that variable.
If you don’t know how to do that, or what are instances and variables, you should study a bit more the Blueprint system and maybe some Object Oriented Programing too.

Important question: Everything works perfectly fine in the editor. When I build the “windows no editor version” the port doesnt open… tryed with a delay or keypress but the port doesnt open and on the download page there there are 2 download versions 2.2.1 4.16 and 2.2 4.16.1 which makes it a bit confusing what is the newest.

Anyway don’t get me wrong, the thing is perfectly documented and I had a 3 step Fan working in half a day so thanks a lot!

Hope you can help with how to open the port on a windows no editor build.

And this is the warning: LogPluginManager:Warning: Engine version string in D:/Gebruikers/Gebruiker/Nieuwe map - kopie (3)/Unreal Projects/arduino_1/Plugins/UE4Duino/UE4Duino.uplugin could not be parsed (“4.16”)

Did some research myself, I guess this link is part of the solution, at least I hope.

BTW: I use arduino to 4x relay and UE4 version 4.16.2

I’ve used it a lot in packaged games, so I know it works. Are you sure you’re opening the correct port number on the packaged version? Or that the game or the Arduino IDE is not still using the port when you try it? Do you close the port when closing the game?

2.2.1 is the latest. I removed the engine hotfix version because C++ APIs don’t change between major versions, so the hotfix version doesn’t matter.

Just add " .1" at the end of the version string. (4.16.1)

I am confused; I want to konow does this plugin suit for UE4 4.16.2 . I have tested this plugin on UE4.16.2 ,and I used the Arduino code of example , But On UE4, The BP did receice somthing ,but diaplay nothing. I am in trouble for a few days, can you give me some suggestions? Thank you !

Yes, it suits. I am using it myself in 4.16.2.
Show me the code you’re using in Arduino and the Blueprint part.

I created the Arduino code as follows:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.setTimeout(5);

}

void loop() {
// put your main code here, to run repeatedly:

  Serial.println("this is the new line ");
  delay(1000);

}

And In UE4(4.16.2) I created a bp_cube (is this style ok?);


This is my bp , When the program is runing , I pressed button L , from the ue4 ,I can see , it indates it indeed receive some data ,but there is nothing display on the screen. and

can u tell me , how to solve it ? thank you

@gaofei7439 That’s weird. I did the same setup as you and this is what I got:
e5da7ad445ba14c54a50c003392704316a2f31fb.jpeg

Are you sure the Arduino code was uploaded to the Arduino board?
Or maybe there’s something else in your Blueprint consumig the characters by accident and ReadLine just works because it finds anything there, like the "
".

Is it worth adding whitelisted platforms to the plugin? For example “WhitelistPlatforms” : “Win64”, “Win32” ]

I have a Windows client acting as a server with the Arduino connection, but an Android app client that does not use but also can’t compile the plugin (can’t find AllowWindowsPlatformTypes.h )

Does this make sense or is there another way to compile an Android build when UE4Duino is included?

From what I found so far, WhiteList and BlackList doesn’t make a difference on compilation. The only way to make it not try to compile the plugin for Android is to remove the .uplugin file and re-generate visual studio project files, so it ignores the plugin completely. But then, if you are using it in other parts of the project, it’ll break your project. I guess you’ll have to do a project for PC and another separate one for the Android.

Hi all UE4Duino users and really thanks for your great work @ .
I am testing some arduino + blueprint codes without success so far and I kindly ask for help.


Those images are my Arduino code and my blueprint code, I do not know what I am doing wrong my main goal is sending from UE4 string ON to Arduino and Arduino must read it and activate 2 digital pins.
EDIT: LogTemp:Error: Failed to open port COM3. Error: 00000006 this is what I have achieved, COM port is not opening neither working. Have tried so far, 3 differents usb ports + hub (2 ad 3.0).
Any help? Really thanks and best regards!

I have been trying to get this to work for some time, not having any success. I have my Arduino outputting a stream of 1’s and 0’s depending on a button state. Using the serial monitor I can see that everything is working properly and that the output is clean and as expected. The issue I am having is getting that data into the blueprint. I want to use the input ‘1’ to change the flicker speed of a light to .2 and I want ‘0’ to reset it to the flicker speed of 1.0. I am not sure exactly how to do this within the Blueprint editor however.

This was an educated guess on how it might work, but I really don’t know. If “Selection” on the ‘Switch on Int’ node is set to 0 or to 1 the result is as expected however apparently I am either not getting the data into the blueprint, I am not handling it properly, or both. One thing to note is this is a constant stream of data, should I base it off of the Event Tick instead? Any thoughts?

Edit: One other note, is that the serial port IS indeed opening, and the flow goes all the way to the end through the ‘0’ option. This is regardless of value however, and only happens once. I need the value to be read properly and for it to repeatedly check the value and update it.

@jwsargent.me Why are you using LineEndToString?!?! It’s description says “Converts a LineEnd enum value to String.” It has nothing to do with reading data from Arduino. You want to use ReadByte, to read the next 0 or 1 from the Arduino. Right after it use FlushPort. Because if you don’t and Arduino is sending data faster than Unreal is reading it (once at each frame), Unreal will start to get late in relation to Arduino.

Also, how are you sending the data from Arduino? If it’s using printl, forget it. That sends the numbers as characters, with line ends and ReadBytes will read each char of that message as a byte (not 0 and 1). So try using Serial.write(1) (or 0).

@ I am using “Serial.write()” now, should output 1 or 0. Thanks for the help. I’ll keep digging around and learning the Blueprint system.

This is the code for my basic arduino 4xrelay board. I use a baut rate (arduino and Ue4) of 1200, seems enough to me. What ever I write to the serial it gets parsed as a integer (ParseInt). So… when I write 10 to the serial relay 1 gets switched off. When I write 11, relay 1 gets switched on. same for 20 21 30 31 40 41. There is no trickery just write according to the docs to the serial port. Works absolutely perfect for me and a big thanks to the creators of this plugin and Ue4. Hope it helps someone.
The Code:

// Basic 4 Realy board connection

// Each relay is turned on and off when sending 10 11 20 21 30 31 40 41

// You can here them click as there state changes from off to on and on to

// off.

// You will also see the corresponding Red LED on the 4 Relay board

// light up when the relay is on.

// define names for the 4 Digital pins On the Arduino

// These data pins link to 4 Relay board pins IN1, IN2, IN3,IN4

#define RELAY1 6

#define RELAY2 7

#define RELAY3 8

#define RELAY4 9

long mydata = 0;

void setup()

{

// Initialise the Arduino data pins for OUTPUT

Serial.begin(1200);
Serial.setTimeout(10);

pinMode(RELAY1, OUTPUT);

pinMode(RELAY2, OUTPUT);

pinMode(RELAY3, OUTPUT);

pinMode(RELAY4, OUTPUT);

}

void loop(){

while (Serial.available() == 0) {}
mydata = Serial.parseInt();
if (mydata == 10){digitalWrite(RELAY1,LOW);}
if (mydata == 11){digitalWrite(RELAY1,HIGH);}
if (mydata == 20){digitalWrite(RELAY2,LOW);}
if (mydata == 21){digitalWrite(RELAY2,HIGH);}
if (mydata == 30){digitalWrite(RELAY3,LOW);}
if (mydata == 31){digitalWrite(RELAY3,HIGH);}
if (mydata == 40){digitalWrite(RELAY4,LOW);}
if (mydata == 41){digitalWrite(RELAY4,HIGH);}
}

Added binaries for UE 4.17 on GitHub