Help with pulseIn alternative for ESP32

I am working on a simple Sony Lanc camera control specifically running on the ESP32.
There are many examples running on Arduino but I have not found any that work for me on the ESP32. I believe the problem lies in the following piece of code particularly the use of pulseIn at the first while statement. All I am looking to do is listen for the pause before another 8bit packet is sent from the camera. Any help would be much appreciated.

 while (cmdRepeatCount < 5) {  //repeat 5 times to make sure the camera accepts the command

                  while (pulseIn(lancPin, HIGH) < 5000) {   
                  //"pulseIn, HIGH" catches any 0V TO +5V TRANSITION and waits until the LANC line goes back to 0V 
                  //"pulseIn" also returns the pulse duration so we can check if the previous +5V duration was long enough (>5ms) to be the pause before a new 8 byte data packet
                  //Loop till pulse duration is >5ms
                Serial.println("<No Lanc Start>");
                }

   //LOW after long pause means the START bit of Byte 0 is here
  Serial.println("<Start bit arrived>");
   delayMicroseconds(bitDuration);  //wait START bit duration

   //Write the 8 bits of byte 0 
                        //Note that the command bits have to be put out in reverse order with the least significant, right-most bit (bit 0) first
                        for (int i=7; i>-1; i--) {
      Serial.println("<Writting bits>");
     digitalWrite(cmdPin, lancBit[i]);  //Write bits. 
     delayMicroseconds(bitDuration); 
                        }
   
                        //Byte 0 is written now put LANC line back to +5V
                        digitalWrite(cmdPin, LOW);
                        delayMicroseconds(10); //make sure to be in the stop bit before byte 1
                        
                        while (digitalRead(lancPin)) { 
                          //Loop as long as the LANC line is +5V during the stop bit
                        }

                        //0V after the previous stop bit means the START bit of Byte 1 is here
         delayMicroseconds(bitDuration);  //wait START bit duration
      
         //Write the 8 bits of Byte 1
                        //Note that the command bits have to be put out in reverse order with the least significant, right-most bit (bit 0) first
                        for (int i=15; i>7; i--) {
              digitalWrite(cmdPin,lancBit[i]);  //Write bits 
             delayMicroseconds(bitDuration);
                        }
 
                        //Byte 1 is written now put LANC line back to +5V
                        digitalWrite(cmdPin, LOW); 

   cmdRepeatCount++;  //increase repeat count by 1
   
   /*Control bytes 0 and 1 are written, now don’t care what happens in Bytes 2 to 7
   and just wait for the next start bit after a long pause to send the first two command bytes again.*/
  

 }//While cmdRepeatCount < 5

I have a little more to add in case it is the circuit which is the problem for the esp32. This is the circuit diagram I am using. I only have a meter but the Camera Lanc cable seems to only have a floating 2v approx output between the Lanc pin and gnd perhaps this is the problem since the circuit seems to expect 5-8v from the camera lanc pin.

I've edited the name of your topic - you had missed the 'e' out of pulseIn.

What is a "LANC" ? No idea what this is.

You should post a handdrawn timing diagram how the 0V / 5V pulses look like.

please add information
where did you connect the black-probe of your digital multimeter to ?
where did you connect the red probe of your digital multimeter to?

Best thing would be to draw this inside the circuitry that you posted.

Ok I think I have solved the problem I originally posed. The issue was not with PulseIn which seems to be working fine know that I have switched to another pin on the ESP32!
For those who do not now 'Lanc' Lanc is a rather old but still used camera control protocol invented by Sony allowing you to remotely control a video camera using a three wire cable shown on the diagram. It is still useful when tethering cameras to Pan Tilt heads and motion control systems when you want to control Zoom Focus Iris etc from the PTZ head which is what I am doing. While I think I have solved the original problem unfortunately the camera is not responding to the 'Lanc' commands which may be another timing issue.
I will report back hear if I get any further forward with this.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.