The initialization of the ToF fails with this code. I'm trying to frankenstein it with Radiohead RFM69, so far no luck.

// rf69_reliable_datagram_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple addressed, reliable messaging client
// with the RHReliableDatagram class, using the RH_RF69 driver to control a RF69 radio.
// It is designed to work with the other example rf69_reliable_datagram_server
// Tested on Moteino with RFM69 http://lowpowerlab.com/moteino/
// Tested on miniWireless with RFM69 www.anarduino.com/miniwireless
// Tested on Teensy 3.1 with RF69 on PJRC breakout board

#include <RHReliableDatagram.h>
#include <RH_RF69.h>
#include <SPI.h>

#include "Seeed_vl53l0x.h"
Seeed_vl53l0x VL53L0X;


// Singleton instance of the radio driver
RH_RF69 driver;
//RH_RF69 driver(15, 16); // For RF69 on PJRC breakout board with Teensy 3.1
//RH_RF69 rf69(4, 2); // For MoteinoMEGA https://lowpowerlab.com/shop/moteinomega

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, CLIENT_ADDRESS);

void setup()
  VL53L0X_Error Status = VL53L0X_ERROR_NONE;
  if (!manager.init())
    Serial.println(F("init failed"));

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM

  // If you are using a high power RF69, you *must* set a Tx power in the
  // range 14 to 20 like this:
  // driver.setTxPower(14);

  Status = VL53L0X.VL53L0X_common_init();
  if (VL53L0X_ERROR_NONE != Status) {
    Serial.println(F("start vl53l0x mesurement failed!"));
    while (1);


  if (VL53L0X_ERROR_NONE != Status) {
    Serial.println(F("start vl53l0x mesurement failed!"));
    while (1);


unsigned int findDistance() {
  VL53L0X_RangingMeasurementData_t RangingMeasurementData;
  VL53L0X_Error Status = VL53L0X_ERROR_NONE;

  memset(&RangingMeasurementData, 0, sizeof(VL53L0X_RangingMeasurementData_t));
  Status = VL53L0X.PerformSingleRangingMeasurement(&RangingMeasurementData);
  if (VL53L0X_ERROR_NONE == Status) {
    if (RangingMeasurementData.RangeMilliMeter >= 2000) {
      Serial.println(F("out of range!!"));
    } else {
      //Serial.print("Measured distance:");
      //Serial.println(" mm");
      return RangingMeasurementData.RangeMilliMeter;
  } else {
    Serial.print(F("mesurement failed !! Status code ="));
    return 0;

uint8_t data[] = "Hello..there";
// Dont put this in the stack:
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];

void loop()
  //Serial.println("Sending to rf69_reliable_datagram_server");

  // Send a message to manager_server
  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
    // Now wait for a reply from the server
    uint8_t len = sizeof(buf);
    uint8_t from;
    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
      Serial.print(F("got reply from : 0x"));
      Serial.print(from, HEX);
      Serial.print(F(": "));
      Serial.println(F("No reply, is rf69_reliable_datagram_server running?"));
    Serial.println(F("sendtoWait failed"));
  • 1
    Please try the I2C Scanner sketch to check, if it can find the sensor on the standard address 0x29, which is used in the library. If it cannot find any device, the communication does not work.Then check the wiring, add strong pullup resistors to the I2C lines (4.7kOhm for example). And include your wiring in the question.
    – chrisl
    Apr 18, 2020 at 20:14
  • @chrisl thanks for your response, an important point to mention is that the code works when run alone, its only when I combine the sensor code with the radio module code i run into problems. Thanks again
    – Mr Joseph
    Apr 19, 2020 at 9:17


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.