Package: bno055-usb-stick-py
BNO055 USB Stick Python driverTL;DR:"Swiss army knife"for usingBNO055 USB Stickunder Linux frompython3.BNO055 USB Stickcomes withDevelopment Desktop 2.0software package,
which is available for Windows only.If you have aBNO055 USB Stickand want to
use it on a Linux platform
(e.g. Ubuntu, Raspbian, Yocto, Suse, etc.)
this repo provides you with apython 3driver,
capable of reading / writing registers / burst read,
and stream data read.OS PrerequisitesWhen plugged in on a Linux system,
theBNO055 USB Stickshould appear
as/dev/ttyACM*device.
This device is a so-calledcdc_acm(communication device class), but let us leave
these details for now.Your Linux user must be a member of thedialoutgroup
(e.g. see thisthread)
to be able to read/writettyACM*devices
without root privileges.udevis installed on the system.
We do autodetect the USB stick by relying on information from
udev.Installationpipinstallbno055_usb_stick_pySupported Python versionpython v3.6+Python dependenciesTL;DR:install
(i)pyserial,
(ii)pyudev,
(iii)dataclasses(if usingpython3.6), and
(iv) optionally:pyquaternionandmatplotlib,
or useenvironment.ymlto create conda environment
with dependencies resolved.For further details regarding creatingcondasenvironment readthisguide.Quick startRead BNO register:frombno055_usb_stick_pyimportBnoUsbStickbno_usb_stick=BnoUsbStick()reg_addr=0x00reg_val=bno_usb_stick.read_register(reg_addr)print(f"bno chip id addr: 0x{reg_addr:02X}, value: 0x{reg_val:02X}")Write register:frombno055_usb_stick_pyimportBnoUsbStickbno_usb_stick=BnoUsbStick()reg_addr=0x3Freg_value=0x01bno_usb_stick.write_register(reg_addr,reg_value)print(f"bno self test started!")Burst register read:frombno055_usb_stick_pyimportBnoUsbStickbno_usb_stick=BnoUsbStick()reg_start_addr=0x08num_registers=0x12burst_read_result=bno_usb_stick.burst_read(reg_start_addr,num_registers)print(f"bno burst read result:{burst_read_result}")Get 10 packets in streaming mode (using generator):frombno055_usb_stick_pyimportBnoUsbStickbno_usb_stick=BnoUsbStick()bno_usb_stick.activate_streaming()forpacketinbno_usb_stick.recv_streaming_generator(num_packets=10):print(f"bno data:{packet}")Get 100 packets in streaming mode (by receiving single packets):frombno055_usb_stick_pyimportBnoUsbStickbno_usb_stick=BnoUsbStick()bno_usb_stick.activate_streaming()for_inrange(100):packet=bno_usb_stick.recv_streaming_packet()print(f"{packet}")Receive infinite number of packets (in case you wait infinite time :wink: ):frombno055_usb_stick_pyimportBnoUsbStickbno_usb_stick=BnoUsbStick()bno_usb_stick.activate_streaming()forpacketinbno_usb_stick.recv_streaming_generator():print(f"{packet}")Bno USB Stick Data PacketWhen receiving data in streaming mode, the result
is an object ofBNO055data class (frombno055.py) file.BNO055data class has the following fields:frombno055_usb_stick_pyimportBNO055bno_data=BNO055()bno_data.a_raw# raw accelerometer data (a_raw_x, a_raw_y, a_raw_z)bno_data.g_raw# raw gyro data (g_raw_x, g_raw_y, g_raw_z)bno_data.m_raw# raw magnetometer data (m_raw_x, m_raw_y, m_raw_z)bno_data.euler_raw# raw euler angles (heading, roll, pitch)bno_data.quaternion_raw# raw quaternion data (q_raw_w, q_raw_x, q_raw_y, q_raw_z)bno_data.lin_a_raw# raw linear acceleration data (lin_a_raw_x, lin_a_raw_y, lin_a_raw_z)bno_data.gravity_raw# raw gravity vector (gravity_raw_x, gravity_raw_y, gravity_raw_z)bno_data.a# accelerometer (a_x, a_y, a_z)bno_data.g# gyroscope (g_x, g_y, g_z)bno_data.m# magnetometer (m_x, m_y, m_z)bno_data.euler# euler angler (heading, roll, pitch)bno_data.quaternion# quaternion values (q_w, q_x, q_y, q_z)bno_data.lin_a# linear acceleration (lin_a_x, lin_a_y, lin_a_z)bno_data.gravity# gravity vector (gravity_x, gravity_y, gravity_z)bno_data.temp# temperature registerbno_data.calib_stat# calibration status (addr 0x35) registerbno_data.st_result# status result (addr 0x36) registerbno_data.int_sta# interrupt status (addr 0x37) registerbno_data.sys_clk_status# system clock status (addr 0x38) registerbno_data.sys_status# system status (addr 0x39) registerPrevent modem manager to capture serial deviceWhen pluggingbno_usb_stickon Ubuntu,
the device is unavailable for the first 10-15 seconds,
due to the fact thatModemManagerprocess
takes over and tries to use the device.To avoid this Ubuntu-specific behavior,
add an exception to theudevrules,
s.t. theModemManagerignores thebno_usb_stick.
Run the script:python disable_modem_manager_bno_usb_stick.pyThe script requires root privileges. Essentially it copies
the97-ttyacm.rulesfile to/etc/udev/rules.dand reloads the
udev rules.MaintainerDr. Konstantin Selyunin,
for suggestions / questions / comments
please contact:
selyunin [dot] k [dot] v [at] gmail [dot] com