EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / imu sensor mpu 6050 help

imu sensor mpu 6050 help

|

Microcontroller › AVR › imu sensor mpu 6050 help

  • This topic has 6 replies, 2 voices, and was last updated 11 years, 2 months ago by AJISH ALFRED.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • September 1, 2014 at 7:25 pm #3242
    disha k
    Participant

    i have interfaced a mpu 6050 to my atmega 8 & have written a code using i2c header file.
    the code is to see whether the device is accessible or not. and the function used is:
     unsigned char i2c_start(unsigned char address)  //  Issues a start condition and sends address and transfer direction.
                                                                                    //return 0 = device accessible, 1= failed to access device
                                                                                   //then i am printing the value got on lcd
    ex:
    #define Dev24C02 0X68   //sensor address
    ret=i2c_start(Dev24C02);    //sending device address
      lcd_showvalue(ret);

     
    so ret should either print 0 or 1.
    but lcd remains blank (there is no  print at all).
    i have tested the lcd (it’s working all fine with other programs).
    I am unable to figure out what is the exact problem..:-(

    September 2, 2014 at 11:27 am #12115
    AJISH ALFRED
    Participant

    Check the lcd writting function written in this code by printing some alphabets.

    September 2, 2014 at 1:42 pm #12120
    disha k
    Participant

    i have done that thing also  nothing is wrong with the lcd …

    this is my actual code:

    here is my code:

    #include<avr/io.h>                 //This is the header for AVR Microcontroller.
    #define F_CPU 12000000UL
    #include “i2cmaster.h”
    #include<util/delay.h>      
    #include”lcd118010.h”                  //lcd
    #define mpu 0X68                     //address of the i2c device
    int main(void)
    {
    unsigned char ret=0;

    DDRC=0X00;
    PORTC=0X00;                           //disabling the internal pull up for sda,scl
    lcd_init();
    i2c_init();                                   //initialise i2c communication

    while(1)
    {
    lcd_string(“hi “);
    _delay_ms(1000);

    ret=i2c_rep_start(mpu);      //send adress to recognize slave device  and if  ret=0 device is  accesible  ret=1 device is not accessible

    lcd_showvalue(ret);  //print that value on lcd
    _delay_ms(1900);

    lcd_clear();    //clear lcd & continue
    }
    }
    [/CODE]

    my observations :lcd is printing “hi” but,  ret   value is not printing(neither 1 nor 0) and neither is lcd clearing.

     

    “””but if i am commenting  ret=i2c_rep_start(mpu); “”””

     

    then only lcd clears &  rexecutes the loop

    how do i solve this problem?  is my sensor ok!!

    [CODE]
    #include<avr/io.h>                 //This is the header for AVR Microcontroller.
    #define F_CPU 12000000UL
    #include “i2cmaster.h”
    #include<util/delay.h>      
    #include”lcd118010.h”                  //lcd
    #define mpu 0X68                     //address of the i2c device
    int main(void)
    {
    unsigned char ret=0;

    DDRC=0X00;
    PORTC=0X00;                           //disabling the internal pull up for sda,scl
    lcd_init();
    i2c_init();                                   //initialise i2c communication

    while(1)
    {
    lcd_string(“hi “);
    _delay_ms(1000);

    ret=i2c_rep_start(mpu);      //send adress to recognize slave device  and if  ret=0 device is  accesible  ret=1 device is not accessible

    lcd_showvalue(ret);  //print that value on lcd
    _delay_ms(1900);

    lcd_clear();    //clear lcd & continue
    }
    }
    [/CODE]

    my observations :lcd is printing “hi” but,  ret   value is not printing(neither 1 nor 0) and neither is lcd clearing.

     

    “””but if i am commenting  ret=i2c_rep_start(mpu); “”””

     

    then only lcd clears &  rexecutes the loop

    how do i solve this problem?  is my sensor ok!!

    September 3, 2014 at 4:24 am #12121
    AJISH ALFRED
    Participant

    Change this statement in your code

     lcd_showvalue(ret);

    as given below;

    lcd_showvalue(ret + ‘0’);

    Because the value in ret is 1, it should be converted to the ascii value of ‘1’ before printing it in the lcd.

     

     

     

    September 3, 2014 at 2:14 pm #12124
    disha k
    Participant

    ok i will do that

    but if you see in the pleury library  that is what i am using  i will post their function here:

    *************************************************************************    
      Issues a start condition and sends address and transfer direction.
      return 0 = device accessible, 1= failed to access device
    *************************************************************************/
    unsigned char i2c_start(unsigned char address)

    {

     

    ////

    ////code

    }/******************************************//////////////////////////////

     

    as you can see i have written:

    ret=i2c_start(mpu);    //  then ret should return 1 or 0 (unsigned char value)

     

     

    And the  lcd function i am using   :

    in header file it is given like this:

    void lcd_showvalue(unsigned char num)

    {

    //code

    }

    that means  “”num””  here is ret  must be a unsigned char value.  So  there is no mistake in the code what i have written earlier right?

    but, i will try what you have said & let u know soon the results.

     

     

     

    September 3, 2014 at 4:23 pm #12125
    disha k
    Participant

    i made the changes what you suggested ..

    but, lcd is just blank…

    September 22, 2014 at 5:38 am #12217
    AJISH ALFRED
    Participant

    Hi Dishak,

    So the problem could be either the function “char i2c_start()  ” is not returning any value properly or there could be some problem inside the function “lcd_showvalue()“. Please post the code of those two functions.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Droplet1 December 14, 2025
  • Bringing a Siemens W-48 and Ericsson Model 1951 back to life December 14, 2025
  • What is involved to convert a small town to fiber optic? December 14, 2025
  • mechanism to shutdown feeding when sensor temperature rises December 13, 2025
  • Oshonsoft MSSP simulation question December 13, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise