03-15-2023 10:18 AM - edited 03-15-2023 01:29 PM
Hello everyone,
I am a student and currently in my practical phase. I am trying to figure out what I am doing wrong when trying to read out the gyro data of the BMI270 for example.
I tried to compile the official Sensor API on Github but ran into error codes with COINES (i installed it) while compiling, so I used the latest version v2-53-2 which was without COINES, compiled it and ran into this error:
Error [-9] : Configuration load error. It occurs when failure observed while loading the configuration into the sensor
Which I couldn't figure out how to solve, so I started to write my own code as I really only want to read out the gyro data itself.
I connected the BMI270 via the quickconnect cable to the Raspberry Pi pins 1 (3.3 VDC), 3 (GPIO8 SDA1 (I2C)), 5 (GPIO 9 SCL1 (I2C)) and 9 (ground).
I am currently using the WiringPi library found here: http://wiringpi.com/
Essentially these are all the functions from the WiringPi libary for I2C:
int wiringPiI2CRead (int fd) ;
int wiringPiI2CWrite (int fd, int data) ;
int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
int wiringPiI2CReadReg8 (int fd, int reg) ;
int wiringPiI2CReadReg16 (int fd, int reg) ;
There are also these functions which I wasn't able to use yet because I didn't know how I should give this function the dPin and cPin, though I saw that the cPin is 13 and dPin is 14 in the Datasheet.
uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ;
void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ;
In general I tried following the Quickstart Guide in the BMI270 Datasheet when writing my code.
Console logs of my code:
------START------
Device found!
DEVICE_ID: 3
CHIP_ID: 0x24
WRITING DATA ......... --> LAST DATA: 0xC1
Initialization status: 00000000 (Bit 0 = 1 --> OK)
7D before: 00001110
7D after: 00001110
40 before: 10101000
40 after: 10101000
42 before: 11101001
42 after: 11101001
7C before: 00000000
7C after: 00000010
rateX -8-Data_14: 0
rateX2-8-Data_15: 0
rateY -8-Data_16: 0
rateY2-8-Data_17: 0
rateZ -8-Data_18: 0
rateZ2-8-Data_19: 0
rateX -8-Data_14: 0
rateX2-8-Data_15: 0
rateY -8-Data_16: 0
rateY2-8-Data_17: 0
rateZ -8-Data_18: 0
rateZ2-8-Data_19: 0
rateX -8-Data_14: 0
rateX2-8-Data_15: 0
rateY -8-Data_16: 0
rateY2-8-Data_17: 0
rateZ -8-Data_18: 0
rateZ2-8-Data_19: 0
------END------
My burst_write function is essentially just using wiringPiI2CWriteReg8(..) in a for loop. Not sure if that would be the right way to do it when you want to upload the config file. But I believe it is probably not, because when I read out the Initialization status I alway receive a 0 for the Bit 0, which according to the Datasheet means its "not ok".
All in all I believe setting bits in the register works, but for some reason I can't read out data, probably because I am doing it wrong I believe. Also I tried out a very simple python code with the BMI160 and a compatible python Driver for it to test if the I2C even works and it seems to give me data there. I didn't try anything in python with the BMI270 yet because I wanted to keep it in C/C++. Maybe there could also be a problem with the WiringPi library I am using. Or I am just missing a specific register which I didn't set properly yet?
Or recommend me a different library which I could use or even post a code sample which works simliar to mine without using the Sensor API of Bosch.
Hopefully someone can help me bringt light into this. 🙂
Best Regards
Kevin
This is how my code looks at the moment:
Solved! Go to Solution.
03-15-2023 02:45 PM
Not sure if this information helps but I wanted to also add it.
As mentioned in my previous post I managed to received the gyro data from the BMI160 through a python script with a specific library for this IMU.
Now I've tried reading out the gyro data of the BMI270 with smbus2 for python.
I have noticed a command in there:
read_i2c_block_data(..)
Which i used to read out the 0x16 (DATA_18 - gyr_z_7_0) register in this way (most likely the wrong way, but at least I finally received a different output than 0):
print("data: " + str(bus.read_i2c_block_data(BMI270_ADDR, 0x16, 12)))
Output Logs:
data: [0, 0, 69, 147, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 235, 147, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
data: [0, 0, 251, 255, 243, 0, 0, 0, 0, 0, 0, 0]
Not sure why it gets stuck at these numbers and most likely the format is wrong too. But maybe someone knows which direction to point me to.
Best Regards
Kevin
03-16-2023 07:11 AM
Hi somml,
You need to make sure the BMI270 hardware is connected correctly as you use I2C communication.
We had little experience about Raspberry Pi 3B+. Official BMI270 sensor API code was written by C language, there are example code on github https://github.com/boschsensortec/BMI270-Sensor-API, you could refer them and migrate them to your platform.
03-16-2023 02:44 PM - edited 03-16-2023 02:45 PM
Thanks for your reply.
The BMI270 (with breakout board) is connected properly to the Raspberry Pi. Still when reading out the data registers, I only receive zeros.
When trying to read out data with the same setup but the BMI160 instead, I can read out the data registers and receive values.
Also when using the Official BMI270 sensor API code on github which you linked, I receive this error when executing:
Error [-9] : Configuration load error. It occurs when failure observed while loading the configuration into the sensor
What could be the problem?
Best Regards
Kevin
03-21-2023 06:52 AM
Hi somml,
There are different BMI270 configuration file versions, and different configuration file versions have different features.
If you you used BMI270 base version, you should load the configuration array bmi270_config_file[] in file bmi270.c, add refer to the procedure for loading configuration file in function bmi2_write_config_file() in file bmi2.c.