Trying to use I2C but only get green blinking

I added this line of code, yet I still get the blinking green and the the device keeps going offline and online according to the Particle Dashboard.
once I disconnect the wires that are connected to D0 and D1 the blinking stops and the code keeps going (printing the error I wrote that we cant find the sensor…)
I am using spark core, maybe the SYSTEM_THREAD(ENABLED) doesnt work on the core? I cant find it on the docs, only for photon and electron, not for the core.

Doh’, I forgot you were using a Core :blush:

In that case finding the blocking section will be your only way out.
I have no such sensor, so it’s a bit hard to check what’s going wrong.

so after some debugging job, I found the area of the code where it starts blinking green, and it makes zero sense.
This is the code:

uint8_t id = read8(BNO055_CHIP_ID_ADDR); Particle.publish("BNO055","right before the if!",30,PRIVATE);//new -CRASHED HERE 1ST TIME X2 delay(15000);//new if(id != BNO055_ID) { Particle.publish("NewBNO055","inside 1st if, ",30,PRIVATE);//new - DOESNT GET HERE delay(15000);//new delay(1000); // hold on for boot id = read8(BNO055_CHIP_ID_ADDR); if(id != BNO055_ID) { Particle.publish("NewBNO055","inside 2nd if, we dont get the id AGAIN ",30,PRIVATE);//new delay(15000);//new return false; // still not? ok bail } }
it prints this line into my dashboard: "Right before the if!"
and doesnt print this line: ""inside 1st if, " meaning the code that is stuck is:

id is equal to 160 and is uint8_t
and BNO055_ID is: #define BNO055_ID (0xA0)
that is also 160… I have no idea whats wrong, this is very weird and random
I will add the fact that when the sensor is not connected, I dont get the green blinking .

You are right, this doesn't make sense.
But Particle.publish() is not the exactest debugging tool.
Serial.print() is better but still not perfect since you print into a buffer and the sending out happens asynchronously.
But it's good for narrowing down.
Once you get closer to the misbehaving code line you can use the the onboard LEDs for exacter checkpoints.

Is your code using async parts like interrupts?

Or it could be that the optimizer fools you a bit. Try adding the id into the publish string.

BTW:

The other reason might be the if() doesn't evaluate true :wink: (which in fact will be the case, given your additional info)

  id        = 160
  BNO055_ID = 160
  if (160 != 160) is NOT not true, so the code inside won't be executed

Well I managed to add a line of delay(1000) and it solved it:

write8(BNO055_SYS_TRIGGER_ADDR, 0x20); delay(1000);//new Particle.publish("BBNO055","after write",30,PRIVATE);//new while (read8(BNO055_CHIP_ID_ADDR) != BNO055_ID)
This delay solves the blinking green problem and now I get the data out of my sensor, dont really know why.
now there is a new problem, after a few times the sensor gives me correct data, at the 6th loop it brings only zeros, I will try to debug and see why it does it.

thanks so far for the help guys

edit:
@ScruffR This is my loop():

void loop() {
  /* Get a new sensor event */
  sensors_event_t event;
  bno.getEvent(&event);

    /* Display the floating point data */
    Serial.print("X: ");
    Serial.print(event.orientation.x, 4);

After 10-15 seconds of it running fine and giving me correct data, it suddenly give me only 0, no idea why…

Hey, I encounter more problems with the bno055 and spark core, and I was wondering if anyone can help.
so I got my bno055 connected, and for 5-10 seconds it gives data, but suddenly after this 5-10 seconds the device goes offline(according to the dashboard), starts blinking green and than restarts itself and the program starts from the beginning, setup and loop.
anyone know whats the problem? or how can I find it? I tried using “printing debug” but didnt anything

That sounds very much like blocking code.
By the few lines of code you provided there, I’d suspect either somewhere in the library or in the loop you just indicated above like this

while (read8(BNO055_CHIP_ID_ADDR) != BNO055_ID)

Once you locate the code that blocks the cloud for more than 10sec, you can start finding ways around that blocking and add Particle.process() wherever blocking is inevitable.

Hey! the code I posted and the line you are talking about are not the problem, this code is not the one that runs in the loop.
I am still trying to find the problem but on luck, the loop is running exactly 3 times, and at the 4 try it crushes , I got device goes offline and start bliking cyan and than, 2 green blinks and blinking cyan again, than after a while the device goes online again and start the setup.
I only call 1 function on the loop. This is the function(and its Inner functions):
The loop():

  sensors_event_t eventUpper;
  bnoUpper.getEvent(&eventUpper);

The getEvent function:

bool Adafruit_BNO055::getEvent(sensors_event_t *event)
{
  /* Clear the event */
  memset(event, 0, sizeof(sensors_event_t));

  event->version   = sizeof(sensors_event_t);
  event->sensor_id = _sensorID;
  event->type      = SENSOR_TYPE_ORIENTATION;
  event->timestamp = millis();

  /* Get a Euler angle sample for orientation */
  imu::Vector<3> euler = getVector(Adafruit_BNO055::VECTOR_EULER);
  event->orientation.x = euler.x();
  event->orientation.y = euler.y();
  event->orientation.z = euler.z();

  return true;
}

the getVector function:

imu::Vector<3> Adafruit_BNO055::getVector(adafruit_vector_type_t vector_type)
{
  imu::Vector<3> xyz;
  uint8_t buffer[6];
  memset (buffer, 0, 6);

  int16_t x, y, z;
  x = y = z = 0;

  /* Read vector data (6 bytes) */
  readLen((adafruit_bno055_reg_t)vector_type, buffer, 6);

  x = ((int16_t)buffer[0]) | (((int16_t)buffer[1]) << 8);
  y = ((int16_t)buffer[2]) | (((int16_t)buffer[3]) << 8);
  z = ((int16_t)buffer[4]) | (((int16_t)buffer[5]) << 8);
  /* Convert the value to an appropriate range (section 3.6.4) */
  /* and assign the value to the Vector type */
  switch(vector_type)
  {
    case VECTOR_MAGNETOMETER:
      /* 1uT = 16 LSB */
      xyz[0] = ((double)x)/16.0;
      xyz[1] = ((double)y)/16.0;
      xyz[2] = ((double)z)/16.0;
      break;
    case VECTOR_GYROSCOPE:
      /* 1rps = 900 LSB */
      xyz[0] = ((double)x)/900.0;
      xyz[1] = ((double)y)/900.0;
      xyz[2] = ((double)z)/900.0;
      break;
    case VECTOR_EULER:
      /* 1 degree = 16 LSB */
      xyz[0] = ((double)x)/16.0;
      xyz[1] = ((double)y)/16.0;
      xyz[2] = ((double)z)/16.0;
      break;
    case VECTOR_ACCELEROMETER:
    case VECTOR_LINEARACCEL:
    case VECTOR_GRAVITY:
      /* 1m/s^2 = 100 LSB */
      xyz[0] = ((double)x)/100.0;
      xyz[1] = ((double)y)/100.0;
      xyz[2] = ((double)z)/100.0;
      break;
  }
  return xyz;
}

and readLen function:

bool Adafruit_BNO055::readLen(adafruit_bno055_reg_t reg, byte * buffer, uint8_t len)
{

  Wire.beginTransmission(_address);
  Wire.write((uint8_t)reg);
  Wire.endTransmission();
  Wire.requestFrom(_address, (byte)len);
  for (uint8_t i = 0; i < len; i++)
  {
    buffer[i] = Wire.read();
  }

  /* ToDo: Check for errors! */
  return true;
}

I tried to find the problem by using partile.publish or serial.print, but for some reaosn when I put this into the code, it doesnt even send 1 data(unlike before i added the print where I add 3 times looping).

Any kind of a direction can help me

Thanks
Asaf