This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BMI160 + NRF52832 + I2C

HI,

I want to develop a program to access Accelerometer and gyroscope value from BMI160 sensor. I have used this BMI160 library 

I alter the TWI_SENSOR code and it works for self testing ACC code. but i need to calibrate the x, y, z axis value and i want to add BLE stack to read in mobile app.

1. How to collect all the X,Y,Z axis value

2. i need to see the LOGS in Bluetooth app by using BLE_UART. how to edit the BLE_UART code to get the respective ACC and GYRO value in BLE APP.

Is there any code for reading X,Y,Z axis for BMI160??

Parents Reply Children
  • Can I use button 1 to on/off the Bluetooth  is it possible?

    The controller can do its work by fetching the data from sensor

    if the button is pressed  controller send the respective data to BLE UART otherwise the controller do their work

  • Unless you have very low power requirements, I would recommend that you stay in the connection all the time to make sure there is not a lot of overhead when sending the data. You can then implement a button handler that send the data using ble_nus_data_send when the button is pressed.

  • Actually the fatal error is not constant

    1. It was came when I disturb the sensor as same like above return err code 0x01
    2. Some other time while I not connect to phone that ble_data_nus_send() returns 0x05 and within few seconds cause fatal error

    And definitely I need low power required

    Is it possible that whenever I need that time I can able to initialize the ble?.

  • this error happen when i move the sensor fast.

    in the above image

    rslt is the return err_ode from  BMI init();

    rsltr is the return err_code from Acc_i2c_Read();

    rsltw from Acc_i2c_Write();

    rsltb from ble_nus_data_send();

        rslt = bmi160_init(&sensor);
        APP_ERROR_CHECK(rslt);
    
    
      rslt = bmi160_set_sens_conf(&sensor);
        APP_ERROR_CHECK(rslt);
        
        
        int8_t Acc_i2c_Write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    
        //  NRF_LOG_INFO("WRITE: dev_id: %x reg_addr: %x reg_data: %x len: %i\n", dev_id, reg_addr, *reg_data, len);
    	//int8_t rslt = 0;
    	uint8_t data[len + 1];
    	data[0] = reg_addr;
    	for (uint16_t i = 0; i < len; i++) {
    		data[i + 1] = reg_data[i];
    	}
    	
    	rsltw = nrf_drv_twi_tx(&m_twi, dev_id, data, len + 1, false);
    	APP_ERROR_CHECK(rsltw);
            return rsltw;
      
    }
    
    
    int8_t Acc_i2c_Read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    	//int8_t rslt = 0;
       //     NRF_LOG_INFO("READ: dev_id: %x reg_addr: %x len: %i\n", dev_id, reg_addr, len);
    	rsltr = nrf_drv_twi_tx(&m_twi, dev_id, &reg_addr, 1, true);
            APP_ERROR_CHECK(rsltr);
    
    	if (rsltr == 0)
    	{
    		rsltr = nrf_drv_twi_rx(&m_twi, dev_id, reg_data, len);
    	}
        //    NRF_LOG_INFO("READ: %x",*reg_data);
    	return rsltr;
    }
    
    
          length1 = sprintf(str, "DataX = %5d \n", accel.x);
    
          rsltb = ble_nus_data_send(&m_nus, str, &length1, m_conn_handle);
         // APP_ERROR_CHECK(rsltb);
    
    

Related