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

Hahaha it’s always something like that. That’s why I make myself all those questions. Even the basic ones like “is Arduino working?”, “is it receiving what I’m sending?”.
Glad you figured it out :slight_smile:

Hi guys… I’m an arduino pro, but a UE noob. I downloaded the current version of UE 4.19.2, I created a ‘Plugins’ folder within my project and drop the contents of the github project there. When starting UE, it complains about missing or out of date binaries. could it be my folder structure? or is 4.19.2 not supported?

my path is:
C:\Program Files\Epic Games\UE_4.19\MyProject\Plugins\UE4Duino

Hey! thanks for this plugin.

I have a litle problem with my Code, and I hope someone can help me. I’m changin’ de rotation of a character by an encoder, and, it works… more or less. The problem is the encoder makes too much ‘ticks’ with just 1 turn. I mean, it returns me like 2 or 3 ints, positive and negative, so… it fks me. I thinks is a problem with how encoders works, but I’m not sure. Someone knows how i can do this?

Unreal is telling you that you don’t have the binaries of the plugin compiled. You need VisualStudio (with c++) to compile them. Also, the engine only compiles code on code projects. In order to convert your project into a code project:

  • remove the plugin from it so you can launch the editor and open the project
  • go to File > New C++ class…
  • You can choose any class (just to add code to the project). I usually choose BlueprintFunctionLibrary because on most of my projects I end up needing one anyways.
  • After it compiles with the new class, close the editor. Your project is now a code project.
  • Add the plugin source files again and launch the project.
  • This time Unreal will ask you if you want to build the plugin. Say Yes.

If don’t want to do all that, on the latest plugin release there’s a zip with source/binaries for 4.19.2.

I don’t know what an encoder is, but it sounds like Arduino is sending information faster than the engine is reading. After each read on the engine, call Flush on the Arduino variable. That’ll clean up any extra information left in the serial port and, next frame, you read the latest information from Arduino.

Or, like many analog sensors I’ve used, it could be noise from the encoder (I still don’t know what it is, so I’m guessing). In that case, I’d filter the noise. A simple way to filter noise is to always add the latest value to a fixed size array and use the average from the values in the array. An array of length 5 should suffice. Most of the time, even less. You just have to keep track of the latest index you added to in order to keep cycling the array, always replacing the oldest value there.

Encoder is like an “endless potencimeter” that can check what is the direction of rotation. I’ve discoverd that the value I get depends of velocity of rotation, so… Im sure idk how to take int from arduino, but i solved it using a string wich printed the value of the int.

Now i have a new problem, i don’t know how to use more than 1 variable on unreal from arduino… and again, the value that “read int” returns is a fixed value, and not the value of variable I created on Arduino. I think I can use prints for everything i need, but it’d be interesting know how to use Ints, Floats…

Thanks for everything.

You’re welcome!

About the Ints and Floats from Arduino, they have to be broken down into 4 byte groups before being sent, respecting endianness. Then, using ReadInt etc in Unreal will re-group and interpret the next 4 bytes in the serial port. For examples of breaking ints and floats in Arduino and sending them to Unreal, take a look at the ArduinoTypesExample.ino file in the plugin folders. The float method in the example works for both floats and ints. The int method works only for ints.

For working with more than one variable, you can have synchronization problems. For instance, Unreal could start reading when Arduino has already sent 2 bytes of an int, making Unreal receive only the last 2 of them if you used flush on BeginPlay. And you should, because if you don’t, you might get all previous data in the port (and it could be a lot).
To solve the synchronization problem I use a “protocol”. I described this method in this post.

It works well. Thank you very much. ^^ Perhaps Is Bluetooth mode supported?

Wow… It’s hard to me get it… I’m trying to do what i want with this help, thanks. but again, I cannot choose what variable read with unreal. If I have 2 ints, for example, to use them in rotation Z and X, there is no method to tell unreal “Read int called Xrotation” or something like this…

Maybe I’m asking something obvious, but I’ve never use arduino before, and just got 2 month with Unreal. Students in practices life :D.

Tons of thanks, again, and sorry for this questions.

Ok… im trying to use your arduino code applied on my own code, and it doesnt work. I feel so useless xdd. I don’t understand how in 3 years there is no even 1 tutorial of how this plugin works

If you mean one board talking to PC via Bluetooth, I’ve never tried that. But I don’t think the plugin would do it, since Bluetooth is a different driver.
What I did once was make an Arduino wired to the PC communicate with another one via Bluetooth module on both boards.

I guess you’re lacking some knowledge of Unreal and Arduino. The examples are usually enough XD

Behind the courtains, the plugin works like this: it opens up a Serial Port and let you send and receive bytes through it. That’s the only thing the Serial Port understands: bytes.
So you can use this plugin to talk to anything that uses Serial Port, not just Arduino.
Now, knowing that you can only send and receive bytes, anything you want to do you need to know how to convert that from and to bytes. That’s the basic data unit in binary computers, so anything can be converted to/from bytes.
The protocol thing I told you about is a way for you to know when you are reading the first bytes of a sequence of fixed length. And inside that sequence you’ll have decided exactly which bytes are what.

Imagine a JPEG file, for instance. It have varied sizes, so in order for a JPEG reader software to know when to stop, there must be some bytes in a specific place in the JPEG format (protocol) that tells its size. That’s called the file header.

What you need to do is to define a format for the data you want to exchange with Unreal and, in Unreal, keep searching for the bytes that define the start of the data. When you find it, you’ll know exactly what comes after and how to read it. These first bytes are usually a sequence that should be very unlike to repeat in your data. Like 0xFF 0xFE 0xFD. That specific byte sequence must be a bit hard to find in random data.

The Read/Write Int, Floats and whatnot functions are just methods I left there to ease the conversion of those formats to and from bytes. But the only thing going through the serial port are bytes.

Hello All :-/ Need some help here.

I’m doing a beginner course in arduino and i thought combing it with UE4. after some digging on line i found this (ue4duino) great plugin.

my simple project is when i click on the arduino button a light will turn on a spotlight in the Unreal Scene.

I already set up my scene in UE4, and when i click the button on the arduino, it fires “0” or “1” to the arduino console.

when i PLAY the scene in the UE4, there is somtimes Flickering light. but it doesn’t stay consist.

I tried to followed the instructions but i guess im missing something.

Im Newbie both to UE4 and Arduino.

im using WIN10, Arduino Uno R3, UE 4.18.2

any help will be very appreciated.

10X

I don’t mean, the internal logic. I mean how to do things works with it xd. I’ve been using unreal 2 month, coming from unity. I can use it, but arduino… just 2 weeks. I did somes interactions like turn on and off a led from unreal, or make a rotation of the character. but not the correct way. Last day I could check the value of a int from arduino in unreal, but it change whenever it wants, not exaccly when i changed it, so…

And again. u cannot select what variable are u using. If i have 2 inputs in arduino and i want to change X rotation and Z rotation, in unreal, with your plugin, there’s no way to say “check variable called Xrotation” for example. xd

Tell me where im wrong…

You’re reading String from Arduino and converting to int. But your string also contains "
", which is most likely being converted to 0, thus turning your light off.
If you really want to send line breaks from Arduino, use "
" and, in Unreal, read it with ReadLine.
Just to make sure, debug your Blueprint with a break point in the “SetIntensity to 0” node and see when it’s getting called.

Sorry, but it looks like you didn’t read anything I wrote. I already told you twice why you can’t have separate variables and how to work like if you had them.
If you want a Ctrl+C, Ctrl+V ready solution, someone else will have to help you. I already gave you directions of how I deal with several variables from Arduino.
Or, if you’re willing to pay, I can help you personally through Skype/TeamViewer.

Man, I can understand, more or less, why u cannot use 2 variables like this, i just confirm it. The problem is 1 I need somehow to do it. 2, with BP i sent u there return a value of 100000. aprox, when in arduino it start at 50. Then, i change the way. I used Get(0) and then transform it to int. It seems to work, but when I stop the input, I got return a random value, so… this rotation has problem xd.

Sorry for be a dumb guy who is trying to understand something never seen.

Read this post I wrote about the protocol scheme. And use a byte array to send to Unreal as many values as you want. In unreal, after finding your first bytes (read that post), you’ll know where your other desired bytes are to retrieve your variables.

The BytesToInt function is your friend here, but don’t use it directly on ReadBytes. You don’t know how many bytes you are reading and you need only 4 to make an Int. Also, flush the serial port after opening it, otherwise you’ll be reading all the data sent from Arduino before the BeginPlay event in the engine. And, last but really important, USE THE PROTOCOL scheme described on the aforementioned post. If you don’t, you’ll never know if the 4 bytes you are reading are from the same Int. You could be reading the last 2 of an Int and the first 2 of the next one. Arduino and Unreal won’t work in sync, that’s why we use a protocol. To find when the next package of data starts and make Unreal read your values from their actual beginning.

@RikuShadow97 also, you could try printing lines from Arduino and using the read line function in Unreal. Then, your strings could be like: “variable1”, “50”. Then you can check if the string is the name of your variable and convert the next string to an Int. You can still very likely get just a piece of the data still, like “vari” and then “able1”, by reading before Arduino finishes writing. That’s why the protocol idea is still the best way.

My first try was like that. But it wasn’t the value wich I wanted to use, it was like millions. I get a solution, but it was meh. I’ve already did the flush after open serial. I’m gonna check the post.

Thanks again.