I am using the same code on both an Arduino and the Photon (only difference is preceding the pin with a D for the Photon). I am using the SAME sensor circuit for each board.
On the Arduino, everything works.
On the Photon, per Joost, indeed the blue light (D7) does flash when I vary the distance. However, the distance read by the Photon is still zero. My code is below. Could the value of the resistor cause this?
unsigned long pulseWidth;
void setup()
{
Serial.begin(115200); // Start serial communications
pinMode(D4, OUTPUT); // Set pin 4 as trigger pin
digitalWrite(D4, LOW); // Set trigger LOW for continuous read
pinMode(D7, INPUT); // Set pin 7 as monitor pin //Yellow
}
void loop()
{
pulseWidth = pulseIn(D7, HIGH); // Count how long the pulse is high in microseconds
Serial.print ("pulse= ");
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
}
}
@Jimmie, print the “raw” pulseWidth and don’t do the divide by 10. What do you get? Also, D7 has an LED connected via a current limiting resistor which may affect the circuit. Can you try another pin like D2/
@Jimmie, my gut tells me to ditch the shield and connect the +5v for the LIDAR to Vin of the Photon with common grounds. Keep the rest connected as you have it (D2, D3). The MODE pin needs to be pulled LOW so 5v is not required from the Photon. Both D2 and D3 are 5v tolerant so no problem there.
when you do finally get it right it will start sending data very quickly, i would suggest this.
if(pulseWidth != 0)
{
pulseWidth = pulseWidth/10; // 10usec = 1 cm of distance
Serial.println(pulseWidth); // Print the distance
digitalWrite(D7, LOW);
}
delay(200); //Delay so we don’t overload the serial port
}
on the breadboard have yellow trigger from lidar/resistor/yellow trigger to D3 of photon in one line.
on seperate breadboard line have resistor/line to D2
for power
from 5v power source have 680 cap accross + & - then power to lidar on other side of cap. run a wire from negative of
power to gnd on photon
Did all of that, does not work! Took same circuit again, same code to an UNO and it worked immediately.
I am not an electronics engineer so I have no idea what is going on. It is frustrating though that a modern supposedly “compatible” and superior board is not working. I am happy to try anything else.
I will also borrow an oscilloscope from a friend if you would help me with how to hook it up and what I should see coming out …
The only thing I can think of is that the Shield-shield is not handling the bidirectional PWM signal properly. If you look at @dkryder working setup, he uses the Photon without any adapter board.
Can you try with the Photon mounted just on a solderless breadboard instead of on the Shield-shield?
However, dkryder says his setup works? Did you hook it up to the same sensor I am using?
I am asking because you are actually switching the wires coming out of the sensor. For it to work (on an Arduino), you need to connect the White wire to D3 and the Yellow wire to D2 (you have them switched). (BTW, I tried them both ways on the Photon and it does not work either way).
Sorry peekay123, you were right too. It is my fault as I understood you meant to take to the sensor power directly from the Photon pins (but I left the board in the shield).
Thank you again. As I said, I learned new things from all of you.
My bad! I understood it to mean wire directly to Photon pins but then I left the board in the shield. I am surprised that a simple level shifter caused this. Thanks again.