Skip to content

Failed to initialize the sensor - any clues? #5

Open
@renardeinside

Description

@renardeinside

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions