Individual Assignment:
1- Measure something: add a sensor to a microcontroller board that you have designed and read it.
Group assignment:
2- Probe an input device(s)'s analog and digital signals - Document your work (in a group or individually)
Link



1- Measure something: add a sensor to a microcontroller board that you have designed and read it.

For this assignment, I wanted to measure the readings from MPU6050 sensor and display it on the serial monitor. I will be using the At328p board that i made in the Output devices week. Using the MPU sensor is important in applications that require sensitive positioning like airplanes and drones. in order for the drone to be aware of its positon.

About MPU 6050


MPU6050 is a Micro Electro-mechanical system (MEMS), it consists of three-axis accelerometer and three-axis gyroscope. It helps us to measure velocity, orientation, acceleration, displacement and other motion like features.

The Board


I followed the same wiring diagram for this picture.


I connected the MPU to my PCB and uploaded this code to it that i found on github. It measures the Pitch and Roll.




// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with eBay Pro Mini, **no external pullups on SDA and SCL** (works with internal pullups!)
// A4 = SDA, A5 = SCL

#include
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
}

void loop() {

  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);  //send starting register address, accelerometer high byte
  Wire.endTransmission(false); //restart for read
  Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data
  int t = Wire.read();
  xa = (t << 8) | Wire.read();
  t = Wire.read();
  ya = (t << 8) | Wire.read();
  t = Wire.read();
  za = (t << 8) | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  Serial.print("roll = ");
  Serial.print(roll,1);
  Serial.print(", pitch = ");
  Serial.println(pitch,1);
  delay(400);
}


The Result




Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.