Announcement

Collapse
No announcement yet.

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

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

    #76
    Originally posted by Staffmc View Post
    I think that i've found a bug, i'm sending like 6 ints via
    Code:
    Serial.print();
    and in the console everything works fine but in ue4 the Read Line node tells me that there's nothing to read :/
    Code:
    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 '\r\n' 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.
    Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
    Unreal products: Dynamic Picture Frames, Neo Kinect

    Comment


      #77
      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

      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)--------------------------|

      Comment


        #78
        I recommend using Flush as soon as you open the port to make sure there's no data left to be read there.
        Code:
        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.
        Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
        Unreal products: Dynamic Picture Frames, Neo Kinect

        Comment


          #79
          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?

          Comment


            #80
            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

            Comment


              #81
              Originally posted by Staffmc View Post
              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
              Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
              Unreal products: Dynamic Picture Frames, Neo Kinect

              Comment


                #82
                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


                Comment


                  #83
                  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?

                  Comment


                    #84
                    Originally posted by alpinious View Post
                    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

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

                    Comment


                      #85
                      Originally posted by RikuShadow97 View Post
                      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?
                      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.
                      Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                      Unreal products: Dynamic Picture Frames, Neo Kinect

                      Comment


                        #86
                        Originally posted by RVillani View Post

                        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.

                        Comment


                          #87
                          Originally posted by RikuShadow97 View Post
                          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.
                          You're welcome!

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

                          Comment


                            #88

                            It works well. Thank you very much. ^^ Perhaps Is Bluetooth mode supported?

                            Comment


                              #89
                              Originally posted by RVillani View Post

                              You're welcome!

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

                              Tons of thanks, again, and sorry for this questions.

                              Comment


                                #90
                                Originally posted by RVillani View Post

                                You're welcome!

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

                                Comment

                                Working...
                                X