söndag 31 maj 2015

Arduino to Unity Project Part 2: Testing, testing



To start off my project I wanted to do a quick and dirty session with the goal to set up a connection between the Arduino IDE and Unity. For this session I had the following equipment:


Hardware:

1 An Arduino Uno microprocessor
2. A Breadboard and Cables
3. a 3-Pin Button
4. a LED-lamp

Software:
1. Arduino IDE
2. Unity 4


Arduino to Serial:

I started by setting up a simple Arduino sketch for using the 3-pin button as a sensor to turn the LED-lamp OFF/ON. I used an example sketch available in the Arduino IDE called Button. There is a tutorial for it here: http://www.arduino.cc/en/Tutorial/Button


 For the wiring a simply used the schematics provided from the retailer where I bought the button:



I also printed the "1" if the button was pressed and "0" if it was open.

This was the result:


Arduino to Unity:

For this part I followed this tutorial: https://www.youtube.com/watch?v=of_oLAvWfSI
I altered the code to write to the serial port. Same as before (1 for button pressed and 0 for button open). I then opened Unity and wrote a C#-script which 

1. Opens a connection to the indicated serialport and reads 1 byte from it.
2. If the byte is 1 the script calls a Translate function and tells it to move to the left. How much it moves depends on the time of the loop. (Everything in both Arduino and Unity-scripts works in a big loop which runs one time per frame).

And then comes the amazing part:
Once you have done the script you just drag it onto  the Unity-asset you want it to control! This might be old news for someone with some experience with Untiy. However, for me this was a very pleasent surprise.

Now I could do this:

Testing Unity Controls

Next I tried to alter the Unity script to do other thing than moving the cube:





Seems to work pretty good!
Now I need more buttons!
















onsdag 27 maj 2015

Arduino to Unity Project Part 1: Project Specification

Computer graphics and interaction DH2323
Project Specification:

Alternative input modalities for interaction in Unity

Evert Lagerberg

Background:
Unity is a powerful open source game engine, which comes with many helpful features for creating interaction. For example, to simulate that the player is controlling a character in a first person perspective, we can just drop a camera object into our Unity scene. This gives us the functionality to move the placement of the camera around in the scene with the arrow buttons of the keyboard, and rotate the camera around  the Y and X axis’s with the mouse. But what if we wanted to design how the physical user interacts with the game world. What if we wanted to use other physical sensors or other input modalities to interact with the game world?

Ardouino is a open-source platform which consists of a circuit board with a programmable microprocessors and various sockets for input and output. The inputs can be used to connect sensors to the arduino and the output to connect actuators. Through the Arduino IDE we can program the microprocessor to tell it how to react on sensor input. Arduino allows us to quickly build prototypes for interactive electronic objects.

Problem
Investigate how the Arduino platform can be connected Unity to send input data from the sensors connected to the Arduino. Evaluate the usability(accuracy, satisfaction, stability) of a hardware prototype input system based on a Arduino-to-Unity-connection.

Project plan:
  1. Acquire the necessary hardware components
  2. Solder and connect cables to set up hardware prototype
  3. Investigate how to have the Arduino IDE send input data to Unity, then implement.
  4. Investigate how to connect input data to controls in unity. Then implement.
  5. Investigate how to control objects, cameras in a Unity scene.

Evaluation:
The project will focus on creating a proof of concept prototype of a hardware input system to control objects and camera in Unity. The evaluation of this system will primarily be a technical documentation of how well the connection from Arduino to Unity works. If the prototype works well enough I can do user tests with 1-2 user and interview them about usability.

Limits:
I will start with trying to implement the control of the camera in unity with a thumb stick connected to the arduino (Like an analog stick of a modern game console). The thumb stick can be moved in Y and X axis so this input can be used the camera in for directions. If I have time I will implement a second thumb stick to control rotation of the camera around the Y and  X axises. If I have more time I would like to add other sensors and use them as controls, for example a pressure sensor to act as a button.

Documentation:

I will keep a diary of the progress of the project on my blog: http://evertlagerberg.blogspot.se/