Announcement

Collapse
No announcement yet.

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

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

    I made a quick tutorial for using this plugin: https://www.youtube.com/watch?v=XvfG56fa_Lk Thanks for making it!
    Best, Shaun

    Comment


      Hey RVillani, thanks a lot for this plugin. It works very well so far, I also have some questions:

      1. Is it possible to detect if a port is connected to an Arduino device? I'm finding open ports to other devices with "Open Serial Port" (I hoped to make an auto-detection for the Arduino port)
      2. Losing parts of the message seems normal from what I read here? Or is it speed related? (Read about the protocol method)
      3. Sending strings through pressing a button on my Arduino board delays the message longer and longer, the longer I press. Say I press the button down for 5 seconds. I'll have a good half a second of delay where message are still arriving in Unreal. While if I press the button just quickly, it also instantly stops in Unreal again.

      Cheers!

      Comment


        IntervideoFilm
        1. Serial communication is kinda neutral to Windows. It can't recognize devices. What you could try is to send some message to the device and expect a specific response to confirm it is the one you want.

        2. It's write/read speed related. If you flush before reading everything, you'll lose what haven't read yet. Unless you open the connection in Arduino and Unreal with different baud rates. Then I guess you might really lose stuff because both devices are talking and listening completely out of sync.

        3. That might be a problem with how you are reading in Unreal and your Arduino code. If, in Unreal, you expect a line ender, like with ReadLine, it'll wait until one is found. Then, if in Arduino you are only sending the line ender after you release the button, you're halting everything.
        Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
        Unreal products: Dynamic Picture Frames, Neo Kinect

        Comment


          Hey RVillani

          1. Ah, I see... That's what I'm doing right now, sending a message every second.

          3. I actually read about "bouncing" in regards to buttons. It might be that. There's lots of stuff to find with Google in regards to it.

          Thank you for the quick answer!

          Comment


            all i need is to start the arduino and that's it. i dont need input from arduino all i need is when i press play, the arduino starts. how do i do that? thanks

            Comment


              Hi,

              Are you planning a 4.21 release for the plugin?

              Comment


                Originally posted by BusterKen View Post
                all i need is to start the arduino and that's it. i dont need input from arduino all i need is when i press play, the arduino starts. how do i do that? thanks
                What do you mean by start? Arduino starts by plugging it to any energy source, like the USB port. Do you mean send a command to it for it to start something? If that's it, use the Serial class' Write*** nodes. Check the OP for example images.
                Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                Unreal products: Dynamic Picture Frames, Neo Kinect

                Comment


                  Originally posted by Ivan.Phelan View Post
                  Are you planning a 4.21 release for the plugin?
                  I don't rush to it when a new engine version comes along because the source is on GitHub, so anyone can compile it. But there you go, buddy.
                  Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                  Unreal products: Dynamic Picture Frames, Neo Kinect

                  Comment


                    Originally posted by RVillani View Post

                    I don't rush to it when a new engine version comes along because the source is on GitHub, so anyone can compile it. But there you go, buddy.
                    Thanks very much, appreciate it.

                    Comment


                      Hi

                      How do I send Hex values via this plugin?

                      I'm trying to use this to communicate with a FTDI device (USB device that converts into a COM port) It is a speed and heart beat reader for a thread mill.
                      Windows is connecting to it via COM3. 57600 baud. In Unreal I can connect to the device with this plugin, so everything seems fine.

                      The protocol for this device tells me to send 0x44 to start the device, then 0x36 to set the output sample rate, and 0x0A to set this rate to 10 samples /sec and then 0x38 to get it to start sending data.
                      The paper tells me what data to expect in return from these commands, also given in Hex.
                      It says I could send the decimal ekvivalent, eg. 68, 54, 10, 56.

                      What node should I use to send this? Write a Byte? Write Bytes? I have tried some of them, but don't get the expected result.

                      A led on the device flashes when I send commands, so I am pretty sure I have a connection.

                      Any advice is greatly appreciated!

                      Thanks, Ole

                      Comment


                        Originally posted by Ragatune View Post
                        What node should I use to send this? Write a Byte? Write Bytes?
                        You are assuming correctly. Each of those is a byte, so Write a Byte. Do use the decimal equivalents, because Unreal only understands decimal in its node fields.
                        Right after you Write a Byte, if you call Read Bytes, does the array comes empty? Did you try to delay before reading the device's answer? Maybe you're just expecting the answer too soon?
                        I'd try it with a Read Byte on Tick for a while after sending a command. To see how long it takes to answer.

                        I recommend using Flush before sending a command, just to make sure there're no previous bytes in the read stream waiting to be read. Because that could look like a command answer, but would just be stuff that was sent before your command.

                        Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                        Unreal products: Dynamic Picture Frames, Neo Kinect

                        Comment


                          Originally posted by RVillani View Post

                          "...Write a Byte. Do use the decimal equivalents, because Unreal only understands decimal in its node fields..."
                          Thank you ever so much! I tried this, and it actually works!
                          I send 68 as one byte, then 54, 10 and finally 56. Then my device starts sending data! ( I also get some correct response bytes when sending the 3 first commands)

                          I have set up a Read Bytes - node in the Tick event. It seems to get the correct data back.
                          The device sends 16 bytes of data, including speed and heart rate. I can decide how often it sends this info, so now I just have to find a good balance of it sending the info and Unreal trying to read it.
                          And then teach Unreal to decode 3 separate bytes of numbers to a float that I can use in my application :-)

                          Thanks again for the info! And thank you for maintaining this plugin!

                          Ole

                          Last edited by Ragatune; 03-04-2019, 07:12 PM.

                          Comment


                            Originally posted by Ragatune View Post
                            And then teach Unreal to decode 3 separate bytes of numbers to a float that I can use in my application :-)
                            3?? That's kinda odd.
                            Anyway, if you need to convert 4 bytes to int or float or from those into bytes, there are nodes for that in the plugin too. BytesToInt and IntToBytes. Same for float.

                            Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                            Unreal products: Dynamic Picture Frames, Neo Kinect

                            Comment


                              Originally posted by RVillani View Post
                              3?? That's kinda odd.
                              Yes, it is!
                              Here is the data string I now successfully receive (from the manual of the device):

                              "The data string/packet is 16 bytes long. The data string/packet
                              starts with 26 00 decimal (1A 00 hex) then 14 bytes of data.
                              Example : 1A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 (hex)
                              Data string description (HEX):

                              1A 00 | 00 00 00 | 00 00 00 | 00 00 00 00 | 00 00 00 | 00
                              ACK...| Vertical...| Speed.....| Run Time....| Horizont. | Heart Rate

                              ...
                              SPEED: Speed of running belt in yds per second. 3 bytes. 00.000-99.999 Yards/Second.
                              00. 00 00 format. Example: 04 03 5B = 4.859 yds per second. 04.(03 5B). 03 5B hex = 859.
                              ..."

                              It's the speed I'm mainly interested in.
                              You see it is coded in a non standard way with one byte before the decimal mark and two after.
                              So I have to take byte 6 to 8 and convert it in this way and make in into the speed of my camera in the VR simulation.

                              I'll take a look at your nodes and the C++ behind it. I guess I'll make my own blueprint node in C++ to do this. Since it is so "non standard" there is no reason that you have support for this in your plugin. But it is really neat that we can play with small hardware devices in this way!

                              Comment


                                Originally posted by Ragatune View Post
                                But it is really neat that we can play with small hardware devices in this way!
                                It is! I've used it to control lights and stuff like that from inside Unreal. Really cool.

                                That's a very interesting way to encode a float. The way I make my conversions in C++ won't help you with that, because it just breaks apart or put back together actual float/int bytes, in the way they are organized in memory.

                                I bet you've already came up with some algorithm for that, but in case you didn't, either in Blueprints or C++ I'd do it this way:
                                • Let's call the three bytes A, B and C. A is the integral part and BC the decimal one.
                                • A + (B * 256 + C) * 0.001
                                In Blueprints, I'd write that formula in a Math Expression node and convert it to a macro. That way it's easy to use it elsewhere and the Math Expression node makes it very performant.

                                EDIT: Actually, in C++ you can make that formula even faster: A + ((B << 8) + C) * 0.001f
                                Last edited by RVillani; 03-05-2019, 12:24 PM.
                                Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                                Unreal products: Dynamic Picture Frames, Neo Kinect

                                Comment

                                Working...
                                X