This week we tried reading and analyzing data from a sensor
I had zero ideas for what to make, so I decided to just start working on my final project as it requires readings from a gyroscope. You can read more about the project here.
I started by first connecting the MPU6050 to an arduino.

(take note that the arduino used in reality is the Arduino Nano, not the
Arduino Uno as shown in the picture)
Then I used the test code provided at Dratek.cz to test the sensor. The code can be found
here.
However, later it turned out the library reccommended by Dratek.cz was not the best one to use.
While it was working fine in in the main file, it broke as soon as you included that library in another file.
This was a problem as I wanted a clean and readable code so I wanted to split the gyroscope code into its own file.
After many hours of debugging, I found out that the library was the problem.
I switched to a different library and it worked fine.
Here is the library I used: https://github.com/ElectronicCats/mpu6050
After successfully reading the data from the sensor, I started working on proccessing the sensor readings.
I wanted to recognize which side of the gyroscope was facing up. However, I quickly stumbled upon another problem.
I was reading the rotation of the gyroscoope in euler angles, but I didn't remember are prone to a problem called gimbal lock.
This means that the gyroscope can get stuck in a position where it can't rotate anymore.
This is a problem as I wanted to use the gyroscope to detect which side is facing up, no matter the rotation.
Luckily this had a simple solution of using quaternions instead of euler angles. I took me quite a few hours to
figure it out though.
While in the process of solving the gimbal lock problem, I realized i needed a better debugging tool then just the Serial monitor.
I wanted to visualize the data in 3D, so I connected to the Arduino a oled display to better show the rotation of the gyroscope.
Thanks to the I2C protocol, I was able to connect the display to the same pins as the gyroscope.
