Arduino IR Sensör Kodu Çalışmıyor

Affansen

Kilopat
Katılım
17 Nisan 2020
Mesajlar
4.766
Makaleler
1
Çözümler
29
Nedenini bilmediğim bir şekilde mBlock ile IR kumanda kodu yaparken hata alıyorum. Kodu Arduino IDE ile açınca ise şu hatayı alıyorum:
Kod:
Arduino:1.6.5 (Windows 8.1), Kart:"Arduino/Genuino Uno"

IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `MATCH(int, int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `MATCH_MARK(int, int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `MATCH_SPACE(int, int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::IRrecv(int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `irparams'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::IRrecv(int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::enableIRIn()'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::blink13(int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `__vector_7'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::resume()'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::decodeNEC(decode_results*)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::getRClevel(decode_results*, int*, int*, int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::compare(unsigned int, unsigned int)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::decodeHash(decode_results*)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
IRremote_ard.cpp.o: In function `MATCH(int, int)':
D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremote_ard.cpp:69: multiple definition of `IRrecv::decode(decode_results*)'
IRremoteNEW.cpp.o:D:\Users\AFFAN\AppData\Local\Temp\build3132428152192588699.tmp/IRremoteIntNEW.h:176: first defined here
collect2.exe: error: ld returned 1 exit status
Derleme sırasında hata oluştu.

  Rapor daha fazla veri içermeli
  "Derleme sırasında ayrıntılı çıktı göster"
  Dosya > Tercihler'de etkinleştirilmiş.

@Toqtirrr


NOT: Windows 10 kullanıyorum. 8.1 diye kayıta geçmiş.
 
Son düzenleme:
IRremoteNEW.h dosyasını kütüphane eklemen lazım gibi, sanırım.

Ancak derleme hatası diyor. MBlock'tan Arduino'ya dönüşümde bir hata olmuş olabilir. MBlock yerine Arduino ile yazman daha iyi olur, böyle karmaşık sensörler için.
 
Son düzenleme:
Ancak derleme hatası diyor. MBlock'tan Arduino'ya dönüşümde bir hata olmuş olabilir. MBlock yerine Arduino ile yazman daha iyi olur, böyle karmaşık sensörler için.
Durum değişmiyor. Yani mBlock derlerken yine hata oluyor. Arduino IDE'ye çevirince de aynı sorun var. Orada da aynı hata var. Sizde kod sorun çıkarttı mı? Yoksa acaba sorun bende mi?
IRremoteNEW.h dosyasını kütüphane gibi eklemen lazım sanırım.
Bulup ekledikten sonra tekrar yazacağım teşekkürler.
 
Kütüphaneye ekle: IRremote.rar

Yapacağın şeyleri şu koda ekle:
C++:
/*
* IRremote: IRrecvDump - dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
* LG added by Darryl Smith (based on the JVC protocol)
*/

#include <IRremote.h>

/*
*  Default is Arduino pin D11.
*  You can change this to another available Arduino Pin.
*  Your IR receiver should be connected to the pin defined here
*/
int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}


void dump(decode_results *results) {
  // Dumps out the decode_results structure.
  // Call this after IRrecv::decode()
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");

  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->address, HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
    Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
    Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 1; i < count; i++) {
    if (i & 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.write('-');
      Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}

Ayrıca eski IRRemote kütüphanesini kaldır, zira sıkıntı çıkarıyor bu kütüphane ile.
 
Son düzenleme:
Kütüphaneye ekle: IRremote.rar

Yapacağın şeyleri şu koda ekle:
C++:
/*
* IRremote: IRrecvDump - dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
* LG added by Darryl Smith (based on the JVC protocol)
*/

#include <IRremote.h>

/*
*  Default is Arduino pin D11.
*  You can change this to another available Arduino Pin.
*  Your IR receiver should be connected to the pin defined here
*/
int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}


void dump(decode_results *results) {
  // Dumps out the decode_results structure.
  // Call this after IRrecv::decode()
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");

  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->address, HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
    Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
    Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 1; i < count; i++) {
    if (i & 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.write('-');
      Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}
Kütüphane zaten kurulu. Dediğiniz şey galiba demo diye geçen örneği. Bu örnekte alınan veri seri porta yazdırılıyor. Buraya kadar normal. Ben zaten bunu yaptım. Bana gerekli olan şey uzaktan kumandalı araba yapmak için gereken kodu içine yerleştirmek.

Kumanda NEC marka bu arada.
 
Seri portta kumandanın tuşlarının değerini görebiliyor musun?
Tabi ki. 0X001 gibi değerler görebiliyorum örnek olarak. Tabi bunu dün gece sizin verdiğiniz kod ile yaptım. İnternette yabancı bir kaynakta yazıyordu böyle yapmak gerektiği. Bana gerekli olan şey mBlock ile çalıştırmak.


Bir de eklemiş olayım, diğer kodlar çalışmıyor. Mesela internette Arduino ile kumanda uygulamaları kodları var ya, hiç biri çalışmıyor bende. 0 değeri görünüyor. :D
 
Peki şöyle yapsan:

Mesela 0X001 değeri mi geldi, ileri git. Komutunu versen, nasıl olur?

"if(veri == 0X001){
digitalWrite(motor1_pin, 1);
digitalWrite(motor2_pin, 1);
digitalWrite(motor3_pin, 1);
digitalWrite(motor4_pin, 1);
}"

Mesela üstteki 2 dakikada yazdığım basit kod gibi. Bunları loopa eklesen. Sorun çözülmez mi?

Bunu ben 6. sınıfta yazmıştım, belki yardımı dokunur:
C++:
#include <SoftwareSerial.h>
#define in1 2
#define in2 3
#define in3 4
#define in4 5
#define k1 7
#define m1 8
#define k2 9
#define m2 11
#define buzzer 10
#define arka1 12
#define arka2 13
SoftwareSerial myBluetooth(0, 1);
char veri;
void setup() {
 pinMode(in1, OUTPUT);
  pinMode(in1, OUTPUT);
 pinMode(in2, OUTPUT);
 pinMode(in3, OUTPUT);
 pinMode(in4, OUTPUT);
 pinMode(k1, OUTPUT);
 pinMode(m1, OUTPUT);
 pinMode(k2, OUTPUT);
 pinMode(m2, OUTPUT);
 pinMode(arka1, OUTPUT);
 pinMode(buzzer, OUTPUT);
 pinMode(arka2, OUTPUT);
 myBluetooth.begin(9600);
}
void loop() {
   if(myBluetooth.available())
   {
      veri = myBluetooth.read();
      if(veri == 'F')
      {
        ileri();
      }
      else if(veri == 'B')
      {
        geri();
      }
      else if(veri == 'L')
      {
        sola();
      }
      else if(veri == 'R')
      {
        saga();
      }
      else if(veri == 'S')
      {
        dur();
      }
       else if(veri == 'G')
      {
        sol_ileri();
      }
      else if(veri == 'I')
      {
        sag_ileri();
      }
      else if(veri == 'H')
      {
        sol_geri();
      }
      else if(veri == 'J')
      {
        sag_geri();
      }
      else if(veri == 'W')
      {
       rgb_1_on();
       rgb_2_on();
      }
      else if(veri == 'w')
      {
       rgb_1_off();
       rgb_2_off();
      }
      else if(veri == 'U')
      {
       arka_1_on();
       arka_2_on();
      }
      else if(veri == 'u')
      {
       arka_1_off();
       arka_2_off();
      }
      else if(veri == 'V')
      {
       digitalWrite(10, 1);
      }
      else if(veri == 'v')
      {
       digitalWrite(10, 0);
      }
      }
}
void ileri()
{
  digitalWrite(in1, 1);
  digitalWrite(in2, 0);
  digitalWrite(in3, 1);
  digitalWrite(in4, 0);
}
void saga()
{
  digitalWrite(in1, 0);
  digitalWrite(in2, 1);
  digitalWrite(in3, 1);
  digitalWrite(in4, 0);
  }
void sola()
{
  digitalWrite(in1, 1);
  digitalWrite(in2, 0);
  digitalWrite(in3, 0);
  digitalWrite(in4, 1);
}
void geri()
{
  digitalWrite(in1, 0);
  digitalWrite(in2, 1);
  digitalWrite(in3, 0);
  digitalWrite(in4, 1);
}
void dur()
{
  digitalWrite(in1, 0);
  digitalWrite(in2, 0);
  digitalWrite(in3, 0);
  digitalWrite(in4, 0);
}
void sol_ileri()
{
  digitalWrite(in1, 1);
  digitalWrite(in2, 0);
  digitalWrite(in3, 0);
  digitalWrite(in4, 0);
}
void sag_ileri()
{
  digitalWrite(in1, 0);
  digitalWrite(in2, 0);
  digitalWrite(in3, 1);
  digitalWrite(in4, 0);
}
void sol_geri()
{
  digitalWrite(in1, 0);
  digitalWrite(in2, 1);
  digitalWrite(in3, 0);
  digitalWrite(in4, 0);
}
void sag_geri()
{
  digitalWrite(in1, 0);
  digitalWrite(in2, 0);
  digitalWrite(in3, 0);
  digitalWrite(in4, 1);
}
void rgb_1_on()
{
  digitalWrite(k1, 0);
  digitalWrite(m1, 0);
}
void rgb_1_off()
{
  digitalWrite(k1, 1);
  digitalWrite(m1, 1);
}
void rgb_2_on()
{
  digitalWrite(k2, 0);
  digitalWrite(m2, 0);
}
void rgb_2_off()
{
  digitalWrite(k2, 1);
  digitalWrite(m2, 1);
}
void arka_1_on()
{
  digitalWrite(arka1, 1);
}
void arka_2_on()
{
  digitalWrite(arka2, 1);
}
void arka_1_off()
{
  digitalWrite(arka1, 0);
}
void arka_2_off()
{
  digitalWrite(arka2, 0);
}
 

Geri
Yukarı