PWM Sensor not working with Bluz


#1

Hello,

I have a PWM sensor. The code I am using is below.

It is working perfectly with Arduino but not working with Bluz as I am getting (pulseWidth =0).

Any help is appreciated.

/*------------------------------------------------------------------------------

LIDARLite Arduino Library
GetDistancePwm

This example shows how to read distance from a LIDAR-Lite connected over the
PWM interface.

Connections:
LIDAR-Lite 5 Vdc (red) to Arduino 5v
LIDAR-Lite Ground (black) to Arduino GND
LIDAR-Lite Mode control (yellow) to Arduino digital input (pin 3)
LIDAR-Lite Mode control (yellow) to 1 kOhm resistor lead 1
1 kOhm resistor lead 2 to Arduino digital output (pin 2)

(Capacitor recommended to mitigate inrush current when device is enabled)
680uF capacitor (+) to Arduino 5v
680uF capacitor (-) to Arduino GND

See the Operation Manual for wiring diagrams and more information:
http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf

------------------------------------------------------------------------------*/

unsigned long pulseWidth;
char stringOne[16];

void setup()
{
  Serial.begin(9600); // Start serial communications
  
  Particle.variable("stringOne", stringOne);

  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
  ltoa(pulseWidth,stringOne,10);
  Particle.publish("Results", String(stringOne) );
  
  // 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
  }
}