Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to initialize the sensor - any clues? #5

Open
renardeinside opened this issue Jun 25, 2023 · 3 comments
Open

Failed to initialize the sensor - any clues? #5

renardeinside opened this issue Jun 25, 2023 · 3 comments

Comments

@renardeinside
Copy link

Hi SparkFun team,

I have a project with the following hardware:

I was unable to find a quick and simple connector between Qwik and shield pins (not entirely sure what they're called), therefore soldered out the following (sorry for the image quality):

  1. 4 pins soldered to the chip - GND, 3V3, SDA, SCL

telegram-cloud-photo-size-2-5244883899052576210-y

  1. Via standard jumper wire they're connected to the shield (respectively to GND, 3V3, SDA and SCL slots):

telegram-cloud-photo-size-2-5244883899052576209-y

  1. Just to verify that slots on the shield are correct:

telegram-cloud-photo-size-2-5244883899052576208-y

  1. After connecting the components I see that the LED on the sensor is glowing red (so I suppose it's connected).

Now in my project, I'm trying to initialize the sensor as follows:

#include "Arduino.h"
#include "Adafruit_TinyUSB.h"
#include "SparkFun_TMF882X_Library.h"

#define SAMPLE_TIMEOUT_MS 3000

SparkFun_TMF882X tofSensor;

void onMeasurementCallback(struct tmf882x_msg_meas_results *myResults)
{

  // print out results
  Serial.println("Measurement:");
  Serial.print("Result Number: ");
  Serial.print(myResults->result_num);
  Serial.print(" Number of Results: ");
  Serial.println(myResults->num_results);

  for (uint32_t i = 0; i < myResults->num_results; ++i)
  {
    Serial.print("    conf: ");
    Serial.print(myResults->results[i].confidence);
    Serial.print(" distance mm: ");
    Serial.print(myResults->results[i].distance_mm);
    Serial.print(" channel: ");
    Serial.print(myResults->results[i].channel);
    Serial.print(" sub_capture: ");
    Serial.println(myResults->results[i].sub_capture);
  }
  Serial.print(" photon: ");
  Serial.print(myResults->photon_count);
  Serial.print(" ref photon: ");
  Serial.print(myResults->ref_photon_count);
  Serial.print(" ALS: ");
  Serial.println(myResults->ambient_light);
  Serial.println();
}

void setup()
{
  Serial.println("Delaying the initialization for 500ms...");
  delay(500);
  Serial.begin(9600);
  Serial.println("Initializing the ToF Sensor");

  if (!tofSensor.begin())
  {
    Serial.println("Error - The TMF882X failed to initialize - is the board connected?");
    while (true)
    {
      Serial.println("Issue with initializing the ToF sensor!");
      delay(500);
    };
  }

  // set our call back function
  tofSensor.setMeasurementHandler(onMeasurementCallback);

  // Set our delay between samples  - 1 second - note it's in ms
  tofSensor.setSampleDelay(700);
}

void loop()
{
  Serial.println("Starting the loop logic in 2 seconds...");
  delay(2000);

  Serial.println("---------------------------------------------------------");
  Serial.print("Taking Samples over a period of: ");
  Serial.print(SAMPLE_TIMEOUT_MS);
  Serial.println(" MS");
  Serial.println();

  // If number of desired samples is 0, the system loops forever - until timeout
  // is hit, or stopped in the callback function.

  int nSamples = tofSensor.startMeasuring(0, SAMPLE_TIMEOUT_MS);

  Serial.print("Took ");
  Serial.print(nSamples);
  Serial.println(" data samples.");
  Serial.println();

  Serial.println("---------------------------------------------------------\n\n");
}

But on the serial output I see:

Issue with initializing the ToF sensor!
Issue with initializing the ToF sensor!
Issue with initializing the ToF sensor!
Issue with initializing the ToF sensor!
Issue with initializing the ToF sensor!

So I suppose that something is missing here. Probably I've misconfigured something. Any help would be appreciated, and please note I'm quite a beginner so any explanation or clue would be helpful.

@PaulZC
Copy link
Contributor

PaulZC commented Jun 26, 2023

Hi Ivan (@renardeinside ),

Do you have another way to test the I2C "Wire" interface? The TMF882X library defaults to using the "Wire" I2C interface. Maybe the XIAO has more than one Wire port (e.g. Wire1)? Do you have another I2C sensor you can try? Or can you run a Wire port scanner example - it should detect the TMF8821 at address 41 Hex, 65 Decimal?

I hope this helps,
Paul

@renardeinside
Copy link
Author

hi @PaulZC ,
it seems like your clues are correct. I'm not entirely sure what's happening under the hood, but I was able to identify the following behavior:

  1. When I run I2C Scanner on a board itself (without the Shield attached), it runs fine - since no I2C devices are connected, the scanner reports "no devices" (as expected).
  2. However, if I plug the board into the shield, the I2C scanner hangs on one of the following lines:
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

The only thing I understand is that the issue is irrelevant to the sensor itself - it's somehow related to the way how shield attachment works with the Wire library.

@PaulZC
Copy link
Contributor

PaulZC commented Jun 26, 2023

Hi Ivan,

The I2C Scanner should still work when you attach the Shield (but do not attach the sensor). Please check your soldering and wiring. Is SCL or SDA shorted to GND (or 3.3V)?

Best wishes,
Paul

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants