
Background
LANC is a serial protocol available in most Sony and Canon videocameras. If you need additional info, Wikipedia has a good introduction on what LANC is.
The best low level definition of the protocol is available on this nice article
http://www.boehmel.de/lanc.htm
At the time I worked on this, there was no open source implementation of LANC available, so I used the opportunity to learn some of the Arduino features by implementing LANC with it. A few months later someone else published a LANC source code for Arduino, therefore there are at least 2 implementations available now for free to the Arduino comunity.
My implementation can be easily extended, and use standard Arduino code (i.e. it doesn't require any additional library nor C code).
Software
This article demonstrates a simple implementation in Arduino Diecimila with a few LANC commands (Play, Rewd, Record and Stop), but it is really easy to extend it to support more commands. In my case, I just needed VTR record mode, as it was disabled in my Sony European model (most vendors disable this feature in European low end camcorders to reduce Taxes).
Being a relatively simple serial protocol, I found rather difficult to implement it in the Arduino platform by just using the libraries available. The major problem is the lack of direct "timer" reading.
In other words, there is no simple way of reading a timer counter in Arduino to learn how many microseconds already spent the ATmega in a given code section. This makes really difficult to synchronize protocol timming with the microcontroller code. I understand this as a clear candidate to create a new library using C rather than Arduino IDE but I wanted to limit myself to the available Arduino features. The main reason is to somehow challenge the current Arduino offering and not go to the GCC tool chain.
Given the lack of a timer, I needed to learn how long it took for the ATMega to do certain things, to properly read the LANC signal at the right time. For that I used a logic analyzer (LA) and a few signals to mark internal activity of my code (such as when the start bit is detected, when the last data bit is read, etc) to guarantee the bit-banging is doing what is supposed to do.
As result, you can see the code basically do bit-banging on a basic premise of 104uS per bit, 8 bits per byte, 1 start bit and some "stop bit" which is not 104uS long but a bit more than that (apparently depends on the camera model). This repeat 8 times for 8 bytes total per frame, and this repeats 20 times every second for a PAL signal.
You may need to reverse engineering commands from your camera by triggering a manual action (such as Zoom IN) and then look into LANC pattern.
Take a look at the source code, it is self explanatory and contains an interesting section to help you reverse engineering your particular camera commands in case you need additional controls. There are some people out there using a potentiometer to control zoom or focus, that should be an easy addon to this code if you need it by leveraging an ADC input for that.
Source code available here.
Hardware
Hardware layer couldn't be easier.
LANC specification requires an open collector to drive the single wire serial connection. At the same time, we need to protect the signal entry for arduino so I clamp it to 5V with a zener.
There are a few I/O ports I used to blink leds or add button on. Check the code for that:
int ledPin = 13; // LED connected to digital pin 13
int PinLANC = 3; // 5V limited input signal from LANC data
int PinCMD = 2; // Command to send to LANC
int PinDEBUG = 12; // Used for timing and debug as a signal output
// for a logic analyzer
int PinRS232 = 4; // When set to LOW will dump RS232 info,
// although several frames will be lost
int PinLEDRecord = 6; // Will be ON when recording
int PinLEDPlay = 7; // Will be ON when playing
int PinLEDActivity = 8;// Will be ON anytime there is status different than STOP
int PinSWRecord = 10;
int PinSWStop = 9;
int PinSWPlay = 11;
Conclussion
Arduino is a platform for easy development, so reverse engineering a protocol like LANC requires some creativity and some additional tools like a Logic Analyzer.
One limitation of my approach is you are dependant on the CPU speed. Moving to a different clock rate or a different Atmel micro will likely change the bit-bang timming in a way the LANC requirements will no longer be met. You will have to adjust some of the delayMicroseconds(xxx) to adjust to LANC timming. |
Comments
Thanks
Yes you can left V+ unconnected if you feed your circuit from somewhere else.
If the LANC commands don't work may be for many reasons, not necesarily the delayMicroseconds. Do you have access to a logic analyzer or oscilloscope to see the signal shape? That will really tell you what is going on.
You must connect the V+ to a +5V source from the Arduino board if you don't feed it from the camera.
RSS feed for comments to this post