2016年6月15日 星期三

Unreal: Arduino Plugin For UE4

since: 2016/06/15
update: 2017/03/23

reference:
1. Plugin UE4Duino - Arduino to UE4 plugin Release!
2. UDK - UE4Duino Plugin
3. loveunrealengine | TIPS


A. 系統環境:
    OS: Windows 8
    UE: UE 4.10

-----------------------------------------------------------------------------------------------

B. Arduino
    1. 將 Arduino 連上電腦, 確認 COM port 的號碼(在此為 4)

    2. 設定好 Arduino 的板子序列埠

    3. 以燒錄器上傳 Arduino 的程式碼:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(random(1, 100));
  delay(1000); // wait for a second
}


-----------------------------------------------------------------------------------------------

C. Unreal Engine

   1. 到 Plugin UE4Duino - Arduino to UE4 plugin Release! 下載檔案:
       UE4Duino_4_10.zip
, 解壓縮後得到 UE4Duino 資料夾

   2. 新增空白的 UE 專案: UE4Duino_01, 在專案下新增 Plugins 資料夾, 並將剛剛的
       UE4Duino 資料夾放入.

   3. 開啟 UE4Duino_01 專案, 檢查 plugin:
       Edit > Plugins:

   4. 進入 UE4Duino_01 專案的 Level Blueprint, 在 Event Graph 修改如下:

   5. Complie Level Blueprint 後關閉 Level Blueprint,
      回到 Level Editor, 在 Content Browser 存檔(Save All) 後, Build -> Play

-----------------------------------------------------------------------------------------------

D. Turn the LED on /off

   1. Arduino:
int led = 13; // LED pin number
String content = "";
char character;

void setup() {
  Serial.begin(9600);
 
  // initialize digital pin 13 as an output.
  pinMode(led, OUTPUT);
 
  delay(1000);
 
  Serial.println("setup ok");
}

void loop() {
  delay(100); // delay in between reads for stability
 
  // UE4 Input
  while(Serial.available() > 0)
  {
    character = Serial.read();
    if(character != '^') {
      content.concat(character);
    }
    else {
      if (content == "ON") {
        digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
        Serial.println("turn the LED on");
      }
      else if(content == "OFF") {
        digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
        Serial.println("turn the LED off");
      }
      content = "";
     
    } // end of else
   
  } // end of while
}


   2. Unreal

   3. 結果:
       按下: o 鍵 ---> Serial Opened
                 h 鍵 ---> turn the LED on // HIGH is the voltage level
                 l 鍵 ---> turn the LED off // making the voltage LOW
                 c 鍵 ---> Serial Closed

-----------------------------------------------------------------------------------------------

E. UE4Duino 2.0

   1. Arduino:
void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
}

void loop() {
 // put your main code here, to run repeatedly:
 //Serial.println(random(1, 100));
 //Serial.print("#");

 Serial.print(random(1, 100)); // not need use
Serial.println
 //Serial.println("#");

 delay(1000); // wait for a second
}


   2. Unreal:

8 則留言:

  1. hey i have a question ... you just simulated in the blueprint ? you didnt insert a acton? because when i run the blueprint the modules didnt nothing explain me, thanks !

    回覆刪除
  2. Hi, have you checked UE4Duino Plugin is enabled? (checkbox is checked)

    回覆刪除
  3. yeah the plugin is active i checked the enable, any idea where else?

    回覆刪除
  4. 1. Your Arduino's Serial output may not analyzed correctly by Unreal. You may try simple Serial.print from Arduino, ex: only char or string but not use println.

    2. And if you use PintString output to screen in Unreal, especially in VR Mode, you may need to let PintString keep more time(I always set 30 second), because the PintString message is slow down to show.

    回覆刪除
  5. OK! thank you so much !...i will do it step by step hehe but my printString is not for VR Mode i use it only for my Print string Arduino and i hope see the char in the graphic window :)

    回覆刪除
  6. Hey friend i have a question in your finally blueprint ... i have problems with the keyboard can you help me because when i want pressed for example O for open serial didn't nothing, explain me thanks :)

    回覆刪除
  7. 1. Replace the "Event BeginPlay" node to "O" Key node
    2. Don't forget to close COM in "Event EndPlay" node
    3. If it don't works, unplug Arduino & plugin it again.

    回覆刪除

注意:只有此網誌的成員可以留言。