Propeller Activity Board + SimpleIDE + Adafruit BNO055
TryingToTeach
Posts: 7
My computer programming class is in a little robot maze competition using the Activity bot. We purchased an Adafruit BNO055 IMU fusion sensor. It appears that the Activity Board supports I2C communication so we figured there should be some tutorials out there on how to use this sensor. However through much searching we have come up empty. Adafruit has tutorials for Adruino, raspberry PI, but as we are new to programming we have not been able to convert them to our needs. I was wondering if it is possible to use this sensor, and if someone could help us get started or point us to a usable resource.
Comments
So, how do you get started with I2C? You probably want to start here (http://learn.parallax.com/propeller-c-simple-protocols/diy-i2c), on Parallax's own website. Once you're comfortable with the general concept of serial communication and I2C's addressing scheme, take a look at your three different C/C++ options:
1) i2c_*() functions in the "Simple" libraries. These C functions come with SimpleIDE and were written by Parallax. I believe they are documented in various places. I host doxygen documentation here for these functions (note that I am not a Parallax employee or affiliated in any way with Parallax).
2) Use PropWare's I2C class. This is my favorite, because I wrote it. It is documented here and you can read these instructions for getting PropWare up and running in SimpleIDE. Take a look at this example usage of using it to read from and write to the board's EEPROM chip.
3) Use libpropeller's I2C class. I actually started PropWare's I2C classes by copying and pasting these. Documented here. One big difference is that you can use libpropeller::I2C in SimpleIDE simply by copying i2c.h and i2cbase.h into your project. PropWare's classes require a few more dependencies than that which is why I recommend following the linked instructions if you go that route.
Alright! That should keep you busy for a bit right?
I suspect that code is in Spin, but it shouldn't be terribly difficult to port it over, using the i2c_ resources David mentioned above.
As a starting point for the BNO055 module I can recommend rjo's BNO055roughdraft2 program in the link provided by Jason above.
In this program I2C is easily handled by an existing object.
Once you can see the output of the BNO055 registers and become confident with the module it is quite easy to move on to your own application.
I suggest you build a simple demonstration gimbal for the module - your students could have a lot of fun, and there is a lot of educational potential!
#include "simpletools.h"
#include "simplei2c.h"
#define BNO055_ADDRESS_B (0x29)
#define BNO055_CHIP_ID_ADDR 0x00
int main() // Main function
{
int8_t temp;
char data[] = {0,0,0,0,0,0,0,0};
pause(1000);
print("Begin test:\n");
i2c *bus = i2c_newbus(1, 0, 0); // New I2C bus SCL=P1, SDA=P0
print("%c", HOME);
while(1) // Repeat indefinitely
{
print("%c", HOME);
print("reading:\n");
i2c_out(bus, 0x29 , BNO055_CHIP_ID_ADDR, 1, data, 8);
while(i2c_busy(bus,0x29));
print("while done:\n");
i2c_in(bus, 0x29 , BNO055_CHIP_ID_ADDR, 1, data, 8);
print("data=%d\n", data[0], CLREOL);
pause(1000);
}
}
Do you have an example not using the EEPROM chip?
Also can you help me with how to change the scl and sda from default.
The PCF8591 object in PropWare uses I2C communication. You can find its source here.
The constructor for PropWare::I2C takes three parameters, but all of them have default values which is why my examples do not use any parameters. If you wanted to use pins 0 and 1 on the Propeller as SCL and SDA respectively, you could construct an instance like so:
or to make it more legible, and easier to tell which pins are used for what
Thanks for your help so far.
Any Other ideas?
Thanks for the help.
That's tough now, since I don't have my own BNO055 to test with. Is it possible that you have P0 and P1 mixed up? It's certainly an easy thing to try.
Aside from that, I don't think I can be any more help without at least one of the following:
1) A picture of your circuit, with wires and their connection points all clearly visible
2) Output from a logic analyzer or oscilloscope showing the I2C communication.
Thanks again.
Use the test code that shows the status registers. You need all 3's for reliable Z axis or it will drift. If you don't move it far you can use previous calibration values in the code to save time and awkward flipping around of your robot. Also try not to bump into anything, I found that will cause some Z drift.
I'm having the exact same problem, but with a P2 and an Arduino shield board. Has anybody figured out what was the cause of the BNO055 not responding? Does it need special timing or a special init/reset sequence?