First apply power to the CMUcam as shown in this diagram:
Then connect the Data wires as shown in this diagram. Be sure to remove the Max232 chip.
Connect the GND wire of the CMUcam to a GND pin on your microcontroller. Connect the SX28 Transmit pin to your Rx pin of the microcontroller( on the Axon I chose to use the Rx of UART0). Connect the SX28 Receive pin to your Tx pin of the microcontroller (on the Axon I chose the Tx of UART0).
Now that the electrical connections are set up , we move on to programming.
NOTE: The following code was made for the Axon microcontroller , but can easily be adapted.
UART Initialization:
uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 115200); // set UARTE speed, for Bluetooth , this is the UART port
CMUcam Initialization
void CMUcam_Initialize(void) { rprintfInit(uart0SendByte);//change UART to CMUcam rprintf("RS"); // Reset CMUcam delay_ms(500); // wait 500 milliseconds rprintf("cr 18 44"); // Set CMUcam to AutoExposure delay_ms(500); // wait 500 milliseconds rprintf("RM 1"); // Set CMUcam to Raw Serial Mode delay_ms(500); // wait 500 milliseconds rprintfInit(uart1SendByte);//change UART to USB rprintf("CMUcam Initialized"); // send out the message through USB }
Set Tracking of CMUcam rprintfInit(uart0SendByte); rprintf("TC 90 250 0 20 0 20"); // set tracking to this specific color
// format is minRed maxRed minGreen maxGreen minBlue maxBlue delay_us(500); // wait 500 microseconds
Get Tracking Data
int CMUcam_MiddleMass(void) //echos # of characters expected for each command { int temp; // set up temporary variable int counter=0; //set the counter to 0 int echo_counter=0; // set the echo_counter to 0 int temp1;
rprintfInit(uart1SendByte);//change UART to bluetooth temp = uart0GetByte(); // Get a Byte while (temp != 255) { // Keep on getting new bytes until the byte = 255 temp = uart0GetByte(); } rprintf("Start= %d ",temp); temp = uart0GetByte(); // Get a Byte while (temp != 77) { // Keep on getting new bytes until the byte = 'M' temp = uart0GetByte(); } rprintf("M= %d ",temp);
echo_counter = 8; // expect 8 bytes ( 0 thru 7) while(1) { temp=uart0GetByte();//returns -1 if no data present
response[counter]=temp;//store values into an array counter++; // add one to "counter" array
if(counter == echo_counter) // once the counter equals the echo_counter { // successfully captured the entire M packet uartFlushReceiveBuffer(0);//flush out receive camera buffer to stop phase shifting delay_us(100);