Devices & Components
Arduino Uno Rev3
Inertial Measurement Unit (IMU) (6 deg of freedom)
Multi-Turn Precision Potentiometer- 10k ohms (25 Turn)
Standard LCD - 16x2 White on Blue
Hardware & Tools
Breadboard, 400 Pin
Software & Tools
Arduino IDE
Project description
Code
digital level
c_cpp
first, it sets up the LCD and the gyro, than it takes the reading and displays it.
1#include<Wire.h> 2const int MPU_addr=0x68; // I2C address of the MPU-6050 3int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; 4#include <LiquidCrystal.h> 5 6// initialize the library with the numbers of the interface pins 7LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 8 9void setup() { 10 // put your setup code here, to run once: 11Wire.begin(); 12 Wire.beginTransmission(MPU_addr); 13 Wire.write(0x6B); // PWR_MGMT_1 register 14 Wire.write(0); // set to zero (wakes up the MPU-6050) 15 Wire.endTransmission(true); 16 Serial.begin(9600); 17lcd.begin(16, 2); 18} 19 20 21void loop() { 22 23Wire.beginTransmission(MPU_addr); 24 Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) 25 Wire.endTransmission(false); 26 Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers 27 AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) 28 AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) 29 AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) 30 Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L) 31 GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L) 32 GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L) 33 GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L# 34 35 lcd.print(" | X = "); lcd.print(GyX); 36 lcd.setCursor(0,1) 37; lcd.print(" | Y = "); lcd.print(GyY); 38delay(500) 39;lcd.clear() 40 41;}
digital level
c_cpp
first, it sets up the LCD and the gyro, than it takes the reading and displays it.
1#include<Wire.h> 2const int MPU_addr=0x68; // I2C address of the MPU-6050 3int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; 4#include <LiquidCrystal.h> 5 6// initialize the library with the numbers of the interface pins 7LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 8 9void setup() { 10 // put your setup code here, to run once: 11Wire.begin(); 12 Wire.beginTransmission(MPU_addr); 13 Wire.write(0x6B); // PWR_MGMT_1 register 14 Wire.write(0); // set to zero (wakes up the MPU-6050) 15 Wire.endTransmission(true); 16 Serial.begin(9600); 17lcd.begin(16, 2); 18} 19 20 21void loop() { 22 23Wire.beginTransmission(MPU_addr); 24 Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) 25 Wire.endTransmission(false); 26 Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers 27 AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) 28 AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) 29 AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) 30 Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L) 31 GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L) 32 GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L) 33 GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L# 34 35 lcd.print(" | X = "); lcd.print(GyX); 36 lcd.setCursor(0,1) 37; lcd.print(" | Y = "); lcd.print(GyY); 38delay(500) 39;lcd.clear() 40 41;}
Downloadable files
untitled
untitled
Comments
Only logged in users can leave comments