Ciao!Ho un problema con il mio arduino Uno e con i miei xbee series 2(con antenna).Dopo aver caricato il codice sull'arduino e dopo aver collegato un xbee al pc e l'altro all'arduino,provo a mandare dei comandi via monitor seriale.Alcuni comandi funzionano(ad esempio left e right) ma altri tipo go o back no.Perchè?Aiutatemiii.Grazie mille
Usb board:
La shield xbee che uso è questa(senza SD):
L'arduino è alimentato esternamente con una batteria da 9V come in questa figura:
http://www.arduino.cc/playground/Lea...BatteryAdapter
ps:sull'arduino,ho collegato una motor shield e poi la xbee shield.La motorshield è questa:
not_found...)_(SKURI0009)
Codice(non guardate i comandi dell'IR e dei LED):
char comando;
const int pinsensore=2;
int statesens=HIGH;
const int ledCount = 10;
int ledPins[] = {0,1,2,3,8,9,10,11,12,13};
void setup(){
Serial.begin(9600);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(ledPins[0], OUTPUT);
pinMode(ledPins[1], OUTPUT);
pinMode(ledPins[2], OUTPUT);
pinMode(ledPins[3], OUTPUT);
pinMode(ledPins[4], OUTPUT);
pinMode(ledPins[5], OUTPUT);
pinMode(ledPins[6], OUTPUT);
pinMode(ledPins[7], OUTPUT);
pinMode(ledPins[8], OUTPUT);
pinMode(ledPins[9], OUTPUT);
pinMode(pinsensore,INPUT);
}
void loop(){
/*if(digitalRead(pinsensore)==LOW)
{
stop();
back();
delay(500);
left();
delay(1500);
go();
}*/
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[9], HIGH);
if(Serial.available()>0){
comando=Serial.read();
Serial.println(comando);
switch(comando){
case 'g': go(); digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], HIGH);
digitalWrite(ledPins[4], HIGH);
digitalWrite(ledPins[5], HIGH);
digitalWrite(ledPins[6], HIGH);
digitalWrite(ledPins[7], LOW);
digitalWrite(ledPins[8], LOW);
digitalWrite(ledPins[9], HIGH);break;
case 's': stop(); digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[3], LOW);
digitalWrite(ledPins[4], LOW);
digitalWrite(ledPins[5], LOW);
digitalWrite(ledPins[6], LOW);
digitalWrite(ledPins[9], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[7], LOW);break;
case 'b': back();digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[3], HIGH);
digitalWrite(ledPins[4], HIGH);
digitalWrite(ledPins[5], HIGH);
digitalWrite(ledPins[6], HIGH);
digitalWrite(ledPins[9], HIGH);
break;
case 'r': right(); digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[3], HIGH);
digitalWrite(ledPins[4], LOW);
digitalWrite(ledPins[5], LOW);
digitalWrite(ledPins[6], HIGH);
digitalWrite(ledPins[9], HIGH);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[7], LOW);break;
case 'l': left(); digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[3], HIGH);
digitalWrite(ledPins[4], LOW);
digitalWrite(ledPins[5], LOW);
digitalWrite(ledPins[6], HIGH);
digitalWrite(ledPins[9], HIGH);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[7], LOW);
break;
}
}
}
void go(){
//Motore sinistro
digitalWrite(7,HIGH);
analogWrite(6,255);
//Motore destro
digitalWrite(4,HIGH);
analogWrite(5,255);
}
void stop(){
//Motore sinistro
digitalWrite(7,LOW);
analogWrite(6,0);
//Motore destro
digitalWrite(4,LOW);
analogWrite(5,0);
}
void back(){
//Motore sinistro
digitalWrite(7,LOW);
analogWrite(6,255);
//Motore destror
digitalWrite(4,LOW);
analogWrite(5,255);
}
void right(){
//Motore sinistro
digitalWrite(7,HIGH);
analogWrite(6,255);
//Motore destro
digitalWrite(4,LOW);
analogWrite(4,0);
}
void left(){
digitalWrite(7,LOW);
analogWrite(6,0);
//Motore destro
digitalWrite(4,HIGH);
analogWrite(5,255);
}
Foto robottino(shield xbee diversa ma struttura uguale):
Grazieee