Bug is a very strong word lol
I guess you already know that, but Serial.println will be the one the plugin will consider to read everything before, because it sends the ’
’ break that ReadLine expects as a line break.
Also, are you certain that you are using the ReadLine function **after **Arduino has sent the all the data? Because the computer can read faster than Arduino can send, and then you’ll get either part of the data or even none of it.
The examples script I package within the plugin folder uses Serial.println and I use ReadLine just fine with that. But if I’m reading back from a command I’ve just sent from the engine, I wait for a small delay, to make sure Arduino has time to read the command and completely answer it.
Bug is a very strong word lol
Srry for using the word Bug, but i’m with this for like 6 hours and i don’t know what to do, here’s my ue4 code
Event Tick -> isValid? -> Print (snd) -> Delay(0.1) -> Read Line -> Print String (Arduino)----------|--------------|---------------------------| Event BeginPlay -> Open Serial Port -> Branch(True) -> Set Arduino -> Set WriteLineEnd Event End Play -> isValid? -> ClosePort (Arduino)--------------------------|
I recommend using Flush as soon as you open the port to make sure there’s no data left to be read there.
Event BeginPlay -> Open Serial Port -> Branch(True) -> Set Arduino -> Set WriteLineEnd -> Flush
Also use flush after Read Line. Just to make sure you won’t get the rest of what was not read in this call when you read it the next time.
By setting WriteLineEnd you’re just affecting the PrintLine function from the plugin, which you seem to not be using.
But those might not be the problem yet. What’s your loop frequency in Arduino? Do you use sleep to slow it down a bit? Is it receiving the whole “snd” string at once? It could be reading so frequently that it might be getting it in pieces.
I’m asking a lot of questions because those are the ones I ask myself when something isn’t working. To communicate with Arduino exchanging a lot of data is really cumbersome without some sort of protocol, because data might come in pieces all the time.
Loop frequency? The baud rate is 9600 and i’ve got to admit that the loop is a bit slower 'cause is making a lot of calculations (I’m using arduino mega). I don’t using sleep, and how can i know that its reciving the snd?
Thxs God it was a problem of mine not yours, now i’m reciving data (The problem was that i’ve used an if for a lcd that i wasn’t using that makes loop more slower.) Anyway thxs for your time
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
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.
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.
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.