Announcement

Collapse
No announcement yet.

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

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

    #16
    I have been trying to get this to work for some time, not having any success. I have my Arduino outputting a stream of 1's and 0's depending on a button state. Using the serial monitor I can see that everything is working properly and that the output is clean and as expected. The issue I am having is getting that data into the blueprint. I want to use the input '1' to change the flicker speed of a light to .2 and I want '0' to reset it to the flicker speed of 1.0. I am not sure exactly how to do this within the Blueprint editor however.

    unreal_blueprint_2.PNG

    This was an educated guess on how it might work, but I really don't know. If "Selection" on the 'Switch on Int' node is set to 0 or to 1 the result is as expected however apparently I am either not getting the data into the blueprint, I am not handling it properly, or both. One thing to note is this is a constant stream of data, should I base it off of the Event Tick instead? Any thoughts?

    Edit: One other note, is that the serial port IS indeed opening, and the flow goes all the way to the end through the '0' option. This is regardless of value however, and only happens once. I need the value to be read properly and for it to repeatedly check the value and update it.
    Last edited by xG_V3RT; 08-31-2017, 05:08 PM.

    Comment


      #17
      jwsargent.me Why are you using LineEndToString?!?! It's description says "Converts a LineEnd enum value to String." It has nothing to do with reading data from Arduino. You want to use ReadByte, to read the next 0 or 1 from the Arduino. Right after it use FlushPort. Because if you don't and Arduino is sending data faster than Unreal is reading it (once at each frame), Unreal will start to get late in relation to Arduino.

      Also, how are you sending the data from Arduino? If it's using printl, forget it. That sends the numbers as characters, with line ends and ReadBytes will read each char of that message as a byte (not 0 and 1). So try using Serial.write(1) (or 0).
      Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
      Unreal products: Dynamic Picture Frames, Neo Kinect

      Comment


        #18
        RVillani I am using "Serial.write()" now, should output 1 or 0. Thanks for the help. I'll keep digging around and learning the Blueprint system.
        Last edited by xG_V3RT; 08-31-2017, 05:19 PM.

        Comment


          #19
          This is the code for my basic arduino 4xrelay board. I use a baut rate (arduino and Ue4) of 1200, seems enough to me. What ever I write to the serial it gets parsed as a integer (ParseInt). So... when I write 10 to the serial relay 1 gets switched off. When I write 11, relay 1 gets switched on. same for 20 21 30 31 40 41. There is no trickery just write according to the docs to the serial port. Works absolutely perfect for me and a big thanks to the creators of this plugin and Ue4. Hope it helps someone.
          The Code:



          // Basic 4 Realy board connection

          // Each relay is turned on and off when sending 10 11 20 21 30 31 40 41

          // You can here them click as there state changes from off to on and on to

          // off.

          // You will also see the corresponding Red LED on the 4 Relay board

          // light up when the relay is on.



          // define names for the 4 Digital pins On the Arduino


          // These data pins link to 4 Relay board pins IN1, IN2, IN3,IN4


          #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(1200);
          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);}
          }
          Attached Files
          Last edited by game_master_jodan; 08-31-2017, 08:47 PM.

          Comment


            #20
            Added binaries for UE 4.17 on GitHub
            Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
            Unreal products: Dynamic Picture Frames, Neo Kinect

            Comment


              #21
              HysiK That error means invalid Handle. It doesn't help much. Are you using the monitor with Arduino at the same time as you use it with Unreal? Because you can't open a COM port for two programs at once.

              game_master_jodan Nice one, man!
              Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
              Unreal products: Dynamic Picture Frames, Neo Kinect

              Comment


                #22
                Hi, I previously had a project working in Unity, I have jumped ship and would like to now have the following [ MyoWear Sensor ] working in UR4 with a little help from the URDuion Plugin. Please would some one take a little time to help me. ? I am happy to speak directly on a live chat / video chat to speed thing up and donate a little for your help.

                Please contact me asap.

                Comment


                  #23
                  Can I have some help creating the Blue prints / Functions / Variables Please?

                  Comment


                    #24
                    I've gotten the Blueprint to work and am able to control elements within the game engine now (Yay!)
                    However, I'm not sure if it's the Blueprint or what but I am getting a flashing every now and then even when the button is held down.

                    When I watch my serial monitor it seems consistent, but it's hard to tell. Is there a known issue with the plugin or maybe issues with how I have approached this that could do that, or should I focus on the hardware side of things?

                    Comment


                      #25
                      PolyBionics I answered you on Skype

                      Originally posted by jwsargent.me View Post
                      I've gotten the Blueprint to work and am able to control elements within the game engine now (Yay!)
                      However, I'm not sure if it's the Blueprint or what but I am getting a flashing every now and then even when the button is held down.

                      When I watch my serial monitor it seems consistent, but it's hard to tell. Is there a known issue with the plugin or maybe issues with how I have approached this that could do that, or should I focus on the hardware side of things?
                      Your Blueprint seems pretty solid to me. Is there some delay on the Arduino loop code? Because then, even with the button being held down, Unreal would read a non-zero byte on one frame and then, for several frames, read nothing (that gives you zero). So Arduino should be sending the bytes to Unreal at least as fast as UE can read them each frame. Or even faster (bytes wouldn't accumulate because you're preventing that with FlushPort, so no problem)
                      Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                      Unreal products: Dynamic Picture Frames, Neo Kinect

                      Comment


                        #26
                        This does not appear to work for ports over 10. This worked geat for lower ports but I don't have any available one the machine at work Is there a workaround?

                        Comment


                          #27
                          Hey,
                          I'm doing a C++ UE4 project. please assist me how to use this plugin in C++.
                          thank you

                          Comment


                            #28
                            Originally posted by Bawboc View Post
                            This does not appear to work for ports over 10. This worked geat for lower ports but I don't have any available one the machine at work Is there a workaround?
                            I've just tested in a packaged game using COM 13. Worked just fine. Look for errors in the Output Log to see what's not working.
                            Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                            Unreal products: Dynamic Picture Frames, Neo Kinect

                            Comment


                              #29
                              Originally posted by ricco_igle View Post
                              Hey,
                              I'm doing a C++ UE4 project. please assist me how to use this plugin in C++.
                              thank you
                              What's your understanding level of C++ in Unreal? Where are you stuck?
                              Freelancer Game Dev Generalist and Unreal Consultant | Portfolio
                              Unreal products: Dynamic Picture Frames, Neo Kinect

                              Comment


                                #30
                                Originally posted by RVillani View Post
                                [MENTION=484398]gaofei7439[/MENTION] That's weird. I did the same setup as you and this is what I got:
                                [ATTACH=CONFIG]149864[/ATTACH]

                                Are you sure the Arduino code was uploaded to the Arduino board?
                                Or maybe there's something else in your Blueprint consumig the characters by accident and ReadLine just works because it finds anything there, like the "\r\n".
                                Getting the exact same thing.
                                Using the provided script "ArduinoTypesExample".
                                It works on the Serial Monitor on the IDE if I type in "lines", but getting nothing on the UE editor. Lines comes out as blank, Float as 0.0 and Integer as 0.

                                I know the Arduino to UE communication is working, because I made a light turn on/off with a button using this example : https://www.arduino.cc/en/Tutorial/DigitalReadSerial

                                What I did notice is that typing the commands on the Serial Monitor only works if "No line ending" is selected, the other options return nothing. Could this be the issue since there is option for that in the "Write LIne End" in Blueprint?

                                Click image for larger version

Name:	39ef0964ab658636dfc64636174d003e.png
Views:	622
Size:	198.9 KB
ID:	1372067
                                Click image for larger version

Name:	96305d528dbe0f3c6cea4c41f5189a81.png
Views:	493
Size:	15.8 KB
ID:	1372068
                                ________________
                                Fabiano Friedrich

                                LinkedIn | fabianofriedrich
                                RevEngLab | www.revenglab.com
                                TZERO Architecture | www.tzero.org

                                Comment

                                Working...
                                X