hanyazou / BMI160-Arduino

76 stars 35 forks source link

Works on Arduino UNO, fails on any ESP8266 #4

Closed PeterRhysJenkins closed 7 years ago

PeterRhysJenkins commented 7 years ago

Hi,

I am trying to get data from an ESP8266 - NodeMCU ESP12-E connected BMI160 via I2C.

The sample code - very slightly modified below - works on a Genuine Arduino UNO. It fails on any ESP8266. I have included the #DEBUG output from both.

Can you give me any idea how to start fixing this problem ?

/ Start of Sketch. This works with a real Arduino UNO. We butchered BMI160Gen.h to use 0x69 for the I2C interface. /

/ This sketch example demonstrates how the BMI160 on the Intel(R) Curie(TM) module can be used to read gyroscope data /

include

include

const int select_pin = 13; // GPIO 13 void setup() { pinMode(select_pin, OUTPUT); // start BMI160 Serial.begin(115200); // initialize Serial communication while (!Serial); // wait for the serial port to open digitalWrite(select_pin, LOW); // LED ON. // initialize device // Wire.begin(4,5); Serial.println("Initializing IMU device..."); delay(5000); // BMI160.begin(BMI160GenClass::SPI_MODE, / SS pin# = /10); BMI160.begin(BMI160GenClass::I2C_MODE); delay(5000); uint8_t dev_id = BMI160.getDeviceID(); Serial.print("DEVICE ID: "); Serial.println(dev_id, HEX);

// Set the accelerometer range to 250 degrees/second BMI160.setGyroRange(250); Serial.println("Initializing IMU device...done."); }

void loop() { int gxRaw, gyRaw, gzRaw; // raw gyro values float gx, gy, gz;

// read raw gyro measurements from device BMI160.readGyro(gxRaw, gyRaw, gzRaw);

// convert the raw gyro data to degrees/second gx = convertRawGyro(gxRaw); gy = convertRawGyro(gyRaw); gz = convertRawGyro(gzRaw);

// display tab-separated gyro x/y/z values Serial.print("g:\t"); Serial.print(gx); Serial.print("\t"); Serial.print(gy); Serial.print("\t"); Serial.print(gz); Serial.println();

delay(500); }

float convertRawGyro(int gRaw) { // since we are using 250 degrees/seconds range // -250 maps to a raw value of -32768 // +250 maps to a raw value of 32767

float g = (gRaw * 250.0) / 32768.0;

return g; }

/ Copyright (c) 2016 Intel Corporation. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /

And here's the debug output:

This is debug output when I run on a real Arduino UNO which also finds I2C on 0X69 This works - you can see the x y and z values at the bottom of the output.

Initializing IMU device... BMI160GenClass::i2c_init()... i2c_xfer(offs=0x0, tx=1, rx=1): D1 BMI160GenClass::i2c_init(): CHIP ID = 0xD1 BMI160GenClass::i2c_init()...done i2c_xfer(offs=0x7F, tx=1, rx=1): 0 i2c_xfer(offs=0x7E, tx=2, rx=0): i2c_xfer(offs=0x7F, tx=1, rx=1): 0 i2c_xfer(offs=0x7E, tx=2, rx=0): i2c_xfer(offs=0x3, tx=1, rx=1): 10 i2c_xfer(offs=0x7E, tx=2, rx=0): i2c_xfer(offs=0x3, tx=1, rx=1): 10 i2c_xfer(offs=0x3, tx=1, rx=1): 10 i2c_xfer(offs=0x3, tx=1, rx=1): 10 i2c_xfer(offs=0x3, tx=1, rx=1): 10 i2c_xfer(offs=0x3, tx=1, rx=1): 10 i2c_xfer(offs=0x3, tx=1, rx=1): 10 i2c_xfer(offs=0x3, tx=1, rx=1): 14 i2c_xfer(offs=0x43, tx=1, rx=1): 0 i2c_xfer(offs=0x43, tx=2, rx=0): i2c_xfer(offs=0x41, tx=1, rx=1): 3 i2c_xfer(offs=0x41, tx=2, rx=0): i2c_xfer(offs=0x55, tx=2, rx=0): i2c_xfer(offs=0x56, tx=2, rx=0): i2c_xfer(offs=0x57, tx=2, rx=0): i2c_xfer(offs=0x0, tx=1, rx=1): D1 i2c_xfer(offs=0x0, tx=1, rx=1): D1 DEVICE ID: D1 i2c_xfer(offs=0x43, tx=1, rx=1): 3 i2c_xfer(offs=0x43, tx=2, rx=0): Initializing IMU device...done. i2c_xfer(offs=0xC, tx=1, rx=6): 5 0 33 0 DE FF g: 0.04 0.39 -0.26 i2c_xfer(offs=0xC, tx=1, rx=6): 9 0 31 0 DE FF g: 0.07 0.37 -0.26

Exact same code on ESP8266 - BMI160GEN.h still with 0X69 The CPU goes into Panic. ⸮Initializing IMU device... BMI160GenClass::i2c_init()... i2c_xfer(offs=0x0, tx=1, rx=1): D1 BMI160GenClass::i2c_init(): CHIP ID = 0xD1 BMI160GenClass::i2c_init()...done i2c_xfer(offs=0x7F, tx=1, rx=1): 0 i2c_xfer(offs=0x7E, tx=2, rx=0): Panic :-1 ctx: cont sp: 3ffef380 end: ffffffff offset: 01b0 >>>stack>>> 3ffef530: ffffffff ffffffff ffffffff ffffffff
hanyazou commented 7 years ago

I've fixed the bug in b2407aa.