Based on F401 example.Changed reset sequence and added RESET control and Power On/Off control. Check several mbed, LPC1768, LPC1114, NucleoF401RE, F411RE, L152RE and GR-PEACH
Dependencies: BNO055_fusion TextLCD
Please see follows.
/users/kenjiArai/notebook/bno055---orientation-sensor/
Diff: main.cpp
- Revision:
- 6:5f380fbcf849
- Parent:
- 5:9594519c9462
- Child:
- 7:f244ea2ab994
diff -r 9594519c9462 -r 5f380fbcf849 main.cpp --- a/main.cpp Thu Apr 16 11:25:47 2015 +0000 +++ b/main.cpp Wed Aug 23 09:45:18 2017 +0000 @@ -3,26 +3,29 @@ * BNO055 Intelligent 9-axis absolute orientation sensor * by Bosch Sensortec * - * Copyright (c) 2015 Kenji Arai / JH1PJL + * Copyright (c) 2015,'17 Kenji Arai / JH1PJL * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ * Created: March 30th, 2015 - * Revised: April 16th, 2015 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE - * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * Revised: August 23rd, 2017 */ // Include --------------------------------------------------------------------------------------- #include "mbed.h" #include "BNO055.h" +#include "TextLCD.h" // Definition ------------------------------------------------------------------------------------ #define NUM_LOOP 100 +#if MBED_MAJOR_VERSION == 2 +#define WAIT_MS(x) wait_ms(x) +#elif MBED_MAJOR_VERSION == 5 +#define WAIT_MS(x) Thread::wait(x) +#else +#error "Running on Unknown OS" +#endif + // Object ---------------------------------------------------------------------------------------- Serial pc(USBTX,USBRX); #if defined(TARGET_LPC1114) @@ -34,9 +37,18 @@ I2C i2c(p28, p27); // SDA, SCL BNO055 imu(i2c, p29); // Reset =D7, addr = BNO055_G_CHIP_ADDR, mode = MODE_NDOF <- as default #elif defined(TARGET_STM32L152RE) || defined(TARGET_STM32F401RE) || defined(TARGET_STM32F411RE) +#if 0 DigitalOut pwr_onoff(PB_10); +#else +DigitalOut pwr_onoff(PA_9); +#endif I2C i2c(PB_9, PB_8); // SDA, SCL -BNO055 imu(i2c, PA_8); // Reset =D7, addr = BNO055_G_CHIP_ADDR, mode = MODE_NDOF <- as default +#if 0 +BNO055 imu(i2c, PA_8); // Reset = ??, addr = BNO055_G_CHIP_ADDR, mode = MODE_NDOF <- as default +#else +BNO055 imu(PB_9, PB_8, PA_8); +#endif +TextLCD_I2C_N lcd(&i2c, 0x7c, TextLCD::LCD8x2); // LCD(Akizuki AQM0802A) #elif defined(TARGET_RZ_A1H) DigitalOut pwr_onoff(P8_11); I2C i2c(P1_3, P1_2); // SDA, SCL @@ -78,7 +90,7 @@ if ((d & 0x30) == 0x30){ break; } - wait(1.0); + WAIT_MS(1000); } pc.printf("-> Step1) is done\r\n\r\n"); //---------- Magnetometer Caliblation --------------------------------------------------------- @@ -94,7 +106,7 @@ if ((d & 0x03) == 0x03){ break; } - wait(1.0); + WAIT_MS(1000); } pc.printf("-> Step2) is done\r\n\r\n"); //---------- Magnetometer Caliblation --------------------------------------------------------- @@ -109,6 +121,16 @@ pc.printf("(4)ACC:X-9,Y0,Z0,(5)ACC:X0,Y-9,Z0,(6)ACC:X0,Y9,Z0,\r\n"); pc.printf(" If you will give up, hit any key.\r\n", d); t.stop(); + + // lcd + lcd.locate(0, 0); // 1st line top + // 12345678 + lcd.printf(" BNO055 "); + lcd.locate(0, 1); // 2nd line top + // 12345678 + lcd.puts(" JH1PJL "); + lcd.setContrast(0x14); + while (true){ d = imu.read_calib_status(); imu.get_gravity(&gravity); @@ -116,7 +138,7 @@ d, gravity.x, gravity.y, gravity.z); if (d == 0xff){ break;} if (pc.readable()){ break;} - wait(1.0); + WAIT_MS(1000); } if (imu.read_calib_status() == 0xff){ pc.printf("-> All of Calibration steps are done successfully!\r\n\r\n"); @@ -128,7 +150,7 @@ int main(){ imu.set_mounting_position(MT_P6); - pwr_onoff = 0; + pwr_onoff = 1; pc.printf("\r\n\r\nIf pc terminal soft is ready, please hit any key!\r\n"); char c = pc.getc(); pc.printf("Bosch Sensortec BNO055 test program on " __DATE__ "/" __TIME__ "\r\n"); @@ -136,10 +158,10 @@ if (imu.chip_ready() == 0){ do { pc.printf("Bosch BNO055 is NOT avirable!!\r\n Reset\r\n"); - pwr_onoff = 1; // Power off - wait(0.1); - pwr_onoff = 0; // Power on - wait(0.02); + pwr_onoff = 0; // Power off + WAIT_MS(100); + pwr_onoff = 1; // Power on + WAIT_MS(20); } while(imu.reset()); } pc.printf("Bosch BNO055 is available now!!\r\n"); @@ -185,16 +207,16 @@ int main() { uint8_t i; - pwr_onoff = 0; + pwr_onoff = 1; pc.printf("Bosch Sensortec BNO055 test program on " __DATE__ "/" __TIME__ "\r\n"); // Is BNO055 avairable? if (imu.chip_ready() == 0){ do { pc.printf("Bosch BNO055 is NOT avirable!!\r\n"); - pwr_onoff = 1; // Power off - wait(0.1); - pwr_onoff = 0; // Power on - wait(0.02); + pwr_onoff = 0; // Power off + WAIT_MS(100); + pwr_onoff = 1; // Power on + WAIT_MS(20); } while(imu.reset()); } imu.set_mounting_position(MT_P6); @@ -210,35 +232,35 @@ imu.get_Euler_Angles(&euler_angles); pc.printf("Heading:%+6.1f [deg], Roll:%+6.1f [deg], Pich:%+6.1f [deg], #%02d\r\n", euler_angles.h, euler_angles.r, euler_angles.p, i); - wait(0.5); + WAIT_MS(500); } pc.printf("Quaternion data\r\n"); for (i = 0; i < NUM_LOOP; i++){ imu.get_quaternion(&quaternion); pc.printf("W:%d, X:%d, Y:%d, Z:%d, #%02d\r\n", quaternion.w, quaternion.x, quaternion.y, quaternion.z, i); - wait(0.5); + WAIT_MS(500); } pc.printf("Linear accel data\r\n"); for (i = 0; i < NUM_LOOP; i++){ imu.get_linear_accel(&linear_acc); pc.printf("X:%+6.1f [m/s*s], Y:%+6.1f [m/s*s], Z:%+6.1f [m/s*s], #%02d\r\n", linear_acc.x, linear_acc.y, linear_acc.z, i); - wait(0.5); + WAIT_MS(500); } pc.printf("Gravity vector data\r\n"); for (i = 0; i < NUM_LOOP; i++){ imu.get_gravity(&gravity); pc.printf("X:%+6.1f [m/s*s], Y:%+6.1f [m/s*s], Z:%+6.1f [m/s*s], #%02d\r\n", gravity.x, gravity.y, gravity.z, i); - wait(0.5); + WAIT_MS(500); } pc.printf("Chip temperature data\r\n"); for (i = 0; i < (NUM_LOOP / 4); i++){ imu.get_chip_temperature(&chip_temp); pc.printf("Acc chip:%+d [degC], Gyr chip:%+d [degC], #%02d\r\n", chip_temp.acc_chip, chip_temp.gyr_chip, i); - wait(0.5); + WAIT_MS(500); } } }