LANC code question

Hello,

Does the code below power up the camera or does it assume that the camera is on and just respond to the "Record Start/Stop command"?

Many thanks for any advice, sorry for such a newbie question. :blush:

/*
Send a Start/Sop Recording command to the LANC port of a video camera.
Tested with a Canon XF300 camcorder
This code requires a simple interface see http://micro.arocholl.com
Feel free to use this code in any way you want.

Comprehensive LANC info: www.boehmel.de/lanc.htm

"LANC" is a registered trademark of SONY.
CANON calls their LANC compatible port "REMOTE".

2011, Martin Koch
http://controlyourcamera.blogspot.com/2011/02/arduino-controlled-video-recording-over.html
*/

#define cmdPin 7 
#define lancPin 11
#define recButton 2
int cmdRepeatCount;
int bitDuration = 104; //Duration of one LANC bit in microseconds. 

void setup() {

pinMode(lancPin, INPUT); //listens to the LANC line
pinMode(cmdPin, OUTPUT); //writes to the LANC line
pinMode(recButton, INPUT); //start-stop recording button
digitalWrite(recButton, HIGH); //turn on an internal pull up resistor
digitalWrite(cmdPin, LOW); //set LANC line to +5V
delay(5000); //Wait for camera to power up completly
bitDuration = bitDuration - 8; //Writing to the digital port takes about 8 microseconds so only 96 microseconds are left till the end of each bit
}

void loop() {
if (!digitalRead(recButton)) {
REC(); //send REC command to camera
delay(1000); //debounce button
}
}



void REC() {

cmdRepeatCount = 0;

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
}

//LOW after long pause means the START bit of Byte 0 is here
delayMicroseconds(bitDuration);  //wait START bit duration

//Write the 8 bits of byte 0 
//"18hex" or “00011000”  tells the camera that there will be a normal command to camera in the next byte
//Note that the command bits have to be put out in reverse order with the least significant, right-most bit (bit 0) first
digitalWrite(cmdPin, LOW);  //Write bit 0. 
delayMicroseconds(bitDuration); 
digitalWrite(cmdPin, LOW);  //Write bit 1 
delayMicroseconds(bitDuration);  
digitalWrite(cmdPin, LOW);  //Write bit 2
delayMicroseconds(bitDuration); 
digitalWrite(cmdPin, HIGH);  //Write bit 3
delayMicroseconds(bitDuration);  
digitalWrite(cmdPin, HIGH);  //Write bit 4
delayMicroseconds(bitDuration);
digitalWrite(cmdPin, LOW);  //Write bit 5 
delayMicroseconds(bitDuration);
digitalWrite(cmdPin, LOW);  //Write bit 6
delayMicroseconds(bitDuration); 
digitalWrite(cmdPin, LOW);  //Write bit 7
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
//"33hex" or “00110011” sends the  Record Start/Stop command
//Note that the command bits have to be put out in reverse order with the least significant, right-most bit (bit 0) first
digitalWrite(cmdPin, HIGH);  //Write bit 0 
delayMicroseconds(bitDuration);
digitalWrite(cmdPin, HIGH);  //Write bit 1 
delayMicroseconds(bitDuration); 
digitalWrite(cmdPin, LOW);  //Write bit 2
delayMicroseconds(bitDuration); 
digitalWrite(cmdPin, LOW);  //Write bit 3
delayMicroseconds(bitDuration);
digitalWrite(cmdPin, HIGH);  //Write bit 4 
delayMicroseconds(bitDuration); 
digitalWrite(cmdPin, HIGH);  //Write bit 5
delayMicroseconds(bitDuration);
digitalWrite(cmdPin, LOW);  //Write bit 6
delayMicroseconds(bitDuration);
digitalWrite(cmdPin, LOW);  //Write bit 7
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 assume the code assumes the camera is on - maybe standby will work to...

NB if the device would be off it would not listen to signals normally ..

Advice: try to find the lanc protocol specification.

sorry for such a newbie question

The person who asks questions is dumb for a short moment, the person who does not ask question is dumb forever (Chinese proverb, Confusius ?)
or
Questions is one of the main reasons forums exist :wink:

Hi,

Thanks so much for your reply. That's what I was thinking. I don't see how it could communicate with the camera if it is not on.

My prototype does work to turn on/off the recording. But only if the camera is on. So the hardware and code is working as it should. But is it possible to also power up the camera?

I have been searching for the LANC protocal to power up the camera. Does anyone have any experience with this problem?

Thanks :slight_smile:

FOund this - The SONY LANC protocol -

It does not mention a power up although it has "2A power (or viewfinder) off" and "5E power off"

and Yes!

"Connect LANC Signal to GND for >140 ms to power on (or on Mini-DIN Pin 3 to GND)."

Don't no if it works but worth a try, (I'll hear from you in 150 ms :wink:

Hi,

Interesting... connecting the LANC Signal to GND for >140 ms does power up the camera, but it doesn't stay on, after about 2 seconds it powers off again. And during the brief time it is on, it does not respond to the Record Start/Stop command.

Too bad, that would have been too easy. :~

Update, for my camera, Sony HXR-MC1, "01011110" is Power Off. It is working well.

Still looking for "Power On".

:slight_smile:

Interesting... connecting the LANC Signal to GND for >140 ms does power up the camera, but it doesn't stay on, after about 2 seconds it powers off again. And during the brief time it is on, it does not respond to the Record Start/Stop command.

Too bad, that would have been too easy. smiley-confuse

And if you GND it for longer e.g. 5 seconds or so? maybe the internal SW has not enough time to start up? Or it is waiting for a special command / sequence?

What I am doing is turning the physical on/off switch to the "on" position. Then I use the power off code to turn the camera off. The physical switch is still in the "on" position but the camera is off. So when I connect the LANC to ground, the camera starts up again and stays on. Until I use the power off code again.

This way, I can leave the camera alone in the field and have it triggered to turn on, record and then turn off using the Arduino and a sensor.

I am still looking to see it there is a "power on" coded command that will work, but if not, this method works well.

:slight_smile:

Sounds as a really workable method, think you found the standby mode.
The ON/OFF switch is hardwired so it seems. The only other option I can think of is a servo pushing the on/off button :wink:

Thanks for sharing your solution,
Rob