Giter Site home page Giter Site logo

sparkfun / sparkfun_qwiic_tmf882x_arduino_library Goto Github PK

View Code? Open in Web Editor NEW
8.0 9.0 3.0 4.85 MB

Arduino Library for SparkFun's Qwiic TMF882X breakout boards

Home Page: https://docs.sparkfun.com/SparkFun_Qwiic_TMF882X_Arduino_Library/

License: Other

C++ 16.85% C 83.15%
arduino dtof field-of-view qwiic sparkfun-tutorial

sparkfun_qwiic_tmf882x_arduino_library's Introduction

SparkFun Qwiic TMF882X Arduino Library

SparkFun Qwiic TMF882X dToF Arduino Library

follow on Twitter

Qwiic dToF Imager <br />TMF8820 Qwiic Mini dToF Imager <br />TMF8820 Qwiic dToF Imager <br />TMF8821 Qwiic Mini dToF Imager <br />TMF8821
Qwiic dToF Imager TMF8820
[ SEN-19036 ]
Qwiic Mini dToF Imager TMF8820
[ SEN-19218 ]
Qwiic dToF Imager TMF8821
[ SEN-19037 ]
Qwiic Mini dToF Imager TMF8821
[ SEN-19451 ]

Repository Contents

  • /examples - Example sketches for the library (.ino). Run these from the Arduino IDE.
  • /src - Source files for the library (.cpp, .h).
  • keywords.txt - Keywords from this library that will be highlighted in the Arduino IDE.
  • library.properties - General library properties for the Arduino package manager.

Documentation

Products that use this Library

License Information

This product is open source!

Please review the LICENSE.md file for license information.

If you have any questions or concerns on licensing, please contact technical support on our SparkFun forums.

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

sparkfun_qwiic_tmf882x_arduino_library's People

Contributors

bboyho avatar edspark avatar gigapod avatar jurstu avatar nseidle avatar paulzc avatar sfemark avatar wenn0101 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparkfun_qwiic_tmf882x_arduino_library's Issues

Failed to initialize the sensor - any clues?

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.

Unable to Set Custom I2C ID

I tried setting a new I2C ID using setI2CAddress function. The function returns True , but the communication fails. I tried the following program . I also attached the I2C communication data capturing using Saleae logic analyzer.

/*

  Example-01_Basic.ino

  This demo shows a basic use of a TMF882X device. The device is connected to, 
  and a single reading is taken for each loop iteration. 

  Supported Boards:
  
   SparkFun Qwiic dToF Imager - TMF8820        https://www.sparkfun.com/products/19036
   SparkFun Qwiic Mini dToF Imager - TMF8820   https://www.sparkfun.com/products/19218
   SparkFun Qwiic Mini dToF Imager - TMF8821   https://www.sparkfun.com/products/19451
   SparkFun Qwiic dToF Imager - TMF8821        https://www.sparkfun.com/products/19037
   
  Written by Kirk Benell @ SparkFun Electronics, April 2022

  Repository:
     https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library

  Documentation:
     https://sparkfun.github.io/SparkFun_Qwiic_TMF882X_Arduino_Library/

  SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
*/

#include "SparkFun_TMF882X_Library.h" //http://librarymanager/All#SparkFun_Qwiic_TMPF882X

SparkFun_TMF882X  myTMF882X;
uint8_t new_address = 0x50;

// Structure to hold the measurement results - this is defined by the TMF882X SDK.

static struct tmf882x_msg_meas_results myResults;

void setup()
{

    delay(1000);
    Serial.begin(115200);
    Serial.println("");

    Serial.println("In setup");
    Serial.println("==============================");

    // Initialize the TMF882X device
    if(!myTMF882X.begin())
    {
        Serial.println("Error - The TMF882X failed to initialize - is the board connected?");
        while(1);
    }else
        Serial.println("TMF882X started.");

    Serial.println("Change the device address");
    delay(2000);
    Serial.println(myTMF882X.setI2CAddress(new_address));
    delay(2000);

    // The device is now ready for operations
}

void loop()
{
    delay(2000);
    
    // get a Measurement
    if(myTMF882X.startMeasuring(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 (int 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();
    }
}
[Session 0.zip](https://github.com/sparkfun/SparkFun_Qwiic_TMF882X_Arduino_Library/files/9263378/Session.0.zip)

Compilation errors on NANO 33 IoT (issue with QwI2C class)

When I try to compile one of the example programs, e.g. Example-01_Basic.ino, I get compilation errors related to the QwI2C class in this library.

Steps to reproduce:

  1. Install SparkFun Qwiic TMF882X library via Arduino UI (bug appears on v1.0.0 and v1.0.1)
  2. Create new sketch and copy in some example code
  3. Select Arduino Nano 33 IoT as your board
  4. Click the "verify" checkmark

Full error log:

In file included from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_tmf882x.h:53:0,
                 from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_tmf882x.cpp:52:
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:64:15: error: 'TwoWire' has not been declared
     bool init(TwoWire& wirePort, bool bInit=false);
               ^~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:77:5: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
     TwoWire* _i2cPort;
     ^~~~~~~
     TwoWire_h
In file included from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_tmf882x.h:53:0,
                 from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/sfe_shim.cpp:62:
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:64:15: error: 'TwoWire' has not been declared
     bool init(TwoWire& wirePort, bool bInit=false);
               ^~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:77:5: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
     TwoWire* _i2cPort;
     ^~~~~~~
     TwoWire_h
In file included from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:48:0:
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:64:15: error: 'TwoWire' has not been declared
     bool init(TwoWire& wirePort, bool bInit=false);
               ^~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:77:5: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
     TwoWire* _i2cPort;
     ^~~~~~~
     TwoWire_h
In file included from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_tmf882x.h:53:0,
                 from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/sfe_arduino.cpp:60:
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:64:15: error: 'TwoWire' has not been declared
     bool init(TwoWire& wirePort, bool bInit=false);
               ^~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:77:5: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
     TwoWire* _i2cPort;
     ^~~~~~~
     TwoWire_h
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp: In constructor 'QwI2C::QwI2C()':
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:74:22: error: class 'QwI2C' does not have any field named '_i2cPort'
 QwI2C::QwI2C(void) : _i2cPort{nullptr}
                      ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp: At global scope:
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:83:6: error: prototype for 'bool QwI2C::init(arduino::TwoWire&, bool)' does not match any in class 'QwI2C'
 bool QwI2C::init(TwoWire &wirePort, bool bInit)
      ^~~~~
In file included from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:48:0:
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:64:10: error: candidates are: bool QwI2C::init(int&, bool)
     bool init(TwoWire& wirePort, bool bInit=false);
          ^~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:63:10: error:                 bool QwI2C::init()
     bool init(void);
          ^~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp: In member function 'bool QwI2C::init()':
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:103:10: error: '_i2cPort' was not declared in this scope
     if (!_i2cPort)
          ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:103:10: note: suggested alternative: 'Port'
     if (!_i2cPort)
          ^~~~~~~~
          Port
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:104:31: error: no matching function for call to 'QwI2C::init(arduino::TwoWire&, bool)'
         return init(Wire, true); // no wire, send in Wire and init it
                               ^
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:100:6: note: candidate: bool QwI2C::init()
 bool QwI2C::init(void)
      ^~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:100:6: note:   candidate expects 0 arguments, 2 provided
In file included from /home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:48:0:
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:64:10: note: candidate: bool QwI2C::init(int&, bool)
     bool init(TwoWire& wirePort, bool bInit=false);
          ^~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.h:64:10: note:   no known conversion for argument 1 from 'arduino::TwoWire' to 'int&'
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp: In member function 'bool QwI2C::ping(uint8_t)':
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:116:10: error: '_i2cPort' was not declared in this scope
     if (!_i2cPort)
          ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:116:10: note: suggested alternative: 'Port'
     if (!_i2cPort)
          ^~~~~~~~
          Port
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:119:5: error: '_i2cPort' was not declared in this scope
     _i2cPort->beginTransmission(i2c_address);
     ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:119:5: note: suggested alternative: 'Port'
     _i2cPort->beginTransmission(i2c_address);
     ^~~~~~~~
     Port
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp: In member function 'bool QwI2C::writeRegisterByte(uint8_t, uint8_t, uint8_t)':
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:131:10: error: '_i2cPort' was not declared in this scope
     if (!_i2cPort)
          ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:131:10: note: suggested alternative: 'Port'
     if (!_i2cPort)
          ^~~~~~~~
          Port
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:134:5: error: '_i2cPort' was not declared in this scope
     _i2cPort->beginTransmission(i2c_address);
     ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:134:5: note: suggested alternative: 'Port'
     _i2cPort->beginTransmission(i2c_address);
     ^~~~~~~~
     Port
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp: In member function 'int QwI2C::writeRegisterRegion(uint8_t, uint8_t, uint8_t*, uint16_t)':
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:166:5: error: '_i2cPort' was not declared in this scope
     _i2cPort->beginTransmission(i2c_address);
     ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:166:5: note: suggested alternative: 'Port'
     _i2cPort->beginTransmission(i2c_address);
     ^~~~~~~~
     Port
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp: In member function 'int QwI2C::readRegisterRegion(uint8_t, uint8_t, uint8_t*, uint16_t)':
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:186:10: error: '_i2cPort' was not declared in this scope
     if (!_i2cPort)
          ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:186:10: note: suggested alternative: 'Port'
     if (!_i2cPort)
          ^~~~~~~~
          Port
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:202:9: error: '_i2cPort' was not declared in this scope
         _i2cPort->beginTransmission(addr);
         ^~~~~~~~
/home/carter/Arduino/libraries/SparkFun_Qwiic_TMF882X_Library/src/qwiic_i2c.cpp:202:9: note: suggested alternative: 'Port'
         _i2cPort->beginTransmission(addr);
         ^~~~~~~~
         Port

exit status 1

Compilation error: exit status 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.