Motion Tracker With Arduino and Gyroscope Sensor

by RakaAmburo in Circuits > Arduino

156 Views, 0 Favorites, 0 Comments

Motion Tracker With Arduino and Gyroscope Sensor

start gyro instruct.png
gyroTest.jpg
Building a Precision Motion Tracker with Arduino and Gyroscope Sensor

Welcome again to this new Amburo tutorial. On this occasion, we will play a little bit with this extraordinary board. Many years ago I discovered this tiny little marble, this is a motion processing unit board or MEMS(Micro Electronic Mechanical Systems). As you may know, this board can feed an output of information about its movement this device is commonly known as a gyroscope. I got fascinated right away by the things that this thing can do. So the first question that came into my mind is how to demonstrate in a very simple powerful way how this thing works and how many things can be achieved by it. So many hours of searching led me to this interesting javascript 3D library:

https://threejs.org/

This javascript library can help you render 3D objects and move them by certain functions. By joining these two things I would be able to show the beauty of motion capture. But something else was missing... the remote feeding. So I added a Nodemcu instead of a simple Arduino to control and extract the information from this boar. This will allow me to detach the movement sensor device from the system that shows the movement. Leading me to whole new ideas that I will be presenting in the future.

Let me be clear, of course, am not inventing anything here. Am just puting things togehter. In order for you to build a very sophisticated system in a very innovative and simple way. So the idea is to find a way to somehow send the data feed by the MPU by the NodeMCU to the computer and then feed this information to the 3D object library making it move as the object board itself, so let's get into it.

So, first thing first. How are we going to send the information from the NodeMCU. In this instance, we can do many things. We can use a rest service, we can use UDP and also I think we can use web socket. In all cases, we will need as you may know a server and a client. Now I think in this case the most appropriate thing to do is to use UDP since we will have a continuous flow or stream of information. Bear in mind that we don't care if a minimal amount of packages are lost. We only need the continuous flow of incoming data representing the movement of the object. So the use of the UDP protocol will be the most efficient way to go.

I also liked the idea of WebSocket, because the protocol behaves more or less similarly to UDP and also will be a direct connection, NodeMCU(server) html/javascript client.

Supplies

gyrosupplies.png

For this project, we will need a NodeMCU (esp8266), an MPU board(6050 but you can use others), and a set of 4 cables to make the connections.

Diagram

finalDiagram.png

Here you have the diagram showing how the different components interact. So what will be the configuration for UDP? Basically, NodeMCU will send UPD packages, We will implement and UDP server in NODEJS that will redirect all the information received to the webpage with the javascript 3D library through a WebSocket connection. Then transform the information and feed the 3D library methods in order to make the 3D object move accordingly.

Diagram 2

gyroDiagram.png

A simpler diagram showing how this prototype will work.

Connections

gyroconnections.png

As you can see the wiring between the NodeMCU and the MPU is very simple, ground to ground, VCC to VCC, D7 to SDA(Serial Data), and D6 to SCL(Serial Clock)

NodeMCU Code

wire.png
setup.png
loop.png

As we did in the past we will include the required libraries for the esp8266wifi, the UDP library, and a new one (wire) that will be controlling the connection to the MPU board. The Wi-Fi credentials and variables will store data for the required movement calculations. Will set up the digital pins and other configurations for establishing communication with the MPU board. Begin the serial and wifi connection.

The loop will be receiving the information from the board and doing the math, this process is kind of complex, not going to dive deep into this now, and we will be breaking down all this in different tutorials.

Each loop will send the processed information through the network.

Git Repo

Server and Html Implementations

github.png
binding.png
socket.png
html.png

If we go to the gyro/serverUdpWebSocket in nodejsScripts you will see the structure of the project. We have the gyrodatatransportserver NODEJS file, which will be receiving the UDP signals from the NodeMCU, On top you will find the required libraries for the UDP, WebSocket, and a static HTML server. The bindings and processing of the UDP signal and the WebSocket configuration.

Once a single is received, if there is a connected WebSocket client established in line 38 the signal is forwarded to the WebSocket client.

In the js folder, you have the Three library minimized, you will find a link in the description to dive deep into it. In textures, you will find a couple of files that basically will define the appearance of the 3d object. Index has a simple redirect to the main HTML file gyroto3dobject.html, this file contains the scripts required, the Three library, jQuery, and the initialization functions. You will see that has some code to move the object with the mouse that is disabled, you can enable it if you want to play around by uncommenting those lines. Finally, the WebSocket will connect to the localhost with a main function that will process the incoming information containing the position of the object.

Gir Repo

Finally

newProtPic.jpg

As you can see in the final demo of the YouTube video, I have been working on an improved prototype, wireless, and assembled as one unified compact board. Also will try to enhance the capture of the movement by using a fifth-pin INT(interrupt).

In addition, I'm working on new tutorials to show how we can use this device to leverage another automation project for example gesture recognition and more interesting stuff alike.

See you in the next one.