Qwiic Distance Sensor (RFD77402) Hookup Guide

Pages
Contributors: Englandsaurus
Favorited Favorite 3

Library Overview

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

First, you'll need to download SparkFun's RFD77402 Library. This can be done by using the below button or by utilizing the Arduino library manager. You can also grab the latest, greatest version over on the library's GitHub repository.

Before getting started, let's check out the publicly available functions of our library.

  • boolean begin(TwoWire &wirePort = Wire, uint32_t i2cSpeed = I2C_SPEED_STANDARD); --- Initializes the RFD77402 sensor on a given I2C bus, with a given I2C speed. This function will default to the primary I2C bus and standard I2C speed if called without any arguments.
  • uint8_t takeMeasurement(); --- Takes a single measurement and sets the global variables with new data.
  • uint16_t getDistance(); --- Returns the local variable distance to the caller.
  • uint8_t getValidPixels(); --- Returns the number of valid pixels found when taking measurement.
  • uint16_t getConfidenceValue(); --- Returns the qualitative value representing how confident the sensor is about its reported distance.
  • uint8_t getMode(); --- Read the command opcode and convert to the corresponding mode.
  • boolean goToStandbyMode(); --- Tell MCPU to go to standby mode. Return true if successful.
  • boolean goToOffMode(); --- Tell MCPU to go to off state. Return true if successful.
  • boolean goToOnMode(); --- Tell MCPU to go to on state. Return true if successful.
  • boolean goToMeasurementMode(); --- Tell MCPU to go to measurement mode. Takes a measurement. If measurement data is ready, return true.
  • uint8_t getPeak(); --- Returns the VCSEL peak 4-bit value.
  • void setPeak(uint8_t peakValue); --- Sets the VCSEL peak 4-bit value.
  • uint8_t getThreshold(); --- Returns the VCSEL Threshold 4-bit value.
  • void setThreshold(uint8_t threshold); --- Sets the VCSEL Threshold 4-bit value.
  • uint8_t getFrequency(); --- Returns the VCSEL Frequency 4-bit value.
  • void setFrequency(uint8_t threshold); --- Sets the VCSEL Frequency 4-bit value.
  • uint16_t getMailbox(); --- Gets whatever is in the 'MCPU to Host' mailbox. Check Interrupt Control Status Register bit 5 before reading.
  • void reset(); --- Software reset the device
  • uint16_t getChipID(); --- Returns the chip ID. Should be 0xAD01 or higher.
  • boolean getCalibrationData(); --- Retrieves 2 sets of 27 bytes from MCPU for computation of calibration parameters. 54 bytes are read into the calibration array, true is returned if new calibration data is loaded successfully.
  • uint16_t readRegister16(uint8_t addr); --- Reads two bytes from a given location from the RFD77402.
  • uint8_t readRegister(uint8_t addr); --- Reads from a given location from the RFD77402.
  • void writeRegister16(uint8_t addr, uint16_t val); --- Write a 16 bit value to a spot in the RFD77402.
  • void writeRegister(uint8_t addr, uint8_t val); --- Write a value to a spot in the RFD77402.