Microcontroller › AVR › imu sensor mpu 6050 help
- This topic has 6 replies, 2 voices, and was last updated 10 years, 7 months ago by
AJISH ALFRED.
-
AuthorPosts
-
September 1, 2014 at 7:25 pm #3242
disha k
Participanti 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 #12115AJISH ALFRED
ParticipantCheck the lcd writting function written in this code by printing some alphabets.
September 2, 2014 at 1:42 pm #12120disha k
Participanti 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 communicationwhile(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 communicationwhile(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 #12121AJISH ALFRED
ParticipantChange 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 #12124disha k
Participantok 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 #12125disha k
Participanti made the changes what you suggested ..
but, lcd is just blank…
September 22, 2014 at 5:38 am #12217AJISH ALFRED
ParticipantHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.