Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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 RVillani 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
    Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
    Unreal products: Dynamic Picture Frames, Neo Kinect

    Comment


      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 RVillani's idea of 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:

      Code:
      Serial.write(0xFE);
      After this, convert your variable into an array of bytes:

      Code:
      float floatVal = 23.56;
      byte *b = (byte *)&floatVal;
      
      Serial.write(0xFE);
      
      int i;
      for (i = 0; i < 5; i ++){   
          Serial.write(b[i]);
      }
      Then, in UE, you check for the control byte, then reassemble everything (minus the control byte):

      Click image for larger version

Name:	Annotation-20200212-121724.png
Views:	440
Size:	159.6 KB
ID:	1720239

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

      Comment


        Originally posted by DickKickem. View Post
        Code:
        float floatVal = 23.56;
        byte *b = (byte *)&floatVal;
        
        Serial.write(0xFE);
        
        int i;
        for (i = 0; i < 5; i ++){
        Serial.write(b[i]);
        }
        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.
        Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
        Unreal products: Dynamic Picture Frames, Neo Kinect

        Comment


          Great, thanks for the tips, RVillani!

          Comment


            Hello RVillani,

            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.

            Comment


              Originally posted by COMET-35 View Post
              Hello RVillani,
              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
              Code:
              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.
              Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
              Unreal products: Dynamic Picture Frames, Neo Kinect

              Comment


                Cool project.

                Do you plan to add the HID protocol support too ?

                I wrote this to be able to do that in Arduino-side: https://www.codeproject.com/Tips/125...g-HID-Protocol

                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.
                Last edited by Fortnite50v50_; 02-17-2020, 11:03 AM.

                Comment


                  RVillani

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

                  Comment


                    Originally posted by Haeath View Post
                    Cool project.

                    Do you plan to add the HID protocol support too ?

                    I wrote this to be able to do that in Arduino-side: https://www.codeproject.com/Tips/125...g-HID-Protocol

                    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.
                    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.
                    Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                    Unreal products: Dynamic Picture Frames, Neo Kinect

                    Comment


                      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
                      Last edited by Fortnite50v50_; 02-27-2020, 01:38 PM.

                      Comment


                        I´m having trouble running UE4Duino. I created a new project and put ue4Duino (correct version) inside Plugins Folder. When I try to open the project it says "failed to load plugin ue4duino because module could not loaded" And the project closes. I tried with version 4.23.1 and also 4.24.1 (I downloaded the two engine versions)
                        Click image for larger version  Name:	Imagem1.png Views:	7 Size:	36.7 KB ID:	1729841

                        UPDATE:
                        I managed to solve it. If someone is experiencing the same, try this:
                        1. Check if Visual Studio is installed with "game development with C++".
                        2. Create a unreal blank project with C++ and not Blueprint
                        3. Create Plugins Folder under the project folder and put inside all ue4duino files without Binaries folder (delete it).
                        4. Wait until the unreal project load and select rebuild plugin, when asked.
                        5. After that, copy this ue4duino folder with your recompiled binaries to whatever project you want, including VR templates using only blueprints.
                          that is it!
                        Last edited by johnpaullima; 03-10-2020, 08:39 AM.

                        Comment


                          Hello,

                          Is it possible to use this plugin to wait for data from outside.

                          For example, sends a command from the PC to my device and then, wait for data or timeout reach.

                          What I see in some examples, it's write data to the serial port, add a delay and then, read data from the serial port. I would like to be blocked until I receive some data OR reach a timeout.

                          Thanks

                          Comment


                            Hi!
                            I would like to ask you guys, How to dynamically get the COM port number?

                            Click image for larger version

Name:	arduino.jpg
Views:	181
Size:	222.6 KB
ID:	1783606

                            Comment


                              Originally posted by Spyhabs View Post
                              Hello,

                              Is it possible to use this plugin to wait for data from outside.

                              For example, sends a command from the PC to my device and then, wait for data or timeout reach.

                              What I see in some examples, it's write data to the serial port, add a delay and then, read data from the serial port. I would like to be blocked until I receive some data OR reach a timeout.

                              Thanks
                              You NEVER want to block Unreal. Instead, write a timeout logic while trying to non-blockingly get the answer from Arduino. Something like
                              Code:
                              SendCommandToArduino()
                              {
                                  Serial.Print("some command");
                                  CommandTime = WorldRealltimeSeconds;
                              }
                              
                              Tick(float DeltaSeconds)
                              {
                              
                                  if (CommandTime - WorldRealtimeSeconds > Timeout)
                                  {
                                      SendCommandToArduino();
                                  }
                                  else
                                  {
                                      Response = Serial.ReadBytes();
                                      // Check if response is valid
                                  }
                              }
                              Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                              Unreal products: Dynamic Picture Frames, Neo Kinect

                              Comment


                                Originally posted by Muszti Projekt View Post
                                Hi!
                                How to dynamically get the COM port number?
                                This plugin doesn't do it.
                                I did it years ago for a Unity application, but I had to call code to read the Windows registry. Something like checking the names of the devices registered on all existing ports and using the first one that matched the Arduino device, if any.

                                I didn't do it for this plugin because I can't know beforehand all possible Arduino device names. I only did it on the Unity application because I was only gonna use a specific board, which I got the name from Windows' Device Settings.

                                Perhaps I could try to do it in the plugin and just return all names, so the burden to pick the right one would be on the final developer. It's not as beautiful as I like a plugin to be, but at least it would give users an option.
                                Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                                Unreal products: Dynamic Picture Frames, Neo Kinect

                                Comment

                                Working...
                                X