Interfaçage d’une CMUCam2 à une OOPIC (3 / 5 étapes)

Étape 3: Connectez le câble de programmation standard et télécharger code

Connectez le câble de programmation standard et télécharger votre code. Voici des exemples de code pour vous aider à démarrer.

Ce code suivra le mouvement en utilisant les commandes LF et FD. Il va alterner IOLine 7 (accroché à une LED) et reflètent l’état du suivi LED sur le CMUCam.

 '******** serial port related objects ********Dim serialPort As New oSerialPortDim txBuff As New oBuffer27 'change 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'******** debug related objects ********Dim statLED As New oDIO1'**********************************************'* Generic Subroutines *'**********************************************Sub main 'initialize everything main_init 'set our output mask to only follow center of mass CMUCAM_setOutputMask(2, 3) 'load our initial difference frame CMUCAM_loadDiffFrame() 'start the difference calculation CMUCAM_startDiffCalc(10)End SubSub main_init 'initialize a status LED statLED.IOLine = 7 statLED.Direction = cvOutput 'initialize our serial port serial_init()End Sub'processes received packetsSub processPacket() Dim mx As Byte Dim my As Byte 'check for both Mx and My to be 0 'granted if they are not 0, the location will be off (ie 'T 12 34) 'but then they won't meet the 0 criteria rxBuff.Location = 2 mx = rxBuff.Value rxBuff.Location = 4 my = rxBuff.Value 'the 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'**********************************************'* CMU Cam Functions *'**********************************************'sets the given led to on, off, automatic'param ledNum number of led (0,1)'param val off, on, auto (0,1,2)Function CMUCAM_ledSet(ledNum As Byte, val As Byte) As Byte 'VString wasn't working right in the new compiler... 'not sure about the old one 'txBuff.VString = "L0 0" 'setup our command string manually txBuff.Location = 0 txBuff.Value = "L" txBuff.Location = 1 'the str$ function sucks...so 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 'send the command serial_SendBufferEnd Sub'loads the initial difference frameSub CMUCAM_loadDiffFrame() 'setup our command string manually txBuff.Location = 0 txBuff.Value = "L" txBuff.Location = 1 txBuff.Value = "F" txBuff.Location = 2 txBuff.Value = 13 'send the command serial_SendBufferEnd Sub'starts calculating frame differences'param thresh threshold (0-9)Sub CMUCAM_startDiffCalc(thresh As Byte) Dim tens As Byte 'setup 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 'send the command serial_SendBufferEnd Sub'sets the output mask'param packetType type of packet to mask (0,1,2,etc) see page 46'param mask mask value to apply (0-255)Sub CMUCAM_setOutputMask(packetType As Byte, mask As Byte) Dim hundreds As Byte Dim tens As Byte 'setup our command string manually txBuff.Location = 0 txBuff.Value = "O" txBuff.Location = 1 txBuff.Value = "M" txBuff.Location = 2 txBuff.Value = " " 'packet type txBuff.Location = 3 txBuff.Value = serial_toChar(packetType) txBuff.Location = 4 txBuff.Value = " " 'mask 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) 'carriage return txBuff.Location = 8 txBuff.Value = 13 'send the command serial_SendBufferEnd Sub'**********************************************'* General Serial Subroutines *'**********************************************'initializes the serial portSub serial_init() 'initialize 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 'initialize an event to buffer our data serialReceive_Wire.Input.Link(serialPort.Received) serialReceive_Wire.Output.Link(serialReceive_Event.Operate) serialReceive_Wire.Operate = cvTrue 'initialize our RX buffer rxBuff.Location = 0 'initialize our serial port serialPort.Baud = cv9600 'initialize our serial status LED serialActive_LED.IOLine = 6 serialActive_LED.Direction = cvOutput 'wait here until our serial port gets activated While serialPort.Operate = cvFalse WendEnd Sub'copies data into our receive buffer and checks for packet completionSub serialReceive_Event_Code() '.received becomes false when 4byte buffer is empty While(serialPort.Received = cvTrue) 'copy the byte to our buffer rxBuff.Value = serialPort.Value 'check for end of packet If rxBuff.Value = 13 'process packet processPacket() 'reset the buffer to the beginning rxBuff.Location = 0 Else rxBuff.Location = rxBuff.Location + 1 EndIf WendEnd Sub'turns 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'converts 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' sends the data contained in txBuff' Note: make sure buffer contains a carriage return (13) at the end!!Sub serial_SendBuffer() 'iterate through, sending each byte, end on carriage return txBuff.Location = 0 While 1 serialPort.Value = txBuff.Value ooPIC.Delay = 1 'might not need this 'see if it was a carriage return If txBuff.Value = 13 'break out of our loop Return End If 'go to the next character txBuff.Location = txBuff.Location + 1 WendEnd Sub 

Articles Liés

INTERFAÇAGE d’une matrice de 8 X 8 points LED affichage avec un AT89C51 microcontrôleur

INTERFAÇAGE d’une matrice de 8 X 8 points LED affichage avec un AT89C51 microcontrôleur

Interfaçage sur un 8 x 8 matricielle peut être amusant et est facile à jouer avec, nous allons donc rentrer directement dedans !Étape 1: Vous aurez besoin :AT89C51 MICROCONTRÔLEURMATRICE 8 X 8UN CONSEIL DE DÉVELOPPEMENT OUMODULE DE MATRICE DE POINTSÉ
PC interfaçage d’une caméra de GameBoy

PC interfaçage d’une caméra de GameBoy

Voici un autre passé le projet de la mine depuis une couple d'années. À cette époque, je cherchais un appareil basse résolution pour le traitement d'image simple robotique et tout j'ai eu l'expérience avec a PIC (12, 16 et 18) microcontrôleurs. Donc
Accéléromètre, interfaçage avec une planche Mediatek Linkit

Accéléromètre, interfaçage avec une planche Mediatek Linkit

Aujourd'hui, je vais montrer comment Mediatek Linkitone Conseil travaille avec accellerometer ADXL335.Le ADXL335 est un petite, mince, faible consommation, complète accéléromètre 3 axesavec signal conditionné sorties de tension. L'accélération des me
Servo moteur de balayage Mode interfaçage avec une planche Mediatek Linkit

Servo moteur de balayage Mode interfaçage avec une planche Mediatek Linkit

Un servomoteur est un vérin rotatif ou actionneur linéaire qui permet un contrôle précis de la position angulaire ou linéaire, de vitesse et d'accélération. [1] il se compose d'un moteur approprié couplé à un capteur de position. Il requiert égalemen
Interfaçage d’un M74HC238 3-8 Line décodeur avec un Arduino (exemple)

Interfaçage d’un M74HC238 3-8 Line décodeur avec un Arduino (exemple)

il s'agit d'un didacticiel de base conçu pour vous donner une compréhension de base de l'utilisation d'un M74HC238 décodeur ligne 3-8.Comme son nom l'indique, vous devrez seulement 3 broches numériques sur votre Arduino pour contrôler tous les 8 sort
Interfaçage des moteurs avec Arduino

Interfaçage des moteurs avec Arduino

Interfaçage des différents types de moteurs avec un microcontrôleur est parmi les compétences les plus fondamentaux, un passionné de maker/robotique besoins au maître. Dans ce projet je vais accumuler du précédent projet Smart Phone contrôlée LED s'a
Objet numérique compteur à l’aide de LDR interfaçage avec Mediatek LinkIt One

Objet numérique compteur à l’aide de LDR interfaçage avec Mediatek LinkIt One

Dans ce Instructable, vous serez en mesure à Mediatek Linkit une carte d'Interface à l'aide de LDR et compteur d'objet numérique qui peut comte objets jusqu'à 9999.Étape 1: exigences Usage général PCB bord4 CD 4026 Johnson décennie Counter.4 communes
Interfaçage d’un micromètre numérique à un Arduino & moniteur VGA

Interfaçage d’un micromètre numérique à un Arduino & moniteur VGA

Mise à jour : Igaging origine série utilisez un câble de Mitutoyo et la sortie du flux de données bit Mitutoyo 52. Le code et les schémas ci-dessous travaux SPC Digimatic étriers, micromètres, à composer des indicateurs et des échelles des deux socié
* mise à jour * LED-tour « Hello », Vu-mètre avancé de détection musique sans qu’avec Arduino et l’interfaçage d’IC avec le logiciel PC Windows !

* mise à jour * LED-tour « Hello », Vu-mètre avancé de détection musique sans qu’avec Arduino et l’interfaçage d’IC avec le logiciel PC Windows !

LED-tour « Hello », Vu-mètre avancé de détection musique sans qu'avec Arduino d'ICet l'interfaçage avec le logiciel PC Windows ! Salut, tout le monde.Ce qui rend ce projet cool c'est le fait, que sa musique de télédétection, contrairement aux traditi
Interfaçage de Circuits électroniques à Arduinos

Interfaçage de Circuits électroniques à Arduinos

interfaçage de Circuits électroniques pour ArduinoDans ce instructable j'utilise un exemple d'interfacer un Arduino à un émetteur-récepteur ARINC 429 afin de démontrer le processus général d'interfacer un Arduino pour circuits électroniques, donc vou
Boulon d’interfaçage avec Arduino : Boulon UART

Boulon d’interfaçage avec Arduino : Boulon UART

IntroductionCette instructable faite pour les utilisateurs de boulon qui souhaitent l'obturateur hardware Arduino Uno d'interface ou tout simplement envie d'expérimenter avec l'UART de boulon.Conditions préalablesAccès à l'atelier de boulon ITO et sa
SIM900A interfaçage avec Arduino UNO et Running AT simples commandes

SIM900A interfaçage avec Arduino UNO et Running AT simples commandes

Bonjour les gars,J'ai mon nouveau module SIM900A de SIMCom. Je faisais face à des problèmes tout en elle interagira avec Arduino Mega.Puis j'ai essayé il interface avec arduino UNO. Donc dans ce instructable je vais vous montrer comment j'ai surmonté
Interfaçage MSP430 Launchpad avec affichage 7 segments

Interfaçage MSP430 Launchpad avec affichage 7 segments

Bonjour les gens,Bienvenue à mon MSP430 Launchpad interfaçage tutoriel, dans ce instructable je va être entoilage un Launchpad MSP430 avec un affichage 7 segments de la cathode commune.Veuillez noter que je suis reformater mon article original publié
Interfaçage GY 26 avec atmega640

Interfaçage GY 26 avec atmega640

Bonjour ami une fois de plus avec les nouveaux instructable dans ce que je vous montrera comment interfacer GY 26 avec UART quand j'ai commencé à travailler sur ce très moins de ressources où disponible sur internet. Donc j'ai pensé partager mon trav