Sony LANC Project and Protocol.

Jaggermax

Inactive
Joined
Apr 6, 2001
Messages
505
Reaction score
0
For the past two days, I have been experimenting with trying to get my microcontroller to talk to my Sony CCD-TRV43 camcorder.  At first I was going to hardwire the camera, but then I opened it and got scared.  I am now attempting to tap into the LANC port on the camera.  I bought the Sony "Control F Protocol Manual" as a start to see how the camcorder communicates.  It's very indepth and poorly written, but it got me started.  

The LANC port uses a three conductor plug with ground, +5, and the serial line on the plug.  The communication is handled by 9600 baud async serial communication across the serial line.  I got to tell you, the communication protocall is deep.  In a nutshell, the camcorder sends a field of data on the serial line.  The field is made up a 6ms start bit, 8 bytes (9600 baud rate), then a 3ms stop bit.  Then it repeats itself.  To talk to the camcorder, you must first find the first word of the data stream by finding the start bit and then quickly write a two word command onto the serial line.  The first word tells what device you want to talk to (camera) and then the second word tells the camera what you want it to do (power on, record, zoom, etc...).  The remaining 6 bytes are basically just to read the status of the camera and you dont really need to do anything.  

The hard part is trying to time my commands with the serial line on the camcorder.  All I have managed to do so far is read the data stream from the camera and turn the camera off.  Now I need to figure out how to get my commands back to the camcorder.  If any of you electronic or programming guys are interested, email me.  Maybe together we can figure the LANC out!

P.S.( to turn a Sony camera back on after it auto shutsdown in standby mode is to ground the serial line on the LANC port.)
 



Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Hi Jaggermax,
Where did you find that protocol manual??  Sounds like interesting bedtime reading :)
Afraid this stuff is over my head - I'm still hacking around with RTCs and LCD displays.... Maybe in a year or so....??
I don't have a video cam to play around with - but I'm curious if power consumption in "standby" mode is higher than when the switch is turned "off".

Brian hard-wired his TRV 818.  From his description sounds like it wasn't too difficult.

Is there a way on any of the Sony cams to operate the "night-shot" mode via the LANC port - or is that mechanical on all of 'em??

Archilochus
 

ArkansasElkHunter

Well-known member
Joined
Jan 19, 2002
Messages
1,748
Reaction score
0
Arch,

The night shot is both mechanical and electronic.  the slide switch flips a filter into position and also trips a limit switch.  All the ones I have tried at best buy have the same sound as the little filter lens flips into position.  I know the limit switch turns on the IR Led source, but I don't know what else it does.  I know brian tried everything he could to bypass the mechanical part and couldn't.  
 

hamiltoe

Well-known member
Joined
Jul 8, 2001
Messages
174
Reaction score
0
Jaggermax,
If it uses standard RS232 (which is async serial communication, I think), it may be easier to figure out the communication protocal via a PC.  You might be able to use hyperterminal (comes with windows) to send/receive data.  Also, if you are any good at Visual Basic, their serial communication OCX is pretty easy to use and you could probably get if figured out pretty quick.  That's how I figured out how to read the data from Trail Master's TM-550 camera.  After you figure it out, then you could port it over to the microcontroller....just a thought.
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Ouch!!
Just made a quick scan of that site.  I think I'll stick with my soldering iron for this job!

You're a brave man Jaggermax!

Archilochus
 

Jaggermax

Inactive
Joined
Apr 6, 2001
Messages
505
Reaction score
0
Brave or just plain stupid?  :crazeye:

I tried until 3 AM last night, and finally just gave up.  I can read the Lanc fine, but writing is a different story.  Im going to wait a couple of days to rethink my attack plan.  Problem that I am having is that I am having trouble getting the exact 52us timing I need to transpose my signal.  May have to go to a faster micro.  
 

spectr17

Administrator
Admin
Joined
Mar 11, 2001
Messages
69,528
Reaction score
408
Jaggermax,

Last year in the rec.video newsgroup there were some guys who took the Sony tripods that had the LANC control on them and yanked them off the tripod and were using them to remotely control video cams.

Can't remember who it was but if you psot about this someone should recognize the subject and steer you to those brave souls.
 

Jaggermax

Inactive
Joined
Apr 6, 2001
Messages
505
Reaction score
0
Thanks Spectr.  I saw a number of companies on the net selling the tripods.  I may break down and buy one to see how it works.  I also found a website from a company that makes exactly what I wanted to do, a lanc remote.  Somthing like this would be very easy to integrate to a microcontroller board.  His website is http://home.t-online.de/home/hifiaalen/ue_minil.htm.  You may have to clip and paste this link.  I left him an email trying to see what he sells them for.  You will have to do a translation on the website

(I just realized I should have started this post under the Video Game Cam post)

(Edited by Jaggermax at 8:30 pm on July 21, 2002)
 

gizz

Well-known member
Joined
Mar 11, 2001
Messages
1,395
Reaction score
0
I think this is fine here jaggermax since this is game cameras and camcorders.
Sorry i can't be of much help but i like following along nonetheless.
 

Jaggermax

Inactive
Joined
Apr 6, 2001
Messages
505
Reaction score
0
Well, after almost a straight week of trying to hack the LANC protocol, tonight I was on the verge of thowing everything in my lab out the window.  I literally spent 6 hours a day, each of the past 7 days trying to figure out how the damn protocol works, and guess what?.......I FIGURED THE $#$%&# THING OUT!.  I was literally seconds from calling it quits for good when I figured out what the problem was.  All data sent to the serial line must be inverted.  All the info on the net says the commands the camera sends are inverted, but say nothing about having to invert the data you want to write back.  Also, all of the sample LANC codes  on the net are all non inverted commands!  

I was able to make the camera record, power off, power on, zoom, rewind, and FF all through one of my modified controller boards.  I am basically taking all of the commands I found on the net and trying each one, one at a time.  Some work, some dont.  The commands that will most likely be the most useful are power off, power on, record, and maybe zoom.  

If all goes well, I should have a video camera board for a game cam built by the end of the week.  Right now, I am controlling a Sony CCD-TRV43 camera, however, the same code should be able to run any camcorder that has a LANC port.  Hopefully, once I get the kinks out of the software, I will be building some video controller boards with the PIR built it, a LANC interface port, and an output relay to fire one of the "Bigger IR" infrared arrays (www.dalewheat.com).  If any of you know of any other features I should look at, give me a shout.  

P.S.  to answer some of your questions Arch,   for the manual, I contacted sony's parts division and asked for the "Protocol of Control L" manual.  $15 bucks including shipping, but it's very poorly written and hard to follow.  Very little info in it as well and outdated.  As far as standby mode, I had my camcorder on the shelf for over a month in standby mode and the batteries were still full.  Very little power drain.  Also, there is no LANC control for the nightshot that I have found.  I just always leave it on anyway since I dont mind the green tint in the day shots.    

(Edited by Jaggermax at 12:11 am on July 28, 2002)
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Good to hear you got it going! Persistence pays off - Hope you didn't pull ALL your hair out :-O
Thanks for the update & info.
Archilochus
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Hi Jaggermax,
Been doing some reading on the LANC stuff (eyes are all bloodshot and hands are starting to shake)  Some of the stuff I've read is obviously outdated - one page stated the start bit as 1.2mS.
Anyways... there are a few things I'm trying to get straight that I can't seem to find info on.

So you catch the 6mS start bit - (oh yeah.. THAT sounds easy! - NOT) - and you're supposed to then inject your commands (inverted) in the first two bytes of the 8 byte string. How critical is the start timing of the imposed signal?? Does it need to start EXACTLY at the end of the 6mS start bit - or can it start a mS or so early? - I imagine starting late is a BAD idea :-(

How many times should a command be imposed in order to guarantee that the cam will recognize and respond to it?

In your first post you mentioned that to turn the Sony cam ON after it shuts down automatically -  you short the serial line to the LANC port ground. But I've also read that there is a "power-on" command that can be sent - what's the difference between the two??

<<<<EDIT>>>>>
ARRRGGGGGG!!! - now I'm totally lost! Every page I read seems to say something different! Guess I'll have to break down and buy the book :-(

Archilochus

(Edited by Archilochus at 5:47 pm on July 28, 2002)
 

Jaggermax

Inactive
Joined
Apr 6, 2001
Messages
505
Reaction score
0
Your right, every bit of info out there on the net concerning lanc is different .  I found that not all of the commands work on my camera.  I tried the power on, but it would not work.  This is because when the camera goes into shutdown, the LANC line is pulled high and ceases to send any data.  Maybe some other cameras are different but mine can only be restarted by pulling the LANC line to ground.  

Now the hard part.  Here is the way I found the LANC to work.  One data stream consists of 8 bytes, the first two bytes, byte 0 and 1, are all we need to worry about.  The other 6 are just for reading the status of the camera.  First you have to find the data stream startbit, this is when the lanc line goes high for 1.5ms.  When you detect that, the next transition of the line going low is the actual start bit.  The startbit is 104us long.  As soon as the start bit is over, you start sending your 8 bits of byte0 LSB first.  To do this, just start shifting out byte0 on the lanc line with a period of 104us for each bit (start with bit 0).  At the end of bit7, there are two or three stopbits (all high) before the beginning of byte1.  (lost yet).  To find  the startbit of the next byte, just wait for the line to go low again and repeat the process for the second byte.  

You have to send the data to the camera 6 times in a row for it to work.  To send the data again, just wait 9ms after your last bit of byte 1 is sent.  Then detect the 1.5ms word startbit and start over.  And yes, timing is extremely critical.  The easy part is finding the startbits, the hard part is getting the timing right to send back on the line. You do have some gap of acceptable timeing.  I found a period of 98us to 106us would work.    

Some commands work and some don't.  The tele and wide commands work great, but you have to send them over and over to fully zoom out and in.  If you only send it 6 times, the camera will just slightly zoom in or out.  Instead of sending each command to the camers 6 times for wide and tele, you have to send them 200.  Same is true for editsearch.  Record and poweroff only need it send 6 times.  

Since all of the info on the net is misleading, I plan on writing up a project report and posting it on my website as soon as I finish my programming.  Hopefully it should be helpful to some of you.  

(Edited by Jaggermax at 8:54 pm on July 28, 2002)
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Thanks again for the info Jaggermax.  The information I found confusing that seems to be different on various pages relates to timing - or maybe I'm just reading the stuff wrong :-O

Can't wait to see your report! Wish I had a video-cam to tinker with.

Is it easy to blow stuff up if you get the signals wrong??

Archilochus
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Hi Jaggermax,
Just trying to see if I'm even getting close with understanding the LANC stuff.... this is what I've pieced together so far for timing:
http://archilochus.netfirms.com/images/lanctime.gif
I borrowed that image from a web-site and modified it a bit.
>>>>
Is this the basic series of events??

1) The PIR detects motion and wakes up the micro from sleep.

2) You want to wake the video-cam from (sleep) standby - so the serial line is pulled low briefly (or maybe on some cams you send a 'wake-up' command??).

3) After a pause of a few seconds to let the cam power-up? - it will start sending out data on the LANC port.

4) To sync with the ('strings'/ 'frames'/ 'fields') of 8 bytes, you need to first find the 'gap' between frames (this 'gap' is some time that I couldn't quite determine for sure - around 5.4 to 7mS?? for NTSC)

5) Once a 'gap' is found, you wait for a start bit (first low transition of the new frame).

6) When that first falling edge of the start bit is detected, you wait ~104 uS (maybe a few uS less?? - or do you wait only 52uS?? some confusion there! - some code I found waited only 26uS after detecting that falling edge before starting Tx).

7) Now you send a command byte(0) @ 9600 baud, inverted, LSB first.

8) After sending the byte - check for stop bits (2 or 3??). is this required??

9) Get your next command byte(1) ready to send

10) Look for the start bit of the next byte(1) - when found - repeat 6 - 8 (but with second command sent).

11) After sending the second command byte(1) - repeat from step 4, for five more frames to make sure your request is recognized (6 frames total).

Not sure if you need to tell the cam to enter 'record' mode - then tell it to 'start recording' - or if the cam wakes up from standby already in record mode??  Does any of this work with the cams ON / OFF switch turned to OFF - or does the cam need to be switched to 'record'??

12) After recording for the desired amount of time - repeat above with the appropriate commands to stop recording and then again to shut down (or maybe just let it go into standby automatically??).

Hmmm ... well..... I'm quite lost! .... Did any of that even come close??

Thanks again,
Arch

(Edited by Archilochus at 9:24 am on July 30, 2002)
 

Jaggermax

Inactive
Joined
Apr 6, 2001
Messages
505
Reaction score
0
By George Arch, I think you got it!  I tied the pir line directly to the INT0 line of the micro and put the micro to sleep.  On pir trigger, the INT0 is pulled low which wakes up the micro.  First thing I do is pull the lanc line down for 20ms, enough to wake the camera up.  I then wait for the next FRAME start bit which is a high signal for 1700us.  (The frame is the 8 words that make up one command receive/transmit string).  I then wait for the line to go low again.  As soon as it goes low, I configure my LANC port on the micro as an OUTPUT,  wait 104us, and then start writing my bit, LSB first at 104us invervals.  At the end of the 104us for the last bit I immediatley make the LANC port on my micro an INPUT, wait at least 200us (when my lanc port is an input, the camera then takes control of the line and pulls it high, which tells you it is the stop bits of the first byte sent), and then wait for the line to go low again.  This low signals the startbit beginning of the next byte to write.  I then wait 104us, turn the lanc port back into an OUTPUT and repeat the process for the second byte to write.  You really need a decent Oscope to tweak your timings of the LANC signal.  Almost impossible to do it without one.  

One hard part was turning one port back and forth from and input to an ouput and still getting the timing right.  Basically, when I want to record, I simply pull the Lanc line low to turn the camera on and then write the code to the camera to start recording (1rst byte &h18, second byte &h33).  After a certain amount of time of recording, I then send the same command again to stop recording and then send another set of commands to turn the power off to the camera.    Remember, each command must be send 5 consecutive times.  

Another interesting thing I found is that the camera switch can be in the LOCKED setting and the camera will still work with LANC.  Also, the gap between the end of the second byte your write (most websites refer to it as byte 1) and the startbit of the next frame is about 9ms.  So if you want to send a set of commands 5 times, wait 9ms after the last bit in the second byte you send and the repeat.  Did I help or confuse you more, lol???
 

Archilochus

Well-known member
Joined
Mar 27, 2001
Messages
1,285
Reaction score
0
Thanks Jaggermax,
I do think I'm beginning to see the light!  :)
Have to start hacking away at some code so I'll have something ready to try when I get hold of a video cam.

Arch
 


Top Bottom