Anyone had issues with the plugin where constant writing bytes to COM (lets say 90 times a second for 30 seconds) ends up making the write byte(s) funciton take 10ms of gamethread time. Using the write bytes function is even worse of an offender. At worst I’d like to write a total of 810 bytes (9*90Hz) a second…
Have you tried opening the connection with Arduino using higher baud rates? If I remember correctly, it controls the speed of communication.
Already at 115200, though even 9600 should be enough
I haven’t experienced performance problems like that, so I won’t be of much help to you. I still think it may be the way you are using it.
hey there i am currently working with a project i need to connect arduino to unreal engine developed game
unreal needs to send output like some values given to servos and arduino should recieve it and move the servo.
any help i am going to connect arduino with com port which will recieve the values through it
Hi Everyone,
I am really new to both Arduino and Unreal and although I am slightly getting everything now. Still I can’t really figure out the plugin (Definitely me ). My arduino code isn’t very complicated I think but I struggle to translate it to the nodes. I basically need two buttons to be read. I made it work in the Arduino code as follows:
// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin1 = 8; // the number of the pushbutton pin 2
const int buttonPin2 = 9; // the number of the pushbutton pin 3
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
void setup() {
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT_PULLUP);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT_PULLUP);
}
void loop(){
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
// read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2);
// check whether a pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
// turn LED on: // Tweet that the washer is done
Serial.print(“BP1=”);
Serial.println(buttonState1);
}
else {
Serial.print(“BP1=”);
Serial.println(buttonState1);
}
if (buttonState2 == HIGH) {
// turn LED on: //Tweet that the dryer is done
Serial.print(“BP2=”);
Serial.println(buttonState2);
}
else {
Serial.print(“BP2=”);
Serial.println(buttonState2);
}
}
Also I can’t seem to find all the nodes, for example ‘read read serial’ 'get arduino and ‘close serial’. So basically I am just struggling here. Could anybody help me out how to get started.
Howdy!
I got everything working with the example code, but I can’t figure out how to send data from UE4, like a float or int and stick that into a variable on the Arduino side of things. In short, I’m trying to get UE4 to control components on the Arduino board.
Thoughts?
Cheers,
Sterling
You can either send data as String with Print or PrintLine functions or use Write to send bytes. There are several write functions such as WriteInt and WriteFloat. But since Ints and Floats are 4 bytes each, Arduino will read those four bytes and you’ll have to convert them back to an int or float using C++ logic in Arduino. It’s much simpler to use just byte.
@saikat005 It means the binaries were not made with the same engine version you are trying to use them with. Try installing Visual Studio with the C++ features and letting the engine compile it for you.
@banjak15 To personally help you, I could give you consultation through Skype, but I charge for that. You can do it by making your character BP talk to Arduino directly. It could read values from Arduino and use those to set movement commands.
UE4.19.1
UE4Duino_2.2.1_4.19
Seems it not support UE4.19.1 yet.
Install Visual Studio with C++ features, generate Visual Studio project files (available through right clicking the .uproject file) and start the project. Unreal Engine should propose rebuilding of the plugin.
Also, set “EnabledByDefault” to true with Notepad++ in the UE4Duino.uplugin file, if you have not done that already.
Thanks! That’s exactly what can be done. Or else, I’d have to upload a new zip for each hotfix version of the engine. And we’re already in 4.19.2.
Don’t. There’s a bug (don’t know if it’s still there, but it was so in 4.18) in the engine that prevents the plugin from compiling if it’s set to EnabledByDefault and you use it in a component. Some people have reported it not compiling even used in the Pawn blueprint. It’s like the engine considers it’s not being used and doesn’t compile. Then the game fails silently because a connection with the Serial port is not made. It’s frustrating.
I think that i’ve found a bug, i’m sending like 6 ints via
Serial.print();
and in the console everything works fine but in ue4 the Read Line node tells me that there’s nothing to read
String str = Serial.readString();
if(str == "snd")
{
Serial.print(myIMU.roll, 2);
Serial.print("/r");
Serial.print(myIMU.pitch, 2);
Serial.print("/r");
Serial.print(myIMU.yaw, 2);
Serial.print("/r");
Serial.print(myIMU.ax, 3);
Serial.print("/r");
Serial.print(myIMU.ay, 3);
Serial.print("/r");
Serial.print(myIMU.az, 3);
Serial.print("/r");
Serial.print(v_flex1);
Serial.print("/r");
Serial.print(v_flex2);
Serial.print("/r");
Serial.print(v_flex3);
Serial.print("/r");
Serial.print(v_flex4);
Serial.print("/r");
Serial.println(v_flex5);
}
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.
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