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

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.

I’m getting this message
UE4Duino-error.JPG

Fixed it. I should have read earlier, but it is important to have the latest VS version installed (free community version).

Hello everyone, I got the same problem as mikec156. But i couldn’t solve it by updating VS. Any suggestions on how to solve this problem?

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 ?

Hey Guys,
I’m Using the Plugin With UE 4.21.2. It all works fine in the Editor. But after Packaging the Project the .exe wont start.

I think i did every kind of solution wirtten here…

Is there anything to add?

While Packaging i get those Warnings ( see Images)

Thanks a Lot!

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

Greatings Games_master_jodan

Ok Ok. I had a hard time getting this plugin to work in a final build. But I did it and now I want to help.

Here is MY step by step succes formula:

Have the right visiual studio installed!

  1. Download the plugin (for your Ue4 version).
  2. Make a plugins folder inside your project.
  3. Place the plugin inside the plugins folder of your project.
  4. Start your project.
  5. Activate your plugin in the edit/plugins window.
  6. restart UE4
  7. Make something usefull with the plugin as shown in previous posts. Dont forget to close the port on endgame!!
  8. Go to edit/plugins ue4duino, You should see a package button.
  9. Package the plugin inside your ENGINE/plugins folder (this is somehow needed to get the versions matching (took me ages to get this right)).
  10. I repeat!! The plugin is now in your engine folder. The folder were your engine is installed (not your project folder).
  11. Delete the plugin inside your projects folder. Else you get same key stuff errors when building.
  12. Start Ue4, everything should work fine now with the plugin inside your engine folder.
  13. Package,Cook, build, compile or use pak files (no clue what all these words mean)
  14. Forget 13. just Package for win 64 developemen dont use pak files (you want to check something)
  15. You endup with a WindowsNoEditor/Engine/Plugins/Ue4Duino/UE4Duino.Uplgin file

Double click “projectname”/Saved/StagedBuids/WindowsNoEditor/“Your project-shortcut”

Now everything should work!

I am not a coder so maybe I talk out of my …

Please correct me when wrong!

Hope it helps someone.

Greetings

@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 :frowning:

I don’t know if anyone has posted this yet, but I’ve been trying to get reliable data from Arduino, to no avail.

Then, I stumbled upon 's ideaof having a protocol and made a similar setup. Hopefully, it’ll help someone.

On the Arduino, you need to add a “control” byte which tells UE where the data (float, int, etc.) starts:


Serial.write(0xFE);

After this, convert your variable into an array of bytes:



float floatVal = 23.56;
byte *b = (byte *)&floatVal;

Serial.write(0xFE);

int i;
for (i = 0; i < 5; i ++){   
    Serial.write(b*);
}

Then, in UE, you check for the control byte, then reassemble everything (minus the control byte):

Everything works like a charm, no more garbled data.
Hope this helps!

1 Like

That’s cool! Thanks!
I suggest two improvements:

  1. 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.
  2. 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.

Great, thanks for the tips, !

Hello ,

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


PrivateDependencyModuleNames.AddRange(new string] { "UE4Duino" });

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.

Cool project.

Do you plan to add the HID protocol support too ?

I wrote this to be able to do that in Arduino-side:

And I am using this: https://www.codeproject.com/Articles…ices-using-HID for PC-side

But I wonder if we can bypass it and do it in UE4 directly with your method.

@

Thank you. I did not know that. My stuff builds now.

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. :slight_smile:
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 :smiley: