Getting the Euler angles from a BNO055 using SAML22

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wondering if someone could help me with a weird problem I'm having with a BNO055 (The sensor works fine with Arduino.) I'm trying to read data from a Adafruit BNO055 board using a SAML22 Xplained board and I2C. I used Atmel Start to create a new project and used the included BNO055 library. I can read the chip id, page id, software id, etc. without a problem, I2C seems to work fine.

Then I tried reading the calibration data and temperature, which again worked without a problem. However as soon as I want to read Euler data, sensor data or quaternions the transmission starts to lag and my terminal displays 0's. All reading functions are in the library and should work. The only real difference between reading temperature data and lets say the acceleration in x direction is that the latter consists of 2 bytes. Otherwise they are on the same page/address. I feel like it might be an error with the I2C speed while printing the data in the terminal. I've tried using the debugger to find the error, but when using it the I2C keeps falling in a timeout loop. Could it be that trying to print data to the terminal sends the I2C connection into a time out? If that's the case how can I see the data I'm reading out? And why would it work for temperature but not another data type...

 

The Adafruit sensor has 10kOhm on the I2C lines, and am using 100kHz clock speed, also tried with 50kHz but it didn't get better.

 

For what it's worth here my code, again this is just standard Atmel Bno055 library:

 

void UART_EDBG_init()
{
	usart_async_get_io_descriptor(&USART_0, &terminal_io);
	usart_async_enable(&USART_0);
}

static void configure_sensor(void)
{
	bno055_set_power_mode(BNO055_POWER_MODE_NORMAL);
	bno055_set_intr_rst(BNO055_ENABLED);

	bno055_set_gyro_any_motion_axis_enable(0, BNO055_ENABLED);
	bno055_set_gyro_any_motion_axis_enable(1, BNO055_ENABLED);
	bno055_set_gyro_any_motion_axis_enable(2, BNO055_ENABLED);
	bno055_set_gyro_unit(BNO055_GYRO_UNIT_DPS);

	bno055_set_accel_any_motion_no_motion_axis_enable(0, BNO055_ENABLED);
	bno055_set_accel_any_motion_no_motion_axis_enable(1, BNO055_ENABLED);
	bno055_set_accel_any_motion_no_motion_axis_enable(2, BNO055_ENABLED);
	bno055_set_accel_unit(BNO055_ACCEL_UNIT_MG);
	bno055_set_accel_any_motion_thres(5);
	bno055_set_accel_any_motion_durn(1);
	bno055_set_intr_accel_any_motion(BNO055_ENABLED);
	bno055_set_intr_mask_accel_any_motion(BNO055_ENABLED);
	bno055_set_accel_slow_no_motion_thres(5);
	bno055_set_accel_slow_no_motion_durn(1);
	bno055_set_intr_accel_no_motion(BNO055_ENABLED);

	bno055_set_temp_source(BNO055_GYRO_TEMP_EN);
	bno055_set_temp_unit(BNO055_TEMP_UNIT_CELSIUS);

	bno055_set_operation_mode(BNO055_OPERATION_MODE_NDOF);
}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
	
	UART_EDBG_init();

	i2c_m_sync_get_io_descriptor(&COMMUNICATION_IO, &I2C_0_io);
	i2c_m_sync_enable(&COMMUNICATION_IO);
	i2c_m_sync_set_slaveaddr(&COMMUNICATION_IO, CONF_BNO055_I2C_ADDR, I2C_M_SEVEN);

	/* Set slave address select pin to high to select slave I2C address 0x29 */
	gpio_set_pin_level(BNO055_ADDR_SEL, true);

	if ((int8_t)0 != ORIENTATION_SENSOR_0_init()) {
		/* sensor initialization unsuccessful */
		/* indicate error by turning ON LED1 */
		gpio_set_pin_level(LED, LED_ON);
	}

	/* configure sensor parameters*/
	configure_sensor();

	while (1) {
		
		if (mag_calib_data != 3 || accel_calib_data != 3 || gyro_calib_data != 3 || sys_calib_data != 3){
			bno055_get_mag_calib_stat(&mag_calib_data); 
			bno055_get_accel_calib_stat(&accel_calib_data);
			bno055_get_gyro_calib_stat(&gyro_calib_data);
			bno055_get_sys_calib_stat(&sys_calib_data);
			
			snprintf(str, STR_SIZE, "Mag: %d	Accel: %d	Gyro: %d	Sys: %d\r\n", mag_calib_data, accel_calib_data, gyro_calib_data, sys_calib_data);
			io_write(terminal_io, (uint8_t *)str, strlen(str));
		} else {
			/*
			bno055_read_euler_h(&euler_h);
			bno055_read_euler_r(&euler_r);
			bno055_read_euler_p(&euler_p);
			snprintf(str, STR_SIZE, "Euler: %" PRId16"\t%" PRId16"\t%" PRId16"\r\n", euler_h, euler_r, euler_p);
			io_write(terminal_io, (uint8_t *)str, strlen(str));
			*/
			bno055_read_temp_data(&temp_data);		
			snprintf(str, STR_SIZE, "Temperature: %d Celsius\r\n", temp_data);
			io_write(terminal_io, (uint8_t *)str, strlen(str));
		}
	}
}