I have managed to read the calibration values of the sensor and save them in a file.
The problem I have is when I want to insert these values into the sensor, it throws some errors that I can not explain why I put the script and your help will be very useful
archivo = open("data.txt","r")
data1= archivo.readline()
data = list(data1.split()) #
print ("longitud de data =", len(data))
print ("tipo de dato =", type(data))
bno.set_calibration(data)
print(" Se a grabado exitosamente la calibracion al BNO055")
archivo.close()
The error you give me is
Traceback (most recent call last):
File "menuV3.py", line 168, in <module>
bno.set_calibration(data)
File "/home/pi/Adafruit_BNO055/BNO055.py", line 554, in set_calibration
self._write_bytes(ACCEL_OFFSET_X_LSB_ADDR, data)
File "/home/pi/Adafruit_BNO055/BNO055.py", line 290, in _write_bytes
command[4:] = map(lambda x: x & 0xFF, data)
File "/home/pi/Adafruit_BNO055/BNO055.py", line 290, in <lambda>
command[4:] = map(lambda x: x & 0xFF, data)
TypeError: unsupported operand type(s) for &: 'str' and 'int'
Here I show you what the bno.set_calibration (data) function does
def set_calibration(self, data):
"""Set the sensor's calibration data using a list of 22 bytes that
represent the sensor offsets and calibration data. This data should be
a value that was previously retrieved with get_calibration (and then
perhaps persisted to disk or other location until needed again).
"""
# Check that 22 bytes were passed in with calibration data.
if data is None or len(data) != 22:
raise ValueError('Expected a list of 22 bytes for calibration data.')
# Switch to configuration mode, as mentioned in section 3.10.4 of datasheet.
self._config_mode()
# Set the 22 bytes of calibration data.
self._write_bytes(ACCEL_OFFSET_X_LSB_ADDR, data)
# Go back to normal operation mode.
self._operation_mode()
Finally I show you the function write_bytes
def _write_byte(self, address, value, ack=True):
# Write an 8-bit value to the provided register address. If ack is True
# then expect an acknowledgement in serial mode, otherwise ignore any
# acknowledgement (necessary when resetting the device).
if self._i2c_device is not None:
# I2C write.
self._i2c_device.write8(address, value)
else:
# Build and send serial register write command.
command = bytearray(5)
command[0] = 0xAA # Start byte
command[1] = 0x00 # Write
command[2] = address & 0xFF
command[3] = 1 # Length (1 byte)
command[4] = value & 0xFF
resp = self._serial_send(command, ack=ack)
# Verify register write succeeded if there was an acknowledgement.
if ack and resp[0] != 0xEE and resp[1] != 0x01:
raise RuntimeError('Register write error: 0x{0}'.format(binascii.hexlify(resp)))