03-04-2021 11:16 PM - edited 03-04-2021 11:24 PM
I have hooked up the BMG250 shuttle board to my Raspberry Pi 3 (I2C) and it is currently in suspend mode. I am able to read/write to registers such as GYR_CONF (0x42) and GYR_RANGE (0x43).
So in order to change the PMU status from suspend mode to normal mode I execute the following line:
bus.write_byte_data(0x68, 0x7E, 0x15)
To check the PMU status I wrote:
time.sleep(1)
bus.read_i2c_block_data(0x68, 0x03, 1)
And I keep getting PMU Status as 0. Instead of the integer 4 which would be representative of normal mode. Does anybody know how to fix this?
Here is my full code:
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# I2C address of the device
BMG250_DEFAULT_ADDRESS = 0x68
# BMG250 Register Map
BMG250_REG_CHIPID = 0x00 # Chip ID Register
BMG250_REG_ERR = 0x02 # Error Register
BMG250_REG_PMU = 0x03 # PMU Status
BMG250_REG_STATUS = 0x1B # Status Register
BMG250_REG_CMD = 0x7E # Command Register
BMG250_REG_NVCONF = 0x70 # Watchdog Timer
BMG250_REG_NVM = 0x6A # NVM Programming
BMG250_REG_IF = 0x6B # Interface Configuration
BMG250_REG_ST = 0x6D # Self-Test Register
BMG250_REG_X_LSB = 0x12 # X-axis Data LSB
BMG250_REG_X_MSB = 0x13 # X-axis Data MSB
BMG250_REG_Y_LSB = 0x14 # Y-axis Data LSB
BMG250_REG_Y_MSB = 0x15 # Y-axis Data MSB
BMG250_REG_Z_LSB = 0x16 # Z-axis Data LSB
BMG250_REG_Z_MSB = 0x17 # Z-axis Data MSB
BMG250_REG_TEMP = 0x20 # Temperature Register
BMG250_REG_RANGE = 0x43 # Range Register
BMG250_REG_DOR = 0x42 # Data Output Rate Register
# BMG250 Range Register Configuration
BMG250_RANGE_2000 = 0x00 # Full Scale = +/-2000dps
BMG250_RANGE_1000 = 0x01 # Full Scale = +/-1000dps
BMG250_RANGE_500 = 0x02 # Full Scale = +/-500dps
BMG250_RANGE_250 = 0x03 # Full Scale = +/-250dps
BMG250_RANGE_125 = 0x04 # Full Scale = +/-125dps
# BMG250 Data Output Rate Register Configuration
BMG250_1600_HZ = 0x2C # 1600 Hz Configuration
# BMG250 PMU Configuration
BMG250_PMUT = 0x11 # Gyroscope Temp Normal Mode
BMG250_PMUN = 0x15 # Gyroscope Normal Mode
BMG250_PMUF = 0x17 # Gyroscope Fast Mode
BMG250_PMUSR = 0xB6 # Gyroscope Soft Reset
# BMG250 NV Configuration
BMG250_NVCONF = 0x00 # I2C Watchdog Timer Configuration
time.sleep(1)
"""Select the Data Output Rate Register Configuration from the given provided value"""
DOR1600 = (BMG250_1600_HZ)
bus.write_byte_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_DOR, DOR1600)
time.sleep(1)
value3 = bus.read_i2c_block_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_DOR, 1)
print("BMG250 Data Output Rate value: %s" %value3)
time.sleep(1)
"""Select the PMU Status from the given provided value"""
PMU_MODE = (BMG250_PMUN)
bus.write_byte_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_CMD, PMU_MODE)
time.sleep(1)
value1 = bus.read_i2c_block_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_PMU, 1)
time.sleep(0.1)
print("BMG250 PMU value: %s" %value1)
time.sleep(1)
"""Check the Error Register"""
value6 = bus.read_i2c_block_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_ERR, 1)
print("BMG250 ERR value: %s" %value6)
time.sleep(1)
"""Select the Range Register Configuration from the given provided value"""
RANGE_CONFIG = (BMG250_RANGE_2000)
bus.write_byte_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_RANGE, RANGE_CONFIG)
time.sleep(1)
value4 = bus.read_i2c_block_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_RANGE, 1)
print("BMG250 RANGE value: %s" %value4)
time.sleep(1)
"""Read from the Temperature Register"""
value5 = bus.read_i2c_block_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_TEMP, 2)
time.sleep(0.1)
print("BMG250 TEMP value: %s" %value5)
time.sleep(1)
class BMG250():
def __init__(self):
self.read_gyro()
def read_gyro(self):
"""Read data back from BMG250_REG_X_LSB(0x12), 6 bytes
X-Axis LSB, X-Axis MSB, Y-Axis LSB, Y-Axis MSB, Z-Axis LSB, Z-Axis MSB"""
data = bus.read_i2c_block_data(BMG250_DEFAULT_ADDRESS, BMG250_REG_X_LSB, 6)
# Convert the data
xGyro = data[1] * 256 + data[0]
if xGyro > 32767 :
xGyro -= 65536
yGyro = data[3] * 256 + data[2]
if yGyro > 32767 :
yGyro -= 65536
zGyro = data[5] * 256 + data[4]
if zGyro > 32767 :
zGyro -= 65536
return {'x' : xGyro, 'y' : yGyro, 'z' : zGyro}
BMG250 = BMG250()
i = 1
while i < 2:
gyro = BMG250.read_gyro()
time.sleep(0.1)
print("X-Axis of Rotation : %f" %(gyro['x']))
print("Y-Axis of Rotation : %f" %(gyro['y']))
print("Z-Axis of Rotation : %f" %(gyro['z']))
print(" ************************************ ")
time.sleep(1)
i += 1
03-05-2021 04:47 AM
Hi,
I think maybe some mistake during BMG250 initial.
We have formal BMG250 API and example, please refer BMG250-API example to build up your code.
Best regards.