Lidar-Lite not working with Bluz



I juts received my Bluz today.

I have code that runs perfectly on both Arduino and Particle Photon.

However, when compiling the code for Bluz, I am getting compile errors from Arduino.h and Wire.h.

Any help is appreciated.


Can you post a little more information? What libraries are you using? Are you compiling in the Particle Web IDE? What are the specific errors you are seeing?

If possible, can you minimize your code down to the piece that recreates the issue and then post it?

All Arduino and Particle libraries won’t necessarily work with bluz right away, they could require some tweaking. While they all speak the common Wiring language, there can be subtle differences or some libraries use processor specific assembly that isn’t portable from one platform to another.


Hi Eric,

Thank you.

I am not using any libraries (on the Arduino and/or on the Bluz). I am compiling using Particle Web IDE. There are no errors and code is uploaded to board with no problems.

The sketch is actually just a few lines. The sensor measures distance (pulseWidth) which I am storing in the Particle.variable tempC.

tempC is reporting 0 so the board is not reading anything from the sensor. BTW, the same exact code works on Arduino including pin numbers.

unsigned long pulseWidth;
double tempC = 0;

void setup()
  Serial.begin(9600); // Start serial communications
 Particle.variable("tempC", &tempC, DOUBLE);

  pinMode(2, OUTPUT); // Set pin 2 as trigger pin
  digitalWrite(2, LOW); // Set trigger LOW for continuous read

  pinMode(3, INPUT); // Set pin 3 as monitor pin

void loop()
  pulseWidth = pulseIn(3, HIGH); // Count how long the pulse is high in microseconds
  // If we get a reading that isn't zero, let's print it
  if(pulseWidth != 0)
    pulseWidth = pulseWidth / 10; // 10usec = 1 cm of distance
    Serial.println(pulseWidth); // Print the distance


Sorry Eric for the confusion. The sensor I am using has both an i2c interface and a PWM interface.

The i2c interface is giving the compile errors. The i2C interface runs on the Photon.


The PWM interface is the one I am referring to above which does not use any libraries and is not working.


Unfortunately, the pulseIn() function isn’t supported yet on bluz. For our complete set of functions, you can always check the Reference section of our documentation:

We add new functions with each release, so we will mark that one down to support:

In the meantime, you can easily use Interrupts to measure the same thing. Just use a CHANGE event and record the time when it goes high and then low, should be pretty straight forward.


Hello Eric,

Thank you, I appreciate your finding out what was wrong as it has been frustrating. I will look forward to the new release.

In the mean time, can you refer me to a link showing how to use “._…interrupts to measure the same thing. Just use a CHANGE event and record the time when it goes high and then low” o_r a library that cam mimic this behavior.


This is pseudo-code, not at all tested, but something like this:

#define pin D2

volatile bool readPulse = false;
volatile long lastPulseWidth;
volatile long pulseStart;
void detectHighPulse()
  if (digitalRead(pin)==HIGH) {
  } else {

void setup() {
  attachInterrupt(pin, detectHighPulse, CHANGE);

void loop() {
  while (!readPulse);
  Serial1.print("Last pulse: %d", lastPulseWidth);

There is one issue with bluz, and that is that the MCU runs both your code and the BLE stack. So if the BLE radio needs attention, it runs at the highest level of interrupt, meaning it could throw off this timing because it could be dealing with the radio when the pin goes low again. So the timing could be affected.

Depending how sensitive the sensor is, that may or may not matter. If there is an I2C option, that may be the better route, honestly, as there wouldn’t be any timing issues to worry about.


Thank you Eric.

Indeed, there is an i2C option. I plan to try it and will update.

Thanks again.


Sorry I had sent this to you but cannot find it.

I tried to use i2c using this library but I am getting compile errors:

BTW, this library works fine on the Photon.


Hello @eric,

Is the pulseIn() function supported yet?

Thank you.


It is not part of our standard library at the moment


Thank you @eric.

I needed pulsein for a sensor. That sensor works with an Arduino board in one of two modes, i2C and PWM.

Since pulseIN is not supported by Bluz (per your response), I tried using i2C. The code compiled but I did not receive any output from the sensor.

I have attached the way I connected the sensor to the Bluz board. Is this correct or is something missing?

Your help is appreciated.


Well, this sensor requires 5V, bluz is 3.3V. How are you powering everything?


I am using a power supply board which produces 5VDC from a 12VDC input.

Bluz is powered via VIn.