Dhruv Jain

Interface and Application Programming

Connecting accelerometer board with a Unity app


In this assignment, we were supposed to write an application that interfaces with the input/output device that we made.

My final project is on a scuba diving harness using virtual reality. The idea for which, I highlighted in my week 1. It will contain a suspension mechanism, which will house the user and virtual reality application on oculus lift. It would also contain an accelerometer to recognize the swim gesture motions of the user and send the data to the oculus rift application. The application would then move the user accordingly.

For this assignment, I would show one thing that I am already working for this project - interfacing the acceelerometer board with the unity application on ocean simulation.

Fortunately, I was able to find a good underwater oculus simulation application on the internet called ocean-rift that saved a lot of my effort and made this assignment possible. I contacted the developer and received the code for the demo application, under the conditions that I credit him for his contributions. In this app (Figure 1), the person moves in the ocean full of flora and fauna. The person is actually moved with the keyboard strokes. Up, down, right, left for moving in the horizontal plane and shift and control for moving up and down respestively.

For this assignment, I decided to move the person more naturally, using the swim gestures that move the person. So, naturally, I decided to use the accelerometer, make my custom board and then try to interface it serially with the unity application. I faced a couple of problems, but finally got the code working. The problems were:

1. Controlling application layer with hardware layer: Board sends the code bit by bit over serial (See code, Figure 2). Unity reads the code using the readline (See code, Figure 3) which is much more complex than the hardware layer. It took a while to get the interface correctly.

2. I had to modify the unity app a bit to receive data from the serial port. Being new to Unity, it took a while for me to get comfortble with the application.

3. There was a certain lag caused in the application when I tried to receive data from the serial port. I figured it was due to the fact that I was reading data from multiple points in the app. Also, I couldn't find an event to check if the data is received in the serial port from Unity, so I decided to check for and read the new data every frame. The app runs at approximately 30 frames per second which is doable.

Once everything was working it looked great. For now, I only have two gestures, press down to move up and swim forward to move forward (Figure 4) but I plan to keep on improving and adding more gestures for the final project. On showing it to my friend wearing the oculus rift, he mentioned that the gestures do feel realistic but he'll be happy if there were more gestures.

Figure 1: Ocean-rift oculus app

Figure 2: A part of the arduino code

Figure 3: Unity receiving data from arduino over serial port

Figure 4: Testing the module - It works!