Hello everyone,
I’ve just bought a super-cool Shield Shield. I’m currently looking to connect a LIDAR sensor to it.
Currently, I have the LIDAR sensor connected to the 5V output and ground. What I would like to do is get a continuous reading (every second) to display in the serial monitor. I currently have the Shield Shield powered by USB, with the monitor and trigger pins connected to pins 12 and 11 on the Shield Shield, respectively. They map to D3 and D2 on the Photon respectively, according to https://docs.particle.io/datasheets/particle-shields/#shield-shield-pin-mapping
However, I can not get a reading from the Photon to appear in my serial monitor (the returned pulseWidth is always 0). Does anyone know why this might be the case?
Previous testing:
- I connected the 5V and ground pins to an Arduino, and connected the monitor and trigger pins to the Photon (without the Shield Shield) at D3 and D2 respectively, and was able to get an accurate reading Photon’s serial monitor.
- I connected the 5V and ground pins to the Photon’s Shield Shield (powered by USB), and connected the monitor and trigger pins to an Arduino at D3 and D2 respectively, and was able to get an accurate reading on the Arduino’s serial monitor.
My code:
SYSTEM_MODE(AUTOMATIC);
#include "application.h"
unsigned long pulseWidth;
void setup()
{
Serial.begin(9600); // Start serial communications
pinMode(D2, OUTPUT); // Set pin 2 as trigger pin
pinMode(D7, OUTPUT);
digitalWrite(D2, LOW); // Set trigger LOW for continuous read
pinMode(D3, INPUT); // Set pin 3 as monitor pin
}
void loop() {
pulseWidth = pulseIn(D3, HIGH); // Count how long the pulse is high in microseconds
Serial.print("pulseWidth ");
Serial.println(pulseWidth);
// 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
digitalWrite(D7, HIGH);
delay(500);
digitalWrite(D7, LOW);
}
delay(1000);
}
Thanks in advance!