Search Code

અર્ડુઇનો કોડ MPU-6050 માટે LCD1602 I2C ડિસ્પ્લે સાથે

અર્ડુઇનો કોડ MPU-6050 માટે LCD1602 I2C ડિસ્પ્લે સાથે

આ ટ્યુટોરિયલમાં, આપણે MPU-6050 એક્સેલેરોમીટર અને જાયરોસ્કોપને I2C સંચારનો ઉપયોગ કરીને LCD1602 ડિસ્પ્લે સાથે કેવી રીતે જોડવું તે શીખીશું. MPU-6050 કોણ માપન પ્રદાન કરશે જે LCD પર દર્શાવવામાં આવશે. આ પ્રોજેક્ટ તમને MPU-6050 ના ખૂણાઓને રીઅલ-ટાઇમમાં જોવામાં મદદ કરશે, જે સેન્સર ડેટા અને ડિસ્પ્લે ઇન્ટરફેસિંગની તમારી સમજને વધારશે.

LCD1602-I2C display module with 4 wires

આ ટ્યુટોરિયલના અંત સુધીમાં, તમારી પાસે એક કાર્યકારી સેટઅપ હશે જે LCD સ્ક્રીન પર X, Y અને Z ખૂણાઓ દર્શાવે છે. આર્ડુઇનો પ્રોજેક્ટ્સમાં સેન્સર ડેટા અને ડિસ્પ્લે ટેકનોલોજી સાથે હાથથી અનુભવ મેળવવાનો આ એક શ્રેષ્ઠ માર્ગ છે. વધુ સ્પષ્ટતા માટે, (વિડિયોમાં 00:00 પર) વિડિયો જોવાનું ભૂલશો નહીં.

હાર્ડવેર સમજાવ્યું

આ પ્રોજેક્ટના મુખ્ય ઘટકો MPU-6050 સેન્સર અને LCD1602 ડિસ્પ્લે મોડ્યુલ છે. MPU-6050 એક બહુમુખી સેન્સર છે જે 3-અક્ષ એક્સેલેરોમીટર અને 3-અક્ષ જાયરોસ્કોપને જોડે છે, જે રીઅલ-ટાઇમ કોણ માપન પ્રદાન કરે છે. તે I2C પર સંચાર કરે છે, જે આર્ડુઇનો સાથે સીમલેસ એકીકરણની મંજૂરી આપે છે.

LCD1602 ડિસ્પ્લે પણ I2C પ્રોટોકોલનો ઉપયોગ કરે છે, જે વાયરિંગને સરળ બનાવે છે અને સંચાર માટે જરૂરી પિનની સંખ્યા ઘટાડે છે. I2C ઇન્ટરફેસ બહુવિધ ઉપકરણોને સમાન બસ પર કનેક્ટ કરવાની મંજૂરી આપે છે, જે બહુવિધ સેન્સર અથવા ઘટકો ધરાવતા પ્રોજેક્ટ્સ માટે કાર્યક્ષમ બનાવે છે.

ડેટાશીટ વિગતો

ઉત્પાદકઇનવેન્સેન્સ
ભાગ નંબરMPU-6050
લોજિક/IO વોલ્ટેજ3.3 V / 5 V
સપ્લાય વોલ્ટેજ3.3 V થી 5 V
આઉટપુટ ડેટા દર1 kHz (મહત્તમ)
જાયરોસ્કોપ રેન્જ±250, ±500, ±1000, ±2000 °/s
એક્સેલેરોમીટર રેન્જ±2g, ±4g, ±8g, ±16g
પેકેજQFN
નોંધો / વેરિઅન્ટ્સડિજિટલ મોશન પ્રોસેસર (DMP) શામેલ છે

  • I2C સરનામું તપાસો (ડિફોલ્ટ 0x68 છે).
  • યોગ્ય પાવર સપ્લાય વોલ્ટેજ (3.3 V અથવા 5 V) ની ખાતરી કરો.
  • જો બોર્ડ પર પહેલેથી ન હોય તો SDA અને SCL લાઇનો માટે પુલ-અપ રેઝિસ્ટરનો ઉપયોગ કરો.
  • સ્થિરતા માટે પાવર પિન નજીક ડિકપ્લિંગ કેપેસિટરનો ઉપયોગ કરવાનું વિચારો.
  • સંચાર સમસ્યાઓ ટાળવા માટે વાયરિંગ જોડાણો ચકાસો.

વાયરિંગ સૂચનાઓ

Arduino wiring for MPU-6050 with LCD

MPU-6050 અને LCD1602 ડિસ્પ્લેને તમારા આર્ડુઇનો સાથે જોડવા માટે, આ જોડાણોને અનુસરો:

  • MPU-6050 ના VCC પિનને આર્ડુઇનો પરના 5V પિન સાથે જોડો.
  • MPU-6050 ના GND પિનને આર્ડુઇનો પરના GND પિન સાથે જોડો.
  • MPU-6050 ના SDA પિનને આર્ડુઇનો પરના A4 પિન સાથે જોડો.
  • MPU-6050 ના SCL પિનને આર્ડુઇનો પરના A5 પિન સાથે જોડો.
  • LCD1602 ડિસ્પ્લે માટે, VCC પિનને આર્ડુઇનો પરના 5V સાથે જોડો.
  • LCD1602 ના GND પિનને આર્ડુઇનો પરના GND પિન સાથે જોડો.
  • LCD1602 ના SDA પિનને MPU-6050 માટે વપરાયેલા સમાન A4 પિન સાથે જોડો.
  • LCD1602 ના SCL પિનને MPU-6050 માટે વપરાયેલા સમાન A5 પિન સાથે જોડો.

તમારા જોડાણોને બે વાર તપાસવાનું સુનિશ્ચિત કરો, કારણ કે ખોટું વાયરિંગ ઉપકરણની ખામી અથવા યોગ્ય રીતે સંચાર કરવામાં નિષ્ફળતા તરફ દોરી શકે છે.

કોડ ઉદાહરણો અને વોકથ્રુ

કોડ MPU-6050 અને LCD ડિસ્પ્લે માટે જરૂરી લાઇબ્રેરીઓ શામેલ કરીને શરૂ થાય છે. નીચેનો અંશ બતાવે છે કે MPU-6050 ને કેવી રીતે પ્રારંભ કરવું:

MPU6050 mpu6050(Wire);

અહીં, આપણે MPU6050 ઑબ્જેક્ટ બનાવીએ છીએ, જેનો ઉપયોગ સેન્સરમાંથી ડેટા વાંચવા માટે થશે. આગળ, આપણે setup() ફંક્શનમાં ઉપકરણ સેટ કરવાની જરૂર છે:

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

આ કોડ સીરિયલ સંચાર, I2C બસ અને MPU-6050 સેન્સરને પ્રારંભ કરે છે. તે LCD ને પણ પ્રારંભ કરે છે અને તેની બેકલાઇટ ચાલુ કરે છે. લૂપમાં ખૂણાઓને અપડેટ અને દર્શાવવાનો તર્ક શામેલ છે:

void loop() {
  mpu6050.update();
  lcd.clear();
  lcdDisplay(0, 0, "X:", 2, 0, mpu6050.getAngleX());
  lcdDisplay(13, 0, "Y:", 0, 1, mpu6050.getAngleY());
  lcdDisplay(7, 1, "Z:", 9, 1, mpu6050.getAngleZ());
  delay(100);
}

આ લૂપમાં, X, Y અને Z માટેના ખૂણાઓ અપડેટ થાય છે અને LCD પર દર્શાવવામાં આવે છે. આઉટપુટને યોગ્ય રીતે ફોર્મેટ કરવા માટે lcdDisplay() ફંક્શનનો ઉપયોગ થાય છે. તમે લેખની નીચે લોડ કરેલો સંપૂર્ણ કોડ શોધી શકો છો.

પ્રદર્શન / શું અપેક્ષા રાખવી

જ્યારે સેટઅપ પૂર્ણ થાય અને કોડ અપલોડ થાય, ત્યારે તમારે X, Y અને Z માટેના ખૂણાઓ LCD પર રીઅલ-ટાઇમમાં દર્શાવેલા જોવા જોઈએ. જો બધું યોગ્ય રીતે વાયર કરેલું હોય, તો ડિસ્પ્લે દર 100 મિલિસેકન્ડે રિફ્રેશ થશે, જે MPU-6050 ની વર્તમાન દિશા દર્શાવે છે.

સામાન્ય મુશ્કેલીઓમાં I2C જોડાણો યોગ્ય છે તેની ખાતરી કરવી અને પાવર સપ્લાય સ્થિર છે તેની ખાતરી કરવી શામેલ છે. જો MPU-6050 યોગ્ય રીતે પ્રારંભ ન થાય, તો તમે LCD પર ખોટો અથવા કોઈ ડેટા જોઈ શકો છો (વિડિયોમાં 01:15 પર).

Images

LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
MPU-6050-module-1
MPU-6050-module-1
MPU-6050-module-2
MPU-6050-module-2
MPU-6050-module-schematic
MPU-6050-module-schematic
MPU-6050-module-1
MPU-6050-module-1
Arduino wiring for MPU-6050 with LCD
Arduino wiring for MPU-6050 with LCD
118-Arduino code for MPU-6050 accelerometer and gyroscope sensor (all data)
Language: 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 LCD1602-I2C display module.
 * 
 * Library and code have been taken from:
 * https://github.com/tockn/MPU6050_tockn
 * 
 * Updated by Ahmad Shamshiri on July 05, 2018 at 22:19 in Ajax, Ontario, Canada
 * for Robojax.com
 * Get this code from Robojax.com
 * Watch video instructions for this code at: https://youtu.be/uIz6WIis4dc
 * 
 * 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 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

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();
  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(
             // to print X:
             0, // character 0  
             0, // line 0
             "X:", 

             // to print AngleX
             2, // character 2
             0, // line 0
             mpu6050.getAngleX() 
             );

  lcdDisplay(
             // to print Y:
             13, // character 13 
             0, // line 0
             "Y:", 

             // to print AngleY
             0, // character 0
             1, // line 1
             mpu6050.getAngleY() 
             );  

  lcdDisplay(
             // to print Z:
             7, // character 7 
             1, // line 1
             "Z:", 

             // to print AngleZ
             9, // character 9
             1, // line 0
             mpu6050.getAngleZ() 
             );                         
   delay(100);
}// loop end

/*
 * lcdDisplay(int tc, int tr, String title, int vc, int vr, float value)
 * displays value and title on LCD1602
 * How to use:
 * If you want to display: "Voltage: 13.56mV" starting from the first character
 * on the second row.
 * use:
 * lcdDisplay(0, 1, "Voltage: ", 13.56)
 *   
 * tc  is the character number  (0)
 * tr is the row number in the LCD (1)
 * title is the text ("Voltage:")
 * vc is the character number for the value
 * vr is the row number for the value
 * value is the value (13.56)
 */
void lcdDisplay(int tc, int tr, String title, int vc, int vr, float value)
{
   // Robojax.com MPU6050 Demo
   lcd.setCursor (tc,tr); //
   lcd.print(title);
   
   lcd.setCursor (vc,vr); //
   lcd.print(value);
 
}

Things you might need

Resources & references

Files📁

Arduino Libraries (zip)

Fritzing File

Other files

  • 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