CCTV Pelco-D controller

the old fart

Senior Member
This controls a cctv camera internal menu.
Can be expanded for Pan/Tilt

20M2 chip at 4800baud rate, to ST485CN and a keypad.

ST485CN

pin1 10k reistor to +5v
pin2 tied to +5v
pin3 tied to +5v
pin4 from C.0
pin5 tied to 0v
pin6 A to camera
pin7 B to camera
pin8 tied to +5v

no reistor A-B



SEN040 Data Entry Keypad

Pin C.1 to C1 keypad
Pin C.2 to C2 keypad
pin C.3 to C3 keypad

pin B.1 to R1 keypad
pin B.2 to R2 keypad
pin B.3 to R3 keypad
pin B.4 to R4 keypad



Code:
;
;cctv menu controller
; keypad 5 enter 
; keypad 2 move up
; keypad 8 move down
; keypad 4 move left
; keypad 6 move right
;20M2


low b.1,b.2,b.3,b.4
symbol key_pos=b1
symbol key_value=b2
symbol display=b4
let display = 128
let key_pos=0

start:

scan:

let key_value=0
high b.1
gosub key_test
low b.1


let key_value=3
high b.2
gosub key_test
low b.2


let key_value=6
high b.3
gosub key_test
low b.3


let key_value=9
high b.4
gosub key_test
low b.4


goto scan


key_test:

if pinc.1=1 then add1
if pinc.2=1 then add2
if pinc.3=1 then add3

return
add3: let key_value=key_value+1
add2: let key_value=key_value+1
add1: let key_value=key_value+1


serout b.0,N2400,(254,display,#key_value,"   "); used for degugging only

if key_value=5 then gosub openmenu
if key_value=6 then gosub goright
if key_value=4 then gosub goleft
if key_value=2 then gosub goup
if key_value=8 then gosub godown


display=display+1

if display>148 then let display=128:endif


return


openmenu:
	serout c.0,T4800,(0xFF,0x01,0x00,0x07,0x00,0x5F,0x67)
	pause 1000
	return

goright:
	serout c.0,T4800,(0xFF,0x01,0x00,0x80,0x00,0x00,0x81)
	pause 1000
	return

goleft:
	serout c.0,T4800,(0xFF,0x01,0x01,0x00,0x00,0x00,0x02)
	pause 1000
	return

godown:
	serout c.0,T4800,(0xFF,0x01,0x00,0x40,0x00,0x00,0x41)
	pause 1000
	return

goup:
	serout c.0,T4800,(0xFF,0x01,0x00,0x20,0x00,0x00,0x21)
	pause 1000
	return
Thanks to all who helped with this project, cheers guys.


Dave
 

neiltechspec

Senior Member
Should you not also be issuing a stop command after every move, the camera will just keep moving if you don't won't it ?

Here's one I did for just controlling the Zoom on a box cam with integrated zoom lens.

Code:
#rem
Pelco D Zoom Controller (Cam ID 1) @ 9600,8,n,1
Using PICAXE 08M2 & MAX485

Wide command:
255 001 000 064 000 000 065 (start)
255 001 000 000 000 000 001 (stop)

Tele command:
255 001 000 032 000 000 033 (start)
255 001 000 000 000 000 001 (stop)

pin C.0 is activity LED, flashes 10 times on power up & illuminates during button push
pin C.1 is 485 direction (pins 2&3), high for TX, low for RX
pin C.2 is 485 data out / in (pins 1&4), only using out in this app
pin C.3 is Tele button, active high
pin C.4 is Wide button, active high

#endrem

#picaxe 08m2
#no_data

Main:
	setfreq m16
	high C.1,C.2
	for b1 = 1 to 10
	high C.0
	pause 40
	low C.0
	pause 800
	next b1
	do
	if pinC.4 = 1 then gosub Wide
	if pinC.3 = 1 then gosub Tele
	pause 400
	loop

Wide:
	high C.0
	serout C.2,T9600_16,(255,001,000,064,000,000,065)
	do until pinC.4 <> 1
	pause 800
	loop
	low C.0
	serout C.2,T9600_16,(255,001,000,000,000,000,001)
	pause 800
	return
	
Tele:
	high C.0
	serout C.2,T9600_16,(255,001,000,032,000,000,033)
	do until pinC.3 <> 1
	pause 800
	loop
	low C.0
	serout C.2,T9600_16,(255,001,000,000,000,000,001)
	pause 800
	return
Neil.
 
Top