PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Arduino Duemillenova mit Eclipse Programmieren



Kucky
10.04.2010, 16:20
Hallo zusammen,
ich habe nach vielen Stunden Eclipse (Galileo) für Arduino configuriert. Der Testcode lt. Tutorial war auch OK. Habe nun diesen Code versucht, das allseits bekannte "Blink":


/*
* main.c
*
* Created on: 09.04.2010
* Author: Willi
*/

#include <avr/io.h>
#include <WProgram.h>
int ledPin = 13;

int main(void) {
pinMode(ledPin, OUTPUT);

for(;;) {
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
}


Dann werden folgende Meldungen in der Console angezeigt:


**** Build of configuration Release for project Tutorial_01 ****

make all
Building file: ../Tone.cpp
Invoking: AVR C++ Compiler
avr-g++ -Wall -Os -fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -fno-exceptions -mmcu=atmega328p -DF_CPU=16000000UL -MMD -MP -MF"Tone.d" -MT"Tone.d" -c -o"Tone.o" "../Tone.cpp"
../Tone.cpp:36:20: warning: wiring.h: No such file or directory
../Tone.cpp:37:26: warning: pins_arduino.h: No such file or directory
../Tone.cpp:101: warning: only initialized variables can be placed into program memory area
../Tone.cpp: In function 'int8_t toneBegin(uint8_t)':
../Tone.cpp:141: error: 'bitWrite' was not declared in this scope
../Tone.cpp:143: error: 'digitalPinToPort' was not declared in this scope
../Tone.cpp:143: error: 'portOutputRegister' was not declared in this scope
../Tone.cpp:144: error: 'digitalPinToBitMask' was not declared in this scope
../Tone.cpp: In function 'void tone(uint8_t, unsigned int, long unsigned int)':
../Tone.cpp:218: error: 'OUTPUT' was not declared in this scope
../Tone.cpp:218: error: 'pinMode' was not declared in this scope
../Tone.cpp:314: error: 'bitWrite' was not declared in this scope
../Tone.cpp: In function 'void noTone(uint8_t)':
../Tone.cpp:398: error: 'digitalWrite' was not declared in this scope
make: *** [Tone.o] Error 1



Kann mir bitte einer helfen. Ich habe das AVR-Eclips Tutorial 1+2 und das playground-Tutorial bestimmt schon 10 mal gelesen und die Config überprüft.
Gruß aus Leverkusen
Willi

Kucky
10.04.2010, 21:30
Was mir noch aufgefallen ist, dass nach der Bearbeitung von Eclipse die Arduino IDE diesen Fehler beim uploaden anzeigt.

G:\UserDaten\Willi\Documents\Programmierung\Arduin o\Arduino Projekte\blink.png


Binary sketch size: 896 bytes (of a 30720 byte maximum)

avrdude: stk500_getsync(): not in sync: resp=0x30
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
Gruß
Willi

Thomas$
10.04.2010, 22:30
warum nutzt du nicht die fertige umgebung?

Kucky
11.04.2010, 07:56
Ich bin auf dem Gebiet der Programmierung ein Anfänger, und hätte gern eine IDE die mir Fehler anzeigt, bzw. eine Trace Funktion, mit der ich ein Programm "verfolgen" kann.

Thomas$
11.04.2010, 10:54
die fertige ide zeigt die syntax fehler an und um den rest wie denkfehler zu finden nutzt ich die serielle schnittstelle ich send einfach alles wichtigen variablen an den computer und meist findet man da seine denkfehler

Kucky
11.04.2010, 11:45
Das ist ja alles gut und schön, und den Kniff kenne ich auch. Ist aber keine Antwort auf meine Frage. Trotzdem Danke.
VGW

Kucky
20.04.2010, 22:40
Hallo zusammen,
ich bin nun nach ca. 100.000 Seiten O:) und zig Tutorials weitergekommen. Was aber übrig bleibt, ist dieser Fehler:
--- avrdude: stk500_getsync(): not in sync: resp=0x00 ---
Nun gibt auch hierzu verschiedene Hinweise. Kann mir bitte jemand sagen, was ich bei "overwrite default Port" eintragen muß. Aktuell:
--- avrdude -carduino -PCOM6 -b19200 [...part specific options...] ---
Ich benutze den Arduino Duemilanove mit USB Anschluß und arbeite mit Windows7. Die Configurationen habe ich aus den verschiedenen Tutorials übernommen. Die Hex-Datei von Hello_Blink wurde erstellt. Was mir aber eben erst aufgefallen ist, das auf meinem MC-Bord ATmega328 steht. Dieser wird aber von avrdude nicht unterstützt, deshalb habe ich den ATmega328p gewählt. Ist das ein Problem?
Im Voraus vielen Dank.
Willi

Kucky
26.08.2010, 11:08
Hallo zusammen,
wollte auch mal was positives vermelden. Ich bin durch Ingo von Hotcar auf diesen Link
http://www.chipkin.com/articles/using-eclipse-with-arduino-duemilanove
gestossen. Und siehe da es funktioniert. Wichtig ist bei "Creating a Arduino project" die Notiz bei Punkt 11.2.
Blinky funktioniert. Mein Project selbst macht aber Probleme:
../main.cpp: In function 'void loop()':
../main.cpp:79: error: 'motorR' was not declared in this scope
Hier soll diese Funktion ausgeführt werden;
void motorR (int InputPin2, int InputPin4, int pwm3){
digitalWrite(RMotor1, InputPin2);
digitalWrite(RMotor2, InputPin4);
analogWrite(RSpeed, pwm3);
Weis jemand Rat?
Gruß Kucky

markusj
26.08.2010, 11:52
Du hast offenbar die Headerfiles zur Arduino-Bibliothek nicht eingebunden ... Wo die liegen kann ich dir aber nicht sagen, einbinden kannst du sie aber über die Projektkonfiguration, "C/C++ General", "Paths and Symbols" im Reiter "Includes".
Dann noch wie gewohnt die entsprechenden #include-Anweisungen am Anfang des Quelltextes ...

mfG
Markus

Kucky
26.08.2010, 12:09
Hallo Markus,
danke für die schnelle Antwort. Aber genau hier mache ich die Grätsche :-) .
Meine Bibliothek liegt hier:
"xxxx/ArduinoCore/". Hier sind Files wie "Binary.h oder wiring.h und WProgramm.h". Die letztere habe ich als inklude im Code ganz zu Anfang gesetzt. Ist das falsch? Oder fehlt das was?
Bei Path and Symbols wurde die Pfade automatisch eingetragen.
Gruß Willi

Kucky
27.08.2010, 07:31
Hallo Markus,
habe hier mal den Code gepostet. Vielleicht hilft es.


/

#include <WProgram.h>

const int RMotor1 = 2; // H-bridge leg 3 Input 1 14,4V Motor
const int RMotor2 = 4; // H-bridge leg 2 Input 2
const int RSpeed = 3; // H-bridge leg 7 Enable A (PWM)
const int LMotor1 = 7; // H-bridge leg 13 Input 3 12V Motor
const int LMotor2 = 8; // H-bridge leg 14 Input 4
const int LSpeed = 6; // H-bridge leg 10 Enable B (PWM)

const int ledBlue = 12; // BlueLED left Motor
const int ledRed = 13; // RedLED right Motor

int PinOdoR = 1; // right Pin for IR-Sensor
int PinOdoL = 0; // left Pin for IR-Sensor
// int RSpeed = 120; // is not needed in this Kontex
// int LSpeed = 120;
// int mDirR = 0;
// int mDirL = 0;

// int LedPwmR = 0;
// int LedPwmB = 0;

int readAnalog(int port); // Why are these functions initialized here?
int readOdoR();
int readOdoL();
void blink(int whatPin, int howManyTimes, int milliSecs);
// void motorR (int InputPin2, int InputPin4, int pwm3);
// void motorL (int InputPin7, int InputPin8, int pwm6);
void motorStop();

//-------------------------- Setup ----------------------------------------------------
void setup() {
void motorStop();

pinMode(RMotor1, OUTPUT);
pinMode(RMotor2, OUTPUT);
pinMode(RSpeed, OUTPUT);
pinMode(LMotor1, OUTPUT);
pinMode(LMotor2, OUTPUT);
pinMode(LSpeed, OUTPUT);

pinMode(ledBlue, OUTPUT);
pinMode(ledRed, OUTPUT);

Serial.begin(115200);
// motorStop(); // would be necessary at all?
Serial.println("***********************");
Serial.println("* Encoder-Test *");
Serial.print("* ");Serial.print(__DATE__);Serial.print(" ");Serial.print(__TIME__);Serial.println("*");
Serial.println("***********************");

blink(ledBlue, 3, 1000);
}
//------------------------------------------------------------------------------
void loop() {

int RSpeed = 120;
int LSpeed = 120;
motorR(HIGH,LOW,RSpeed);
motorL(HIGH,LOW,LSpeed);
delay(2000);

Serial.println(" Encoder Rechts/Links ");
for (int i = 0; i <= 52; i++)
{
int valR = readOdoR();
int valL = readOdoL();
Serial.print(" ");Serial.print(valR,DEC);Serial.print(" ;");Serial.print(valL,DEC);Serial.println(" ");
delay (10); // hängt dieser Wert von der Drehzahl des Encoders ab?
if (valR > 400) { digitalWrite(ledRed,HIGH); }
else { digitalWrite(ledRed,LOW); }
if (valL > 400) { digitalWrite(ledBlue,HIGH); }
else { digitalWrite(ledBlue,LOW); }
}
Serial.println(" ");
// motorStop();
Serial.println("***********************");
delay (5000);
}

// -------------------------- Left Motor -----------------------------------------------

void motorR (int InputPin2, int InputPin4, int pwm3){
digitalWrite(RMotor1, InputPin2);
digitalWrite(RMotor2, InputPin4);
analogWrite(RSpeed, pwm3);
}
//-------------------------- Right Motor ----------------------------------------------
void motorL (int InputPin7, int InputPin8, int pwm6){
digitalWrite(LMotor1, InputPin7);
digitalWrite(LMotor2, InputPin8);
analogWrite(LSpeed, pwm6);
}
//-------------------------- Stop Motor ----------------------------------------------
void motorStop (){
motorL(LOW, LOW, 0);
motorR(LOW, LOW, 0);
}
//------------------------------------------------------------------------------
int readOdoR(){
return readAnalog (PinOdoR);
}
//------------------------------------------------------------------------------
int readOdoL(){
return readAnalog (PinOdoL);
}
//------------------------------------------------------------------------------
int readAnalog(int port){
int val = 0;
for (int i = 0; i <= 3; i++)
{ val = val + analogRead(port); }
val = val/3;
return val;
}
//-------------------------- blinks an LED ------------------------------------
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2);
}
}
//------------------------- Programm Ende ---------------------------------------

int main(void) {

/* Must call init for arduino to work properly */
init();
setup();

for (;;) {
loop();
} // end for
} // end main



Ist bestimmt ein typische Anfängercode, aber in der Arduino IDE funktioniert er.
Gruß
Willi

markusj
27.08.2010, 10:57
Hallo Willi,

unwahrscheinlich dass der in der Arduino-IDE in genau dieser Form funktioniert - du hast die Deklaration von motorR() und motorL() auskommentiert, damit kennt der Compiler diese Funktionen in setup() noch nicht weil sie erst danach implementiert wurden.
Grundregel: Alle verwendeten Funktionen müssen vor ihrer Verwendung deklariert worden sein.
Dir bleiben also zwei Möglichkeiten:
1. Du machst die Auskommentierung dieser Zeilen rückgängig und lieferst damit eine Deklaration:
// void motorR (int InputPin2, int InputPin4, int pwm3);
// void motorL (int InputPin7, int InputPin8, int pwm6);
2. Du verschiebst motorL() und motorR() vor setup().

mfG
Markus

Kucky
27.08.2010, 12:52
Hallo Markus,
Du hast natürlich Recht. Die Auskommentierungen waren durch die Versuche gekommen. Hier der org. Arduinocode.



const int RMotor1 = 2; // H-bridge leg 3 Input 1 14,4V Motor
const int RMotor2 = 4; // H-bridge leg 2 Input 2
const int RSpeed = 3; // H-bridge leg 7 Enable A (PWM)
const int LMotor1 = 7; // H-bridge leg 13 Input 3 12V Motor
const int LMotor2 = 8; // H-bridge leg 14 Input 4
const int LSpeed = 6; // H-bridge leg 10 Enable B (PWM)

const int ledBlue = 12; // BlueLED left Motor
const int ledRed = 13; // RedLED right Motor

int PinOdoR = 0; // right Pin for IR-Sensor
int PinOdoL = 1; // left Pin for IR-Sensor
// int mSpeedR = 0; // is not needed in this Kontex ?
// int mSpeedL = 0;
// int mDirR = 0;
// int mDirL = 0;

// int LedPwmR = 0;
// int LedPwmB = 0;

int readAnalog(int port); // Why are these functions initialized here?
int readOdoR ();
int readOdoL ();

//-------------------------- Left Motor -----------------------------------------------
void motorR (int InputPin2, int InputPin4, int pwm3){
digitalWrite(RMotor1, InputPin2);
digitalWrite(RMotor2, InputPin4);
analogWrite(RSpeed, pwm3);
}
//-------------------------- Right Motor ----------------------------------------------
void motorL (int InputPin7, int InputPin8, int pwm6){
digitalWrite(LMotor1, InputPin7);
digitalWrite(LMotor2, InputPin8);
analogWrite(LSpeed, pwm6);
}
//-------------------------- Stop Motor ----------------------------------------------
void motorStop (){
motorL(LOW, LOW, 0);
motorR(LOW, LOW, 0);
}
//-------------------------- Setup ----------------------------------------------------
void setup() {

// set all the other pins you're using as outputs:
pinMode(RMotor1, OUTPUT);
pinMode(RMotor2, OUTPUT);
pinMode(RSpeed, OUTPUT);
pinMode(LMotor1, OUTPUT);
pinMode(LMotor2, OUTPUT);
pinMode(LSpeed, OUTPUT);

pinMode(ledBlue, OUTPUT);
pinMode(ledRed, OUTPUT);

Serial.begin(115200);
// motorStop(); // would be necessary at all?
Serial.println("***********************");
Serial.println("* Encoder-Test *");
Serial.print("* ");Serial.print(__DATE__);Serial.print(" ");Serial.print(__TIME__);Serial.println("*");
Serial.println("***********************");

blink(ledRed, 3, 1000);
}
//------------------------------------------------------------------------------
void loop() {
int RSpeed = 170;
int LSpeed = 150;
motorR(HIGH,LOW,RSpeed);
motorL(HIGH,LOW,LSpeed);
delay(1000);

Serial.println(" Encoder Rechts/Links ");
for (int i = 0; i <= 100; i++)
{
int valR = readOdoR();
int valL = readOdoL();
Serial.print(" ");Serial.print(valR,DEC);Serial.print(" ;");Serial.print(valL,DEC);Serial.println(" ");
delay (15); // hängt dieser Wert von der Drehzahl des Encoders ab?
if (valR > 400) { digitalWrite(ledRed,HIGH); }
else { digitalWrite(ledRed,LOW); }
if (valL > 400) { digitalWrite(ledBlue,HIGH); }
else { digitalWrite(ledBlue,LOW); }
}
Serial.println(" ");
motorStop();
Serial.println("***********************");
delay (5000);
}
//------------------------------------------------------------------------------
int readOdoR (){
return readAnalog (PinOdoR);
}
//------------------------------------------------------------------------------
int readOdoL (){
return readAnalog (PinOdoL);
}
//------------------------------------------------------------------------------
int readAnalog(int port){
int val = 0;
for (int i = 0; i <= 3; i++)
{ val = val + analogRead(port); }
val = val/3;
return val;
}
//-------------------------- blinks an LED ------------------------------------
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2);
}
}
//------------------------- Programm Ende ---------------------------------------



Ich hoffe ich habe Deinen Tipp richtig verstanden.



/************************************************** *************************
*
* File Name: Encoder-Test
* Project : Scheibenbot Kucky 1
*
* Description: Freie Bewegungen im unbekannten Raum
*
* Ver. Date Author Comments
* ------- ---------- ----------------- ------------------------------
* 0.1 12.08.2010 W. Kuckelsberg initial build
*
* Co-Author and helpfull Hand: Stephan Scholz
* Hardware: Arduino Duemillenova
* H-bridge: L298H
* Self test for Encoderdisc
* Informations:
* right planetmotor rotates until ???
* left planetmotor rotates until ???
*/

#include <WProgram.h>

const int RMotor1 = 2; // H-bridge leg 3 Input 1 14,4V Motor
const int RMotor2 = 4; // H-bridge leg 2 Input 2
const int RSpeed = 3; // H-bridge leg 7 Enable A (PWM)
const int LMotor1 = 7; // H-bridge leg 13 Input 3 12V Motor
const int LMotor2 = 8; // H-bridge leg 14 Input 4
const int LSpeed = 6; // H-bridge leg 10 Enable B (PWM)

const int ledBlue = 12; // BlueLED left Motor
const int ledRed = 13; // RedLED right Motor

int PinOdoR = 1; // right Pin for IR-Sensor
int PinOdoL = 0; // left Pin for IR-Sensor
// int RSpeed = 120; // is not needed in this Kontex
// int LSpeed = 120;
// int mDirR = 0;
// int mDirL = 0;

// int LedPwmR = 0;
// int LedPwmB = 0;

int readAnalog(int port); // Why are these functions initialized here?
int readOdoR();
int readOdoL();
void blink(int whatPin, int howManyTimes, int milliSecs);
//void motorR (int InputPin2, int InputPin4, int pwm3);
//void motorL (int InputPin7, int InputPin8, int pwm6);
void motorL ();
void motorR ();
void motorStop();

// -------------------------- Left Motor -----------------------------------------------
void motorR (int InputPin2, int InputPin4, int pwm3){
digitalWrite(RMotor1, InputPin2);
digitalWrite(RMotor2, InputPin4);
analogWrite(RSpeed, pwm3);
}
//-------------------------- Right Motor ----------------------------------------------
void motorL (int InputPin7, int InputPin8, int pwm6){
digitalWrite(LMotor1, InputPin7);
digitalWrite(LMotor2, InputPin8);
analogWrite(LSpeed, pwm6);
}
//-------------------------- Setup ----------------------------------------------------
void setup() {
void motorStop();

pinMode(RMotor1, OUTPUT);
pinMode(RMotor2, OUTPUT);
pinMode(RSpeed, OUTPUT);
pinMode(LMotor1, OUTPUT);
pinMode(LMotor2, OUTPUT);
pinMode(LSpeed, OUTPUT);

pinMode(ledBlue, OUTPUT);
pinMode(ledRed, OUTPUT);

Serial.begin(115200);
// motorStop(); // would be necessary at all?
Serial.println("***********************");
Serial.println("* Encoder-Test *");
Serial.print("* ");Serial.print(__DATE__);Serial.print(" ");Serial.print(__TIME__);Serial.println("*");
Serial.println("***********************");

blink(ledBlue, 3, 1000);
}
//------------------------------------------------------------------------------
void loop() {

int RSpeed = 120;
int LSpeed = 120;
motorR(HIGH,LOW,RSpeed);
motorL(HIGH,LOW,LSpeed);
delay(2000);

Serial.println(" Encoder Rechts/Links ");
for (int i = 0; i <= 52; i++)
{
int valR = readOdoR();
int valL = readOdoL();
Serial.print(" ");Serial.print(valR,DEC);Serial.print(" ;");Serial.print(valL,DEC);Serial.println(" ");
delay (10); // hängt dieser Wert von der Drehzahl des Encoders ab?
if (valR > 400) { digitalWrite(ledRed,HIGH); }
else { digitalWrite(ledRed,LOW); }
if (valL > 400) { digitalWrite(ledBlue,HIGH); }
else { digitalWrite(ledBlue,LOW); }
}
Serial.println(" ");
// motorStop();
Serial.println("***********************");
delay (5000);
}


//-------------------------- Stop Motor ----------------------------------------------
void motorStop (){
motorL(LOW, LOW, 0);
motorR(LOW, LOW, 0);
}
//------------------------------------------------------------------------------
int readOdoR(){
return readAnalog (PinOdoR);
}
//------------------------------------------------------------------------------
int readOdoL(){
return readAnalog (PinOdoL);
}
//------------------------------------------------------------------------------
int readAnalog(int port){
int val = 0;
for (int i = 0; i <= 3; i++)
{ val = val + analogRead(port); }
val = val/3;
return val;
}
//-------------------------- blinks an LED ------------------------------------
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2);
}
}
//------------------------- Programm Ende ---------------------------------------

int main(void) {

/* Must call init for arduino to work properly */
init();
setup();

for (;;) {
loop();
} // end for
} // end main



Nun bekomme ich diese Meldung:
"D:\UserDaten\Users\Willi\Prog\Projekte\ProjEclipse \ArduinoCore\Release\libArduinoCore.a(Print.o):(.d ata+0x6): undefined reference to `__cxa_pure_virtual'
make: *** [Encoder.elf] Error 1"
(der traurige Smilie entstand zwar automatisch, passt aber irgendwie)

Die ArduinoCore ist im Verzeichniss "xxx/ArduionoCore/Release"
Die Dateien mit der Endung *.h sind im Verzeichniss "xxx/ArduionoCore"
Ist das richtig? Wurde automatisch beim erstellen der static Library so hinterlegt. Oder müssen die alle in einem Verzeichniss sein. Um das Problem zu umgehen, habe ich beide Verzeichnisse bei den Projekteinstellungen genannt.
Wäre es für Dich sehr viel Aufwand, meine Code in Eclipse so umzuschreiben, dass ich hier schon mal keinen Fehler habe. =D>
Ich weiss das ist ziemlich unverschämt, wäre Dir aber wirklich sehr dankbar.
Gruß
Willi

markusj
27.08.2010, 17:04
Ich habe keinen Arduino und kann daher nur allgemeine Hilfestellung zu AVR-Eclipse und C geben, und dieses Problem ist sehr C++-Spezifisch.
Welche WinAVR-Version verwendest du? Der letzte Post in diesem (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1244802416) Thread deutet darauf hin dass man ein aktuelles WinAVR braucht, hier (http://www.mikrocontroller.net/topic/68813) wird eine Problemlösung beschrieben von der ich nicht beurteilen kann, wie gefährlich sie ist ...

mfG
Markus

Edit: "keinen" Arduino statt "einen"

Kucky
28.08.2010, 15:02
Hallo Markus,
das mit dem gefährlich sehe ich genauso. Aber ein Link hat mir gezeigt, wie ich Funktionen vor dem SetUp deklarieren muss. Also vielen Dank. Mühsam ernährt sich das Eichhörchen.
Gruß Willi