Webcam

 

Driving the DS-SCX16S-0 16 servo controller (used for the webcam nod and tilt)

Notes
The 16 lines can be addressed but the register numbers for each line do not go 0,1,2,3 etc but -

line 1 - 000
line 2 - 002
line 3 - 004
etc

The PIC must run at 20MHz for the Oshonsoft Basic software UART to give pulses that are accepted by the DS-SCX16S-0
- even though the windows PC can read the output with a 4MHz clock

The DS-SCX16S-0 rs232 input works with a true rs232 signal input to pin 6 via a 0-5Volt voltage clamp circuit as in the manual.
If it is fed from the PIC ports at TTL level then the pulses must be inverted by using
SeroutInv


Using the software UART on the PIC

'rs232_software_inv.bas
'feed the DS-SCX16S-0 via software uart
'inverted serial pulse needed since chip is NOT clipping a true rs232 signal to 0-5Volts
Dim i As Byte
Dim rotate As Byte
Dim nod As Byte
nod = 132
rotate = 36

loop:

SeroutInv PORTD.2, 9600, "[", 0xe0, 0x02, nod, 0xd5, "]", "]"
WaitMs 2000
SeroutInv PORTD.2, 9600, "[", 0xe0, 0x02, rotate, 0xd5, "]", "]"
WaitMs 2000
SeroutInv PORTD.2, 9600, "[", 0xe0, 0x04, nod, 0xd5, "]", "]"
WaitMs 2000
SeroutInv PORTD.2, 9600, "[", 0xe0, 0x04, rotate, 0xd5, "]", "]"
WaitMs 2000
Goto loop


Using the i2c line

'i2c-servo_test.bas
'drive the DS-SCX16S-0 servo driver via i2c on port C 3 and 4

TRISC = 0 'all port C outputs
Symbol sda = PORTC.4 'setSDA for i2c
Symbol scl = PORTC.3 'setSCL for i2c

'prepare to use LCD later
Define LCD_LINES = 4
Define LCD_CHARS = 20
Lcdinit
Lcdcmdout LcdClear

Dim rotate As Byte
Dim nod As Byte

loop:
'----------------------------------------feed i2c webcam servo driver chip
'-------------------position 1
nod = 70
rotate = 150
I2CWrite1 sda, scl, 0xe0, 0x02, nod, 0xd5, rotate, 0xd5 'set them up
WaitMs 50
I2CWrite1 sda, scl, 0xe0, 0x20, 0x00 'make it happen
Lcdcmdout LcdClear
Lcdout "nod ", #nod, " rotate ", #rotate
WaitMs 2000

'----------------flash the i2c leds on i2c 8574 once
I2CWrite1 sda, scl, 0x76, 0x00
WaitMs 500
I2CWrite1 sda, scl, 0x76, 0xff

'-------------------position 2
nod = 150
rotate = 70
I2CWrite1 sda, scl, 0xe0, 0x02, nod, 0xd5, rotate, 0xd5
WaitMs 50
I2CWrite1 sda, scl, 0xe0, 0x20, 0x00
Lcdcmdout LcdClear
Lcdout "nod ", #nod, " rotate ", #rotate
WaitMs 2000

'----------------flash the i2c leds on i2c 8574 twice
I2CWrite1 sda, scl, 0x76, 0x00
WaitMs 100
I2CWrite1 sda, scl, 0x76, 0xff
WaitMs 200
I2CWrite1 sda, scl, 0x76, 0x00
WaitMs 100
I2CWrite1 sda, scl, 0x76, 0xff
WaitMs 200

Goto loop