Bosch BNO055 Library Port

Has anyone looked at porting the Bosch BNO055 library. I have and application that uses the 9-Axis shield and the Bosch library with and Arduino Mega and the YUN Shield. I would like to use this on Particle.

I started to see if it would be easy to port and had thing down to a couple of issues and the fix for that exploded into 370 errors where I get errors like ‘uint8_t does not name a type’ from statements like the one below.

#define BNO055_WR_FUNC_PTR int8_t (*bus_write)\
(uint8_t, uint8_t , uint8_t *, uint8_t)

The original code was rather abstract it what looks like an attempt to make the library work on nearly any machine as it had a typedefs like this and macros like the above:

/* singed integer type*/
typedef	int8_t s_8;/**< used for signed 8bit */
typedef	int16_t s_16;/**< used for signed 16bit */
typedef	int32_t s_32;/**< used for signed 32bit */
typedef	int64_t s_64;/**< used for signed 64bit */

But these caused problems so I did a simple replace of “s_8” with “int8_t” which solved most problems but I am kind of stuck do impart from my limited knowledge of the c language.

Anyone have any ideas?

Thanks

Kurt

Could you use the Adafruit_BNO055 library instead. That one looks like it would be very straight forward to port.

I ported and consolidated Adafruit_BNO055 recently.

I’m sure that I could rework my application. I need the ability to store and recall calibration and I don’t know if the Adafruit lib can do that. Also I spent significant time getting my application working.

Do you know why the c code isn’t compatible? It seems that Bosch went to extremes to make their code easy to port to machines with different word lengths. Either they used some nonstandard C constructs or the Particle platform does.

Kurt

I don’t know if this will work, but it does compile. I was getting lots of duplicate definition errors, so i got rid of almost all the typedef’s at the top of the .h file leaving this as the top of that file down to where it says, “BUS READ AND WRITE FUNCTIONS”

#ifndef __BNO055_H__
#define __BNO055_H__

#include <stdint.h>


/*unsigned integer types*/
typedef	uint8_t u8;/**< used for unsigned 8bit */
typedef	uint16_t u16;/**< used for unsigned 16bit */
typedef	uint32_t u32;/**< used for unsigned 32bit */


/*signed integer types*/
typedef	int8_t s8;/**< used for signed 8bit */
typedef	int16_t s16;/**< used for signed 16bit */
typedef	int32_t s32;/**< used for signed 32bit */


typedef	signed char  s8;/**< used for signed 8bit */
typedef	signed short int s16;/**< used for signed 16bit */
typedef	signed long int s32;/**< used for signed 32bit */


/*unsigned integer types*/
typedef	unsigned char u8;/**< used for unsigned 8bit */
typedef	unsigned short int u16;/**< used for unsigned 16bit */
typedef	unsigned long int u32;/**< used for unsigned 32bit */


/***************************************************************/
/**\name	BUS READ AND WRITE FUNCTIONS           */
/***************************************************************/

After Edit:

I just tested replacing #include < stdint.h> with #include < Particle.h>, and with that change, none of those typedefs seem to be necessary (i.e. it compiles without them).

Ric

Were you able to compile the entire library with these changes?

NAxisMotion.cpp
NAxisMotion.h
BNO055.cpp
BNO055.h

Kurt

I didn’t see the NAxisMotion files. I just made the changes I mentioned above, and compiled a simple .ino file with the bno055.h and bno055.cpp files added to the app (via the tabs).

I was trying to duplicate your results. I took a fresh copy of BNO055.h and BNO055.c (renamed to BNO055.cpp) and a file BNO.ino. I changed BON055.h line 113 to #include <Particle.h> ad nothing else but I get 30 errors.

The first error is “expected identifier before ‘(’ token” …BNO055.h:759:22

Is this what you did in your Edit:

Did you delete all the stuff at the top of the .h file like I mentioned in my post? The top of the file should just be,

#ifndef __BNO055_H__
#define __BNO055_H__

#include <Particle.h>



/***************************************************************/
/**\name	BUS READ AND WRITE FUNCTIONS           */
/***************************************************************/
etc.

Ric

Thank you helping me with this. I don’t know what I am doing wrong. This is however the first thing I have tried with the Particle so there are a lot of things (everything really) about the development environment.

I created a project and added the files BNO055.h and BNO055.cpp that I downloaded from https://github.com/arduino-org/brackets-arduino and then decided I should try https://github.com/BoschSensortec/BNO055_driver in case there were differences but the results are the same.

BNO055.h looks like this:

#ifndef __BNO055_H__
#define __BNO055_H__

#include <Particle.h>

/***************************************************************/
/**\name	BUS READ AND WRITE FUNCTIONS           */
/***************************************************************/
#define BNO055_WR_FUNC_PTR s_8 (*bus_write)\
(u_8, u_8 , u_8 *, u_8)

I think we have the same code but something I am doing is wrong.

The complier trips up on line 759

#define ARRAY_SIZE_TWO		2

with the error : unexpected identifier before ‘(’ token

I don’t even see a ( in this line.

Kurt

What happened to the formatting on that post?

You need to do this,

```cpp
// your code here
```

I don’t have the line “#define ARRAY_SIZE_TWO 2” in either the .h or .cpp file, so there is something different between our two apps. Could that be in your .ino file? The error should say which file it’s in.

I would remove that backslash in this part

#define BNO055_WR_FUNC_PTR s_8 (*bus_write)\
(u_8, u_8 , u_8 *, u_8)

and just write

#define BNO055_WR_FUNC_PTR s_8 (*bus_write)(u_8, u_8 , u_8 *, u_8)

On the other hand, why is this a #define and not a typedef?

Otherwise could you post the code round about the proposed error line 759?
If you can’t see the problem at that position it may well be somewhere near it :wink:

Is there a way I can post the code?

Have you got the code in Web IDE oron GitHub?
With Web IDE you can create a snapshot and post a link to that or you just post the GitHub link.

Ric

It is in the bno055.h file. Here is a screen shot of the errors and the code near

This code was downloaded from the Bosch github page.

I have it on my Mac and I am using the local IDE. I was thinking of putting it into the Web IDE.

I also got my file from a Bosch Github page (here), but my code doesn’t have those lines. Can you post a link to the page where you got the code?

I see one issue in your screenshot.
You cannot have a .cpp file and an .ino file of the same name in your project.

.ino files are preprocessed and converted into a .cpp and that means you get two conflicting files with the same name.