It’s what you said. A sync issue. Unless you are losing data in between strings, than that’s another issue that I haven’t seen.
Try appending the strings you get from Arduino to each other, until you have the complete “phrase”. It’s common to get them in pieces, because of the sync issues. Unreal can be reading before Arduino has finished writing. So append, wait for next read, append again and check for the prefix/suffix. Once you find those, remove what’s before the suffix and keep appending next reads to the string. That way, your string variable will be like a buffer that you remove completed strings from.
And never use Flush! Read until there’s nothing to read. Flush will empty the serial and delete strings you had yet to read.
Actually, just flush once when you open the comms with Arduino, to clear previously accumulated unread data in the serial, before you start reading.
Are you trying to use it on a code project or Blueprint only? If blueprint only, you need the version with the binaries compiled for your UE version. Perhaps you downloaded only the source code.
@ i used UE4duino plugin i just wanna ask that if i need to move a third person character do i have to do coding at both ends or just open the port ? like i really dont understand how to move a third person character should i code in arduino IDE or inside unreal engine character blueprint or inside level blueprint ?
The only logic you should do in Arduino is to send input to the PC. Think of it as if you were creating a generic controller to use in any game. It should output things like “analogX=-0.5; analogY=0.23”.
Then, in Unreal, you code to make it understand that “controller” input. I’d do that in a Blueprint that doesn’t need to know about your specific character. It just outputs the inputs from Arduino. That way, you could use that Blueprint for any project with your custom Arduino controller.
Then, after that is set up, you create a GameMode Blueprint, a PlayerController Blueprint and a Character/Pawn Blueprint.
Make the GameMode’s default classes be your custom PlayerController and Character Blueprints. Then, on your PlayerController, you use the inputs Blueprint to send commands to your Character Blueprint. Your Character Blueprint will have functions like “MoveForward”, “Jump” etc, and the Player Controller calls those functions on it when the correct inputs come from the Arduino Blueprint. This way, your Character is not tied to one specific type of control, only your PlayerController is. And your PlayerController could be replaced by another one that controls your Character using different inputs. Or even control more Characters via possession/unpossession.
That’s why there’s this pattern of GameMode, PlayerController and Pawn in Unreal. To make things independent of each other and easily reusable.
If you don’t care about being organized, you could just make everything I just said in the Character Blueprint, but if you’d like to reuse it some day on another project, with a totally different character, you will curse your past self for it haha
Have you checked if you use the right port inside your device manager? arduino tools port? your timeout time is 5 (seems short to me). Have you printed something succesfully inside the arduin API with the serial plotter? I use this:
void loop(){
#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(2400);
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);}
}
Trying to help (I am not a specialist), so Hope it helps
@Ahmedck@Comkiled95@faos1970 Guys, the forums are bugged and I can’t see your DMs. It looks like you can’t see mine as well.
So please, if it’s not something private, send your messages here. You’ll also help others with the same questions.
Otherwise you can send-me an e-mail here
For some reason, @Ahmedck can’t post here. So here is his question. I hope someone can help him.
Hello i just want help with my school project as i dont have alot of time left i need to move the character inside unreal engine with the help of arduino and i am not able to do so i tried every way i could but i really dont understand how to link the character so it moves , i never used arduino i tried to find tutorials from all over the internet but i really dont understand how they link there unreal characters with i followed the tutorial provided by and the port got opened but i couldn’t move the character i was hoping that someone here could help me out with this and provide me with some blueprint or arduino as i am already approaching the deadline
use two control bytes, to make sure a single byte from the float doesn’t get interpreted as a control byte with the same value. Two in a row would be harder to happen.
on the for, check for i < 4. Right now you are trying to read until b[4], which is an invalid index for 4 bytes. I don’t know how Arduino recovers from that, but it would be a crash on PC.
I was trying to include the Serial.h file in a custom c++ class but I keep getting this error.
Error C1083 Cannot open include file: ‘Serial.h’: No such file or directory
I did make sure to add the path of the header file to my VC++ Directories include directories.in my project properties. Unfortunately Visual Studio still can’t find the header file.
I am using the latest version of UE4Duino.
Any help would be appreciated. Thank you and have a nice day.
You don’t want to change the project settings. Those will be overwritten when you do Generate Project Files (and we always have to do it again every once in a while).
What you need to do in order to use the plugin in C++ code is to add it to your module’s dependencies, in its Build.cs file.
For instance, if your project is called MyProject, it’ll be Source\MyProject\MyProject.Build.cs.
On that file, add “UE4Duino” to your PrivateDependencyModuleNames. So, if UE4Duino is the first module you’re adding there, it’ll look like
Unreal Build Tool will then understand you want to use the UE4Duino module on your project’s main module and automatically know where to include and link stuff from.
Besides that, you need to have the plugin in a Plugins folder and enabled in your project.
That’s very interesting!
Well, lately I’ve been super busy with work, so I try to, at least, keep the plugin’s binaries and code up to date with new UE4 versions. But if you implement that in the plugin, do a pull request to the Git repo and I’d gladly make it a part of it.
Although, it looks like something only very advanced users would try, with the replacement of Arduino libraries and all.
Got it, thanks for the proposition I will try to do it cause I only know C# for now lol, I see so much potential with it, like including of VR controller support made with Arduino in UE4 directly, without the need of SteamVR and Windows driver USB setup, the dream