How to Program Pan and Tilt HS-422 Servos with BS2~Pls Help~

Recently, :slight_smile:

I purchased a Lynx B - Pan and Tilt Kit (Black Anodized) and model # is BPT-KT. It come with two HS-422 Servos.

I use it to build a “Light Tracker” in order to control the 5 Photoresistors Sensors panel with 5 A/D convertor toward the direction of Flash Light. 4 sensors on the corner and the 5 on the middle. I plan to compare the 4 corner sensors with the middle one and the servos would move toward the light until any one of the 4 corner sensors and the 5 middle sensor both have the same amount of received light.

:question: The only problem I left is how to program two HS-422 servos of Lynx B - Pan and Tilt Kit on Basic Stamp Editor with Basic Stamp 2 Microcontroller + Education Development Board in order to move any possible direction??? (Left or Right & Front or Back)

Please provide me as many as you may in order to finish my senior project.

Thank you for helping.

Appreciate.

Sincerely,

Marco Liu
:smiley:

You have any code to start with? We can’t do your senior project for you, but we’d be happy to help.

Thank you for helping ~ I already write half of the program code, the only thing I don’t know how to write is Servos’ programs.

The following is my codes and please help me or guide me how can I finish it.

Thank you very much

Appreciate

Marco Liu

[code]’ {$STAMP BS2}
’ {$PBASIC 2.5}

'----- Declarations ]--------------

adcBits1 VAR Byte 'Variable
adcBits2 VAR Byte
adcBits3 VAR Byte
adcBits4 VAR Byte
adcBits5 VAR Byte

'----- Initialization ]------------

CS1 PIN 0 'Input
CS2 PIN 4
CS3 PIN 6
CS4 PIN 8
CS5 PIN 10
CLK PIN 1 'Clock
D01 PIN 3 'Output
D02 PIN 5
D03 PIN 7
D04 PIN 9
D05 PIN 11

'----- Main Routine ]--------------

DO
GOSUB Check_adc 'Analog to digital converter
GOSUB Navigate ’
LOOP

Check_adc:

HIGH CS1                                     'ADC-0831 Start convertion.
LOW  CS1                                    'Stay low for the duration convertion.
LOW  CLK                                    'Clock pulses take the right form.
PULSOUT CLK, 210                           'Sending high and low clock signals.
SHIFTIN D01,CLK,MSBPOST,[adcBits1\8]      'Command send clock pulses to ADC0831's CLK
                                                 'input and reads output bits from ADC0831's DO1
                                             'output. This command also loads DO1 output
                                             'into the adcBits byte.
HIGH CS2
LOW  CS2
LOW  CLK
PULSOUT CLK, 210
SHIFTIN D02,CLK,MSBPOST,[adcBits2\8]

HIGH CS3
LOW  CS3
LOW  CLK
PULSOUT CLK, 210
SHIFTIN D03,CLK,MSBPOST,[adcBits3\8]

HIGH CS4
LOW  CS4
LOW  CLK
PULSOUT CLK, 210
SHIFTIN D04,CLK,MSBPOST,[adcBits4\8]

HIGH CS5
LOW  CS5
LOW  CLK
PULSOUT CLK, 210
SHIFTIN D05,CLK,MSBPOST,[adcBits5\8]

RETURN

Navigate:

IF (adcBits1 > 80) AND (adcBits3 < 100) THEN

ELSEIF (adcBits2 > 100) AND (adcBits3 < 140) THEN

ELSEIF (adcBits3 > 100) THEN

ELSEIF (adcBits4 > 100) AND (adcBits3 < 140) THEN

ELSEIF (adcBits5 > 80) AND (adcBits3 < 150) THEN

ELSE
ENDIF
RETURN[/code][/code]

Thats a start, but some advice is to use the code feature to keep things formated. When you compose a reply message at the top of the window here are buttons : Quote, Code, List, List= Img, and URL. When posting code in the future, click the “Code” button, paste your code, then click the “Code” button again to close the code tag.

your code here

Thank you for teaching, I learn a lesson.

a couple of questions:

-where are the 5 light sensors physically located with respect to each other?

-are the sensors matched or calibrated in some way so that the same amount of light falling on each of them produces the same input to its ADC?