hamid9543
Joined: 31 Jan 2013 Posts: 63
|
AHRS BNO055(gy-955) read |
Posted: Thu Jul 21, 2022 9:16 am |
|
|
My code to reading the z-Euler angle from AHRS bno055 is as follows, but only 0.00 is printed.
i tested code in arduino uno and it works correctly!
Code: |
#include <16F1937.h>
#use delay(internal=32MHz)
#use i2c(Master,Fast=400000,sda=PIN_C4,scl=PIN_C3,force_hw)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#define BNO055 0x52
float Yaw=0;
unsigned int8 status;
unsigned int8 get_ack_status(unsigned int8 address)
{
unsigned int8 status;
i2c_start();
status = i2c_write(address);
i2c_stop();
if(status==0) return(TRUE);
else return(FALSE);
}
void Search_i2c()
{
printf("\n\rStart:\n\r");
delay_ms(1000);
unsigned int8 count = 0;
for(unsigned int8 i=0x10; i < 0xF0; i+=2)
{
status = get_ack_status(i);
if(status == TRUE)
{
printf("Addr:%X\n\r",i);
count++;
delay_ms(500);
}
}
if(count == 0) printf("Nothing Found\n\r");
else printf("Chips Found=%u\n",count);
}
void BNO055_Config()
{
i2c_start();
i2c_write(BNO055);
i2c_write(0x3E); // Power Mode
i2c_write(0x00); // Normal:0X00 (or B00),Low Power: 0X01 (or B01),Suspend Mode: 0X02 (orB10)
i2c_stop();
delay_ms(100);
i2c_start();
i2c_write(BNO055);
i2c_write(0x3D); // Operation Mode
i2c_write(0x0C); //NDOF:0X0C (or B1100),IMU:0x08 (or B1000),NDOF_FMC_OFF: 0x0B (or B1011)
i2c_stop();
delay_ms(100); //Operation Mode switching time maximum=20ms
}
void BNO055_read() //reg_addr_Yaw=0x1A
{
i2c_start();
i2c_write(0x52); // 0x1A :GY955_SLAVE_WRT
i2c_write(0x1A); //reg_addr_Yaw=0x1A
i2c_start();
i2c_write(0x53); // 0x1B ::GY955_SLAVE_RD
Yaw = (int16)(i2c_read()|i2c_read(0)<<8 )/16.00;
i2c_stop();
}
void main()
{
delay_ms(2000);
BNO055_Config();
delay_ms(1000);
Search_i2c();
while(TRUE)
{
BNO055_read();
printf("%f\r\n",Yaw);
}
}
|
|
|