Interfacing a CMUCam2 to an OOPIC

Introduction: Interfacing a CMUCam2 to an OOPIC

Overview of how to interface a CMUCam2 to and OOPIC.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Making the Adapter Cable

1. Goto radioshack and buy 2 of these:
Male DB-9 Solder Cup Connector

2. solder pin 5 on connector A to pin 5 on connector B (if you look carefully on the connector, they are marked)

3. solder pin 2 on connector A to pin 3 on connector B (if you look carefully on the connector, they are marked)

4. solder pin 3 on connector A to pin 2 on connector B (if you look carefully on the connector, they are marked)

Step 2: Change the Baud Rate on the CMUCam

Change the baud rate of the CMUCamera to 9600 baud (add a jumper to position 0).

Step 3: Connect the Standard Programming Cable and Upload Code

Connect the standard programming cable and upload your code. Here is some example code to get you started.

This code will track motion using the LF and FD commands. It will toggle IOLine 7 (hooked up to an LED) and mirror the tracking status LED on the CMUCam.

&apos******** serial port related objects ********Dim serialPort As New oSerialPortDim txBuff As New oBuffer27		&aposchange the 27 to make the buffer bigger/smallerDim rxBuff As New oBuffer10Dim serialActive_LED As New oDIO1Dim toggleSerial_Button As New oDIO1Dim toggleSerial_Event As New oEventDim toggleSerial_Wire As New oWireDim serialReceive_Event As New oEventDim serialReceive_Wire As New oWire&apos******** debug related objects ********Dim statLED As New oDIO1&apos**********************************************&apos*           Generic Subroutines              *&apos**********************************************Sub main	&aposinitialize everything	main_init		&aposset our output mask to only follow center of mass	CMUCAM_setOutputMask(2, 3)			&aposload our initial difference frame	CMUCAM_loadDiffFrame()	&aposstart the difference calculation	CMUCAM_startDiffCalc(10)End SubSub main_init	&aposinitialize a status LED	statLED.IOLine = 7	statLED.Direction = cvOutput		&aposinitialize our serial port	serial_init()End Sub&aposprocesses received packetsSub processPacket()	Dim mx As Byte	Dim my As Byte		&aposcheck for both Mx and My to be 0	&aposgranted if they are not 0, the location will be off (ie &aposT 12 34)	&aposbut then they won&apost meet the 0 criteria	rxBuff.Location = 2	mx = rxBuff.Value	rxBuff.Location = 4	my = rxBuff.Value		&aposthe led should blink in unison with the tracking LED on the camera	If (mx = "0") And (my = "0")		statLED = 0	Else		statLED = 1	End IfEnd Sub&apos**********************************************&apos*             CMU Cam Functions              *&apos**********************************************&apossets the given led to on, off, automatic&aposparam ledNum number of led (0,1)&aposparam val off, on, auto (0,1,2)Function CMUCAM_ledSet(ledNum As Byte, val As Byte) As Byte	&aposVString wasn&apost working right in the new compiler...	&aposnot sure about the old one	&apostxBuff.VString = "L0 0"		&apossetup our command string manually	txBuff.Location = 0	txBuff.Value = "L"		txBuff.Location = 1	&aposthe str$ function now this is happening	txBuff.Value = serial_toChar(ledNum)		txBuff.Location = 2	txBuff.Value = " "		txBuff.Location = 3	txBuff.Value = serial_toChar(val)		txBuff.Location = 4	txBuff.Value = 13		&apossend the command	serial_SendBufferEnd Sub&aposloads the initial difference frameSub CMUCAM_loadDiffFrame()	&apossetup our command string manually	txBuff.Location = 0	txBuff.Value = "L"		txBuff.Location = 1	txBuff.Value = "F"		txBuff.Location = 2	txBuff.Value = 13		&apossend the command	serial_SendBufferEnd Sub&aposstarts calculating frame differences&aposparam thresh threshold (0-9)Sub CMUCAM_startDiffCalc(thresh As Byte)	Dim tens As Byte	&apossetup our command string manually	txBuff.Location = 0	txBuff.Value = "F"		txBuff.Location = 1	txBuff.Value = "D"		txBuff.Location = 2	txBuff.Value = " "		txBuff.Location = 3	tens = thresh/10	txBuff.Value = serial_toChar(tens)		txBuff.Location = 4	tens = thresh/10	txBuff.Value = serial_toChar(thresh-tens)		txBuff.Location = 5	txBuff.Value = 13		&apossend the command	serial_SendBufferEnd Sub&apossets the output mask&aposparam packetType type of packet to mask (0,1,2,etc) see page 46&aposparam mask mask value to apply (0-255)Sub CMUCAM_setOutputMask(packetType As Byte, mask As Byte)	Dim hundreds As Byte	Dim tens As Byte		&apossetup our command string manually	txBuff.Location = 0	txBuff.Value = "O"		txBuff.Location = 1	txBuff.Value = "M"		txBuff.Location = 2	txBuff.Value = " "		&apospacket type	txBuff.Location = 3	txBuff.Value = serial_toChar(packetType)	txBuff.Location = 4	txBuff.Value = " "		&aposmask to apply	txBuff.Location = 5	hundreds = mask/100	txBuff.Value = serial_toChar(hundreds)		txBuff.Location = 6	tens = (mask-hundreds)/10	txBuff.Value = serial_toChar(tens)		txBuff.Location = 7	txBuff.Value = serial_toChar(mask-hundreds-tens)		&aposcarriage return	txBuff.Location = 8	txBuff.Value = 13		&apossend the command	serial_SendBufferEnd Sub&apos**********************************************&apos*         General Serial Subroutines         *&apos**********************************************&aposinitializes the serial portSub serial_init()	&aposinitialize a button to turn on and off the serial port (turn on to run, turn off to program)	toggleSerial_Button.IOLine = 5	toggleSerial_Button.Direction = cvInput	toggleSerial_Wire.Input.Link(toggleSerial_Button.Value)	toggleSerial_Wire.Output.Link(toggleSerial_Event.Operate)	toggleSerial_Wire.Operate = cvTrue		&aposinitialize an event to buffer our data	serialReceive_Wire.Input.Link(serialPort.Received)	serialReceive_Wire.Output.Link(serialReceive_Event.Operate)	serialReceive_Wire.Operate = cvTrue	&aposinitialize our RX buffer	rxBuff.Location = 0		&aposinitialize our serial port	serialPort.Baud = cv9600		&aposinitialize our serial status LED	serialActive_LED.IOLine = 6	serialActive_LED.Direction = cvOutput	&aposwait here until our serial port gets activated	While serialPort.Operate = cvFalse	WendEnd Sub&aposcopies data into our receive buffer and checks for packet completionSub serialReceive_Event_Code()	&apos.received becomes false when 4byte buffer is empty	While(serialPort.Received = cvTrue)		&aposcopy the byte to our buffer		rxBuff.Value = serialPort.Value				&aposcheck for end of packet		If rxBuff.Value = 13			&aposprocess packet			processPacket()									&aposreset the buffer to the beginning			rxBuff.Location = 0		Else			rxBuff.Location = rxBuff.Location + 1		EndIf	WendEnd Sub&aposturns on and off the serial port for programmingSub toggleSerial_Event_Code()	If serialPort.Operate = cvFalse		serialPort.Operate = cvTrue		serialActive_LED = 1	Else		serialPort.Operate = cvFalse		serialActive_LED = 0	End IfEnd Sub&aposconverts a single digit number to a characterFunction serial_toChar(inVal As Byte) As Byte	Dim retVal As Byte	Select Case inVal		Case 0			retVal = "0"		Case 1			retVal = "1"		Case 2			retVal = "2"		Case 3			retVal = "3"		Case 4			retVal = "4"		Case 5			retVal = "5"		Case 6			retVal = "6"		Case 7			retVal = "7"		Case 8			retVal = "8"		Case 9			retVal = "9"	End Select		serial_toChar = retValEnd Function&apos sends the data contained in txBuff&apos Note: make sure buffer contains a carriage return (13) at the end!!Sub serial_SendBuffer()	&apositerate through, sending each byte, end on carriage return	txBuff.Location = 0	While 1		serialPort.Value = txBuff.Value		ooPIC.Delay = 1		&aposmight not need this				&apossee if it was a carriage return		If txBuff.Value = 13			&aposbreak out of our loop			Return		End If		&aposgo to the next character				txBuff.Location = txBuff.Location + 1	WendEnd Sub

Step 4: Disconect the Programming Connector

Once the programming connector is disconnected, attach the new cable assembly as shown below. The adapter made in step 1 should allow the CMUCam to be directly plugged into the OOPIC

Step 5: Press the Button to Initialize Serial Communication

The button on IOLine 5 will start the serial communication between the CMUCam and the OOPIC. Since the serial port is used for both programming and the CMUCam, there probably should be a controlled way of toggling between the two.

The program will not run until this button is pressed. If you press the button again, the serial port will go inactive, allowing you to program it. The LED on IOLine 6 displays the current serial port status (on means active, off means ready for programming).

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    2 Discussions


    12 years ago on Introduction

    Hello, and welcome to the Instructables community!

    This currently does not meet our criteria for an Instructable. A completed Instructable:

    - details a finished project with instruction (not just links to instructions)
    - has clear images that you took of your project (web-found clip-art is not acceptable)
    - uses proper spelling and grammar
    - contains appropriate cautions or safety considerations
    - does not violate someone else's copyright
    - does not violate the Instructables terms of service
    - is typically written about something you are very passionate about and want to share.

    If this is a comment, a question, a small tip, or something that cannot truly be a finish project, please post it as a forum topic. If you are looking to start a collaboration, post a topic in the forums.

    Look here: for tips on writing a great Instructable.

    So, it has been unpublished. Please do not republish until it has been corrected. When you republish, if everything is fixed, I'll remove this note. Multiple attempts to republish without correction will result in deletion.