upm icon indicating copy to clipboard operation
upm copied to clipboard

RuntimeError: UPM Runtime Error: BMI160: bmi160_init() failed

Open trixr4kdz opened this issue 6 years ago • 4 comments

Hi,

I currently have the Intel Aero RTF drone running Ubuntu 16.04 LTS and I wanted to be able to read the IMU data from the BMI160 chip that is built into the compute board, but I am stuck with initializing the device. The Intel Aero guide says that the BMI160 chip uses bus 3 on chip 0.

Here is the simple code I'm trying to run currently based off the examples:

#!/usr/bin/env python

from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_bmi160 as sensorObj

sensor = sensorObj.BMI160(3, -1, 0, False)

And the error I am getting is the following:

bmi160_init: mraa_spi_init() failed.
Traceback (most recent call last):
  File "/home/trixie/imu_ws/src/aero_imu/scripts/test.py", line 7, in <module>
    sensor = sensorObj.BMI160(3, -1, 0, False)
  File "/usr/local/lib/python2.7/dist-packages/upm/pyupm_bmi160.py", line 161, in __init__
    this = _pyupm_bmi160.new_BMI160(bus, address, csPin, enableMag)
RuntimeError: UPM Runtime Error: BMI160: bmi160_init() failed

I also installed mraa and upm via ppa and there didn't seem to be any problems.

I am currently at a loss as to how to make this work so any help will be greatly appreciated.

Thanks! Trixie

trixr4kdz avatar Mar 06 '18 01:03 trixr4kdz

Hi, to use MRAA & UPM with the Intel Aero board you'll need to initialize MRAA using a JSON platform file. The mraa.initJsonPlatform(std::string path) → mraa::Result function would do it, but make sure to import mraa in your code too. I don't remember if the PPA version of the libraries have JSON platform support enabled, if this function call fails, you'll need to recompile MRAA and UPM from source. It's pretty straightforward and explained in our building documentation.

You can find the platform file for Intel Aero here.

Once initialized, SPI bus 3 is exposed as bus 0 in MRAA, thus your BMI160 constructor should look like this sensor = sensorObj.BMI160(0, -1, -1, False). Setting the CS pin to -1 assumes it's hardware controlled.

Also, please note that the Intel Aero board supports Yocto officially. Ubuntu 16.04 might not expose the SPI bus in user space for MRAA to use, although there might be kernel patches available to work around this.

Propanu avatar Mar 06 '18 15:03 Propanu

Oh, I see. I missed that part from the mraa repository. I will check it out. Thank you so much!

EDIT: I'm trying to compile upm from source, but now I get the following error:

[ 23%] Building C object src/my9221/CMakeFiles/my9221-c.dir/my9221.c.o
/home/trixie/GitHub/upm/src/my9221/my9221.c: In function ‘my9221_init’:
/home/trixie/GitHub/upm/src/my9221/my9221.c:102:5: error: ‘mraa_gpio_use_mmaped’ is deprecated [-Werror=deprecated-declarations]
     if (mraa_gpio_use_mmaped(dev->gpioClk, 1))
     ^
In file included from /home/trixie/GitHub/upm/src/my9221/my9221.h:41:0,
                 from /home/trixie/GitHub/upm/src/my9221/my9221.c:42:
/usr/local/include/mraa/gpio.h:279:26: note: declared here
 DEPRECATED mraa_result_t mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_b
                          ^
/home/trixie/GitHub/upm/src/my9221/my9221.c:106:5: error: ‘mraa_gpio_use_mmaped’ is deprecated [-Werror=deprecated-declarations]
     if (mraa_gpio_use_mmaped(dev->gpioData, 1))
     ^
In file included from /home/trixie/GitHub/upm/src/my9221/my9221.h:41:0,
                 from /home/trixie/GitHub/upm/src/my9221/my9221.c:42:
/usr/local/include/mraa/gpio.h:279:26: note: declared here
 DEPRECATED mraa_result_t mraa_gpio_use_mmaped(mraa_gpio_context dev, mraa_b
                          ^
/home/trixie/GitHub/upm/src/my9221/my9221.c: At top level:
cc1: error: unrecognized command line option ‘-Wno-misleading-indentation’ [-Werror]
cc1: all warnings being treated as errors
src/my9221/CMakeFiles/my9221-c.dir/build.make:62: recipe for target 'src/my9221/CMakeFiles/my9221-c.dir/my9221.c.o' failed
make[2]: *** [src/my9221/CMakeFiles/my9221-c.dir/my9221.c.o] Error 1
CMakeFiles/Makefile2:9914: recipe for target 'src/my9221/CMakeFiles/my9221-c.dir/all' failed
make[1]: *** [src/my9221/CMakeFiles/my9221-c.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

I think the problem may be that I didn't do this initial step:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:.../mraa/build/lib/pkgconfig

because there wasn't a lib directory in my mraa build.

EDIT2: I got rid of Werror in the CMakeLists.txt file so the warnings are not recognized as errors so now the build is going through.

EDIT3: I'm getting a Segmentation fault error now. Here is the current code I'm trying to run

#!/usr/bin/env python

from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_bmi160 as sensorObj
import mraa

mraa.initJsonPlatform('./intel-aero.json')
sensor = sensorObj.BMI160(0, -1, -1, False)

trixr4kdz avatar Mar 06 '18 19:03 trixr4kdz

Can you please post the MRAA log you get from journalctl -f or were you able to figure it out?

Propanu avatar May 25 '18 18:05 Propanu

@trixr4kdz Did you figure this out? Is it possible to how you access BMI160?

yehmostabsurd avatar Jun 14 '19 05:06 yehmostabsurd