Fala Pessoal,
Estou tentando transmitir via radio uma string, e estou tendo algumas dificuldades.
Na verdade até consegui bons resultados, mas não consigo entender o por que de alguns comportamentos estranhos.
Código no Transmitter:
int axisRoll = 0;
int axisPitch = 1;
const int ez_left = 7;
int rollVal;
int pitchVal;
long pulse_left, cm_left;
void setup() {
Serial.begin(9600);
pinMode(axisRoll, INPUT);
pinMode(axisPitch, INPUT);
pinMode(ez_left, INPUT);
}void loop() {
rollVal = analogRead( axisRoll );
rollVal = map( rollVal, 305 , 600 , -90 , 90 );
pitchVal = analogRead( axisPitch );
pitchVal = map( pitchVal, 308, 603 , -90 , 90 );pulse_left = pulseIn(ez_left, HIGH);
cm_left = ( pulse_left/147 ) * 2.54;
Serial.println( "<"+String ( rollVal ) + "," + String ( pitchVal ) + "," + String ( cm_left )+ ">" );
delay(200);}
Código no receiver:
char inData[50];
int index = 0;
int busy = 0;
char messageFrag;int header = 0;
String message;void setup() {
Serial.begin(9600);
}
void loop() {
if ( Serial.available() > 0 ) {
messageFrag = Serial.read();
if ( header == 1 ) {
inData[index] = messageFrag;
index++;
} else {
if ( messageFrag == 60 ) { // beggining of the message
header = 1;
} else if ( messageFrag == 62 ) { // end of the message
header = 0;
printPacket();
} else {
inData[index] = 0;
index++;
}
}
}
}void printPacket() {
for (int i = 0; i < 50; i++) {
if ( inData[i] != 0 && inData[i] != 60 && inData[i] != 62 ) {
Serial.print( char ( inData[i] ) );
}
}
Serial.println("");
index = 0;
inData[index] = 0;}
Bom, a mensagem que eu esperava receber a cada 200 milisegundos seria:
10,10,165 ( ou algo do tipo)
No entendo, estou recebendo 4 mensagens seguidas de um intervalo de 1 segundo aproximadamente e depois mais 4 mensagens e assim vai...
Configurei os Xbee's através do CoolTerm já que uso Mac, a configuração está:
Xbee Transmitter:
ATMY5678
ATDL1234
ATDH0
ATID1111
Xbee Receiver:
ATMY1234
ATDL5678
ATDH0
ATID1111
Alguém faz idéia do que acontece?
Paz,
TF
Tags:
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por