Search Code

የMPU-6050 ዳሳሽ መረጃን በLCD 1602 ወይም LCD2004 ላይ ከአርዱኖ ጋር ማሳየት

የMPU-6050 ዳሳሽ መረጃን በLCD 1602 ወይም LCD2004 ላይ ከአርዱኖ ጋር ማሳየት

በዚህ ትምህርት ውስጥ፣ ከMPU-6050 ዳሳሽ የተገኘውን መረጃ በLCD 1602 ወይም LCD2004 ላይ እንዴት ማሳየት እንደምንችል እንማራለን። MPU-6050 ባለ 3-ዘንግ ጋይሮስኮፕ እና ባለ 3-ዘንግ አክስሌሮሜትር የሚያጣምር ሁለገብ ዳሳሽ ነው፣ ይህም እንደ እንቅስቃሴ መለየት እና አቅጣጫ ለመለየት ላሉ የተለያዩ አፕሊኬሽኖች ተስማሚ ያደርገዋል። ይህን ዳሳሽ ከLCD ማሳያ ጋር በማገናኘት፣ አንግሎችን እና የሙቀት መጠንን ጨምሮ የእውነተኛ ጊዜ ዳሳሽ መረጃን በዓይን ማየት እንችላለን።

በዚህ ፕሮጀክት ውስጥ ስንራመድ፣ አስፈላጊዎቹን የሃርድዌር ክፍሎች፣ የሽቦ ዝርዝሮች እና የኮድ አተገባበር እንሸፍናለን። ይህ MPU-6050ን እንዴት ማዋቀር እና ውጤቱን በLCD ላይ ማሳየት እንደሚቻል ለመረዳት ይረዳዎታል። ስለ ኮዱ ተጨማሪ ማብራሪያ ለማግኘት፣ ቪዲዮውን በ(በቪዲዮው በ00:00) መመልከትዎን ያረጋግጡ።

ሃርድዌር ተብራርቷል

ለዚህ ፕሮጀክት ዋና ዋና ክፍሎች የአርዱኖ ቦርድ፣ የMPU-6050 ዳሳሽ እና የLCD ማሳያ (1602 ወይም 2004) ናቸው። አርዱኖ ከMPU-6050 የተገኘውን መረጃ በማስኬድ ወደ LCD የሚልክ ማይክሮ መቆጣጠሪያ ሆኖ ያገለግላል።

የMPU-6050 ዳሳሽ መረጃን ወደ አርዱኖ ለመላክ I2C ግንኙነትን ይጠቀማል። እንቅስቃሴን እና አቅጣጫን እንዲለይ የሚያስችሉትን አክስሌሮሜትር እና ጋይሮስኮፕ ያካትታል። የLCD ማሳያ ከዳሳሽ መረጃ የተገኙትን አንግሎች ለማሳየት ይጠቅማል። እሱ ደግሞ በI2C በኩል ከአርዱኖ ጋር ይገናኛል፣ ይህም ሽቦን እና ግንኙነትን ቀላል ያደርገዋል።

የዳታሺት ዝርዝሮች

አምራችኢንቬንሰንስ
የክፍል ቁጥርMPU-6050
የሎጂክ/IO ቮልቴጅ3.3 ቪ / 5 ቪ
የአቅርቦት ቮልቴጅ3.3 ቪ እስከ 5 ቪ
የውጤት ዳታ ፍጥነት1 kHz (ከፍተኛ)
የሙቀት መጠን ክልል-40 እስከ +85 °ሴ
ፓኬጅQFN
ማስታወሻዎች / ልዩነቶችጋይሮስኮፕ እና አክስሌሮሜትር የተዋሃዱ

  • በተገለጸው የቮልቴጅ ክልል ውስጥ ትክክለኛ የኃይል አቅርቦትን ያረጋግጡ።
  • አስፈላጊ ከሆነ በI2C መስመሮች ላይ ፑል-አፕ ተቃዋሚዎችን ይጠቀሙ።
  • ከእርስዎ ውቅር ጋር ለሚስማማ የI2C አድራሻ ያረጋግጡ።
  • ትክክለኛ ንባቦችን ለማግኘት ዳሳሹን ይለካሉ (ካሊብሬት)።
  • የአጭር ዑደት ችግሮችን ለማስቀረት በሽቦ ሲሰሩ ይጠንቀቁ።

የሽቦ መመሪያዎች

arduino_wiring_MPU-6050_LCD2004_bb

MPU-6050ን ከአርዱኖ ጋር ለማገናኘት፣ የMPU-6050ን የVCC ፒን በአርዱኖ ላይ ካለው የ5V ፒን ጋር በማገናኘት ይጀምሩ። በመቀጠል፣ የMPU-6050ን የGND ፒን በአርዱኖ ላይ ካሉት የGND ፒኖች በአንዱ ጋር ያገናኙ። ለI2C ግንኙነት፣ የMPU-6050ን የSDA ፒን በአርዱኖ ላይ ካለው አናሎግ ፒን A4 ጋር ያገናኙ፣ እና የSCL ፒንን ከአናሎግ ፒን A5 ጋር ያገናኙ።

ለLCD ማሳያ፣ የVCC ፒንን በአርዱኖ ላይ ካለው የ5V ፒን ጋር እና የGND ፒንን ደግሞ በአርዱኖ ላይ ካለው የGND ፒን ጋር ያገናኙ። የLCDን የSDA ፒን ለMPU-6050 ከተጠቀመው ተመሳሳይ A4 ፒን ጋር፣ እና የLCDን የSCL ፒን ከA5 ፒን ጋር ያገናኙ። በዚህ መንገድ፣ ሁለቱም MPU-6050 እና LCD ተመሳሳይ I2C መስመሮችን ይጋራሉ፣ ይህም ሽቦን ቀላል ያደርገዋል።

ግንኙነቶቹ ደህንነታቸው የተጠበቀ እና ምንም የላላ ሽቦዎች እንደሌሉ ያረጋግጡ። የእርስዎ LCD ወይም ዳሳሽ ካልበራ፣ ሽቦውን እና ግንኙነቶቹን በድጋሚ ያረጋግጡ።

የኮድ ምሳሌዎች እና ማብራሪያ

በኮዱ ውስጥ፣ ለMPU-6050 እና ለLCD አስፈላጊ የሆኑትን ቤተ-መጻሕፍት በማካተት እንጀምራለን፦

#include 
#include 
#include 

እዚህ፣ ለሁለቱም MPU-6050 እና LCD አንስታንሶችን (instances) እንፈጥራለን። MPU-6050 ለI2C ግንኙነት በ`Wire` ቤተ-መጻሕፍት ይጀመራል፣ LCD ደግሞ በአድራሻው እና በመጠኖቹ ይዋቀራል።

በሴትአፕ ተግባር ውስጥ፣ ዳሳሹን እና LCDን እንጀምራለን፦

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  lcd.begin();
  lcd.backlight();
  lcd.clear();
}

ይህ ኮድ ለማረም ሴሪያል ግንኙነትን ያዘጋጃል፣ የI2C ግንኙነትን ይጀምራል፣ እና LCDን ለማሳያ ያዘጋጃል። ማሳያው እንዲታይ የጀርባ መብራት ይበራል።

በሉፕ ተግባር ውስጥ፣ ከMPU-6050 መረጃን በተከታታይ እናነባለን እና በLCD ላይ እናሳያለን፦

void loop() {
  mpu6050.update();
  lcd.clear();
  lcdDisplay(mpu6050.getAngleX(), mpu6050.getAngleY(), mpu6050.getAngleZ());
  delay(100);
}

ይህ ቁራጭ የዳሳሽ መረጃን ያዘምናል እና በየ100 ሚሊሰከንድ ለአዲስ ንባቦች LCDን ያጸዳል። አንግሎቹን በLCD ላይ ለማሳየት `lcdDisplay` ተግባር ይጠራል።

ለተሟላ ግንዛቤ፣ ሙሉ ኮዱ የሚታይበትን ተጓዳኝ ቪዲዮ ይመልከቱ (በቪዲዮው በ00:00)።

ማሳያ / ምን እንደሚጠበቅ

ሁሉም ነገር በትክክል ሲዋቀር፣ LCD ለX፣ Y እና Z ዘንጎች አንግሎችን በእውነተኛ ጊዜ ማሳየት አለበት። ለውጦቹን በማሳያው ላይ ለማየት የMPU-6050 ዳሳሹን ማዘንበል ይችላሉ። ችግሮች ካጋጠሙዎት፣ በሽቦዎ ውስጥ የተገላቢጦሽ ፖላሪቲ መኖሩን ያረጋግጡ ወይም የI2C አድራሻዎች በትክክል መዋቀራቸውን ያረጋግጡ።

በLCD ላይ ያሉትን እሴቶች መከታተል ዳሳሹ ለእንቅስቃሴ እና ለአቅጣጫ ለውጦች እንዴት ምላሽ እንደሚሰጥ ለማየት ያስችልዎታል። እሴቶቹ የማይንቀሳቀሱ ወይም የተሳሳቱ ከመሰሉ፣ ግንኙነቶቹን ያረጋግጡ እና ዳሳሹ በትክክል እየሰራ መሆኑን ያረጋግጡ።

ምስሎች

arduino_wiring_MPU-6050_LCD2004_bb
arduino_wiring_MPU-6050_LCD2004_bb
LCD2004_display-3
LCD2004_display-3
LCD2004_display-1
LCD2004_display-1
LCD2004_display-2
LCD2004_display-2
119-Arduino code for MPU-6050 accelerometer and gyroscope sensor (angles only)
ቋንቋ: C++
/*
 * 
 * This code is basic usage of the MPU-6050 accelerometer and gyroscope.
 * Running this code, you will get angles only.
 * The angles at X, Y, and Z are displayed on the LCD2004-I2C display module.
 * 
 * Library and code have been taken from:
 * https://github.com/tockn/MPU6050_tockn
 * 
 * Updated by Ahmad Shamshiri on July 07, 2018 at 13:43 in Ajax, Ontario, Canada
 * for Robojax.com
 * Get this code from Robojax.com
 * Watch video instruction for this code at: https://youtu.be/ixe--SXemp8
 * 
 * You will need to watch two videos before following the instructions in this video:
 * 1-MPU6050 Introduction video and code: https://youtu.be/uhh7ik02aDc
 * 2-LCD1602 with I2C module video and code: https://youtu.be/q9YC_GVHy5A
 */
#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(false);

  // initialize the LCD, 
  lcd.begin();
  // Turn on the backlight and print a message.
  lcd.backlight();
  lcd.clear();
   lcd.setCursor (0,0); //
   lcd.print("Robojax MPU-6050"); 
   lcd.setCursor (0,1); //   
 
   lcd.print("Please Wait - 3");  
   lcd.setCursor (0,1); // 
   delay(1000);        
   lcd.print("Please Wait - 2");  
   delay(1000); 
   lcd.setCursor (0,1); //      
   lcd.print("Please Wait - 1");  
   delay(1000);       
}

void loop() {

  mpu6050.update();
  Serial.print("angleX : ");
  Serial.print(mpu6050.getAngleX());
  Serial.print("\tangleY : ");
  Serial.print(mpu6050.getAngleY());
  Serial.print("\tangleZ : ");
  Serial.println(mpu6050.getAngleZ());
  
  lcd.clear();// clearn previous values from screen
   lcdDisplay(
            mpu6050.getAngleX(), // send angle X
            mpu6050.getAngleY(), // send angle Y
            mpu6050.getAngleZ()  // send angle Z
            );                       
   delay(100);

}// loop end

/*
 * Written by Ahmad Shamshiri for Robojax.com
 * lcdDisplay(float x, float y, float z)
 * displays value and title on LCD2004-I2C display
 * How to use:
 * just pass the three values and it will display them.
 * lcdDisplay(mpu6050.getAngleX() , mpu6050.getAngleY() , mpu6050.getAngleZ() )
 */
void lcdDisplay(float x, float y, float z)
{
   // Robojax.com MPU6050 Demo with LCD2004-I2C Display
   lcd.setCursor (0,0); //
   lcd.print("Robojax MPU-6050");  
    
   lcd.setCursor (0,1); //character zero, line 1
   lcd.print("Angle X:");
   lcd.setCursor (9,1); //
   lcd.print(x);   
   
   lcd.setCursor (0,2); //character zero, line 2
   lcd.print("Angle Y:");
   lcd.setCursor (9,2); //
   lcd.print(y);

   lcd.setCursor (0,3); //character zero, line 3
   lcd.print("Angle Z:");
   lcd.setCursor (9,3); //
   lcd.print(z);   
 
}
120-Arduino code for the MPU-6050 accelerometer and gyroscope sensor (all data)
ቋንቋ: C++
/*
 * 
 * This code is basic usage of the MPU-6050 accelerometer and gyroscope.
 * 
 * This code displays data on the LCD2004 display based on
 * the option you set. See below.
 * 
 * 
 * Library and code have been taken from:
 * https://github.com/tockn/MPU6050_tockn
 * 
 * Updated by Ahmad Shamshiri on July 03, 2018 in Ajax, Ontario, Canada
 * for Robojax.com
 * Get this code from Robojax.com
 * Watch video instructions for this code at: https://youtu.be/ixe--SXemp8
 * 
 * You will need to watch two videos before following the instructions in this video:
 * 1-MPU6050 Introduction video and code: https://youtu.be/uhh7ik02aDc
 * 2-LCD1602 with I2C module video and code: https://youtu.be/q9YC_GVHy5A
 
 */
#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

long timer = 0;

#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);

int typeSelect = 6;// select type . See below

String type[]={ "GyroAng and Ang",// select 0
                "GyroAng and Acc",// select 1
                "GyroAng and Gyro",// select 2
                "AccAng and Acc",// select 3
                "AccAng & Gyro",// select 4
                "AccAng and Ang",// select 5
                "Angle and Temp"// select 6
              };
              
void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);

  // initialize the LCD, 
  lcd.begin();
  // Turn on the backlight and print a message.
  lcd.backlight();    
}

void loop() {
  mpu6050.update();

  if(millis() - timer > 1000){
    
    Serial.println("=======================================================");
    Serial.print("temp : ");Serial.println(mpu6050.getTemp());
    Serial.print("accX : ");Serial.print(mpu6050.getAccX());
    Serial.print("\taccY : ");Serial.print(mpu6050.getAccY());
    Serial.print("\taccZ : ");Serial.println(mpu6050.getAccZ());
  
    Serial.print("gyroX : ");Serial.print(mpu6050.getGyroX());
    Serial.print("\tgyroY : ");Serial.print(mpu6050.getGyroY());
    Serial.print("\tgyroZ : ");Serial.println(mpu6050.getGyroZ());
  
    Serial.print("accAngleX : "); Serial.print(mpu6050.getAccAngleX());
    Serial.print("\taccAngleY : ");Serial.println(mpu6050.getAccAngleY());
  
    Serial.print("gyroAngleX : ");Serial.print(mpu6050.getGyroAngleX());
    Serial.print("\tgyroAngleY : ");Serial.print(mpu6050.getGyroAngleY());
    Serial.print("\tgyroAngleZ : ");Serial.println(mpu6050.getGyroAngleZ());
    
    Serial.print("angleX : ");Serial.print(mpu6050.getAngleX());
    Serial.print("\tangleY : ");Serial.print(mpu6050.getAngleY());
    Serial.print("\tangleZ : ");Serial.println(mpu6050.getAngleZ());
    Serial.println("=======================================================\n");
    timer = millis();
                        
     
  }// if
  lcd.clear();// clearn previous values from screen
  switch (typeSelect)
  {
    
  case 0:// display GyroAngle and Angle
   lcdDisplay(mpu6050.getGyroAngleX(),mpu6050.getGyroAngleY(),mpu6050.getGyroAngleZ(), 
             mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ()                                
            );
   break;

  case 1:// display GyroAngle and Acceleration value
   lcdDisplay(mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ(), 
             mpu6050.getAccX(),mpu6050.getAccY(),mpu6050.getAccZ()                                
            );
   break;  

  case 2:// display GyroAngle and Gyroscope value
   lcdDisplay(mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ(), 
            mpu6050.getGyroX(),mpu6050.getGyroY(),mpu6050.getGyroZ()                                
            );
   break;

  case 3:// display Acceleration Angle and Acceleration value
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(),0.0, 
           mpu6050.getAccX(),mpu6050.getAccY(),mpu6050.getAccZ()                                
            );
   break; 

  case 4:// display Acceleration Angle and Gyro value
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(), 0.0, 
              mpu6050.getGyroX(),mpu6050.getGyroY(),mpu6050.getGyroZ()                                 
            );
   break;
   
  case 5:// display Acceleration Angle and Angle
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(), 0.0, 
           mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ()                                   
            );
   break; 
   
  case 6:// display angle and Temperature
   lcdDisplay(mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ(), 
           mpu6050.getTemp(), 0.0, 0.0                                 
            );
   break;                      
  }// switch end
    delay(100);
}// loop


/*
 * Written by Ahmad Shamshiri for Robojax.com
 * lcdDisplay(lcdDisplay(float x, float y, float z, float x1, float y1, float z1)
 * displays values and titles on the LCD2004-I2C display.
 * How to use:
 * just pass the 6 values and it will display them.
   lcdDisplay(mpu6050.getAccAngleX(),mpu6050.getAccAngleY(),mpu6050.getAccAngleZ(), 
           mpu6050.getAngleX(),mpu6050.getAngleY(),mpu6050.getAngleZ()                                   
            );
 */
void lcdDisplay(float x, float y, float z, float x1, float y1, float z1)
{
   // Robojax.com MPU6050 Demo with LCD2004-I2C Display
   lcd.setCursor (0,0); //
   lcd.print(type[typeSelect]);  
   lcd.setCursor (17,0); //
   String dis = "("+String(typeSelect)+")";
   lcd.print(dis);    

    if(typeSelect !=6){
   lcd.setCursor (0,1); //character zero, line 1
   lcd.print("X:");
   lcd.setCursor (2,1); //
   lcd.print(x);  
   /////////////////////
   lcd.setCursor (10,1); //character zero, line 1
   lcd.print("X1:");
   lcd.setCursor (13,1); //
   lcd.print(x1);       
   
   lcd.setCursor (0,2); //character zero, line 2
   lcd.print("Y:");
   lcd.setCursor (2,2); //
   lcd.print(y);
   ////////////////////////
   lcd.setCursor (10,2); //character zero, line 1
   lcd.print("Y1:");
   lcd.setCursor (13,2); //
   lcd.print(y1);   
   

   lcd.setCursor (0,3); //character zero, line 3
   lcd.print("Z:");
   lcd.setCursor (2,3); //
   lcd.print(z);   
   //////////////////////
   lcd.setCursor (10,3); //character zero, line 3
   lcd.print("Z1:");
   lcd.setCursor (13,3); //
   lcd.print(z1);   
    }else{
   lcd.setCursor (0,1); //character zero, line 1
   lcd.print("X:");
   lcd.setCursor (2,1); //
   lcd.print(x);  
   /////////////////////
   lcd.setCursor (10,1); //character zero, line 1
   lcd.print("TMP: ");
   lcd.setCursor (15,1); //
   lcd.print(x1);       
   
   lcd.setCursor (0,2); //character zero, line 2
   lcd.print("Y:");
   lcd.setCursor (2,2); //
   lcd.print(y); 
   

   lcd.setCursor (0,3); //character zero, line 3
   lcd.print("Z:");
   lcd.setCursor (2,3); //
   lcd.print(z);   

  
    }
 
}

ምንጮች እና ምንጮች

ፋይሎች📁

Arduino ቤተ መዝገቦች (zip)

ፍሪትዚንግ ፋይል

ሌላ ፋይሎች

  • LCD1602 LiquidCrystal Library
    robojax-LCD1602_LiquidCrystal.zip
  • MPU6050_tockn-master
    Arduino library for the MPU6050 accelerometer and gyroscope module. Provides functions to read acceleration, gyro, and temperature data, with calibration and angle calculation. Designed for easy integration into motion-sensing projects.
    robojax-MPU6050_tockn-master.zip