Go Down

Topic: Newbie Remote switch question (Read 758 times) previous topic - next topic

arduinokov

Hello,

I have a project in which I have to connect the LANC Signal (from pin 11) to GND for >140 ms to power up my camera. I have to do this remotely when a sensor is tripped. I was wondering what would be the best method to achieve this.

Obviously, a simple switch would do this if I was interacting with the Arduino directly. But since it has to be remotely triggered, I'm not sure the best way to go.

I am using the following code to start the recording, I just need to turn the camera on first (remotely).

Code: [Select]
/*
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
}

dc42

You need to be more specific. How remote is remote - a few metres, or the other side of the world? Do you want a wired connection, a wireless connection, an internet connection, or some other sort of connection between the sensor and the Arduino? When you say "when the sensor is tripped", what sort of sensor are you talking about?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

arduinokov

Hello,

Thanks for taking the time to reply. Sorry for my lack of details. I will be using an XBee connection from a remote (approx. 50 meter) IR "trip wire".

So when the incoming signal arrives that the IR beam has been broken, I need the LANC line to connect to ground for >140 ms to power up my camera.

Then, I have working code to record for a specified amount of time and then turn the camera off. When the IR beam is broken again, the cycle repeats. This allows the camera battery to last one or more weeks in the field.

:D

tkbyd

For others reading this who may, as I was, be unfamiliar with "LANC"....

It is a protocol(?) defined by Sony. Lots of good stuff, including Arduino code and hardware info at...

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

====
I think the reference above to "LANC line" means the connection from the Arduino to the poster's video camera, the line over which he/ she sends the commands to his camera.

As I understand the question, there's no problem with the "remote" aspects of the problem.

(Advice to poster: For now, replace the Xbee signal with a simple pushbutton connected to a spare input of your Arduino. When the system is working to turn on camera, etc, when you push the button, you can then substitute the code for "I saw button pressed" with "Xbee saw movement", and you are done. Develop in stages, getting each bit working separately.)

ANYWAY... back to the question...

Quote
I need the LANC line to connect to ground for >140 ms to power up my camera.


Are you sure? That didn't make any sense to me, until at the page cited I saw...

Quote
It is a two-way serial open collector 9600 baud protocol with inverted logic.


.. and...

Quote
After sending those two bytes the LANC signal must be be left alone and put back to LOW i.e +5V.


.. at which point things began to make sense... but only because I've spent years banging my head against certain walls.

First, a quibble with what I quoted. I think the second sentence should read...

Quote
After sending those two bytes the LANC signal must be be left alone and put back to "zero" i.e +5V.


"Inverted logic" means that a low voltage stands for "1" and a high voltage stands for "0".

The "open collector" stuff means, I think, that you have a network... in this case a "network" of just two devices... but with the potential for more to be added... with two wires running between all the connected devices. One for ground. Boring, but necessary, and sometimes not mentioned for the sake of beginners, and the "signal" wire.

Somewhere, in this case at the video camera, something attempts to hold the signal at a high voltage... 5v, it would seem in this case. But that "holding high" isn't very "strong", and it is perfectly acceptable, indeed intended, that from time to time devices on the network, or even the device normally pulling the line high, will "short" it to zero volts... which will be "seen" by all devices on the network.

So, in this case, the Arduino is supposed to pull the line low for 140ms, the video camera is going to "see" this, and is designed to "do something" when that happens.

Setting an output low for 140ms is not hard. I suspect you, original poster, are already doing this properly. Just check, though... tweak your code to pull the line low for 800ms, and watch with a voltmeter to see the line DOES go low. If so, on to the next thing....

Are you sure about everything you said? You said you've turned the camera off. If it is "off off", it won't be looking and the LANC interface, won't be doing anything... including holding the signal line weakly high... and thus won't notice the 140ms short- to- ground that your Arduino is generating.


Go Up