Go Down

Topic: error: avrdude: stk500v2_ReceiveMessage(): timeout (Read 985 times) previous topic - next topic

Loren

I receive the error listed above when I attempt to upload a sketch with a couple of libraries that I have written.  I can up load other sketches successfully.  Originally I thought that it was a corrupt library file so I retyped everything into a new sketch (including the libraries).

I'm happy to post any other information that might be helpful. 


Thoughts?  Suggestions?


Loren

PS if I have posted in the wrong place feel free to move my post.

PaulS

You posted in the Programming section. That means you need to post your code, too.

Loren

Ok

Sketch:

Code: [Select]
#include "Midi.h"
#include "Card.h"
//#include "eht.h"
#include "SD.h"
#include "SPI.h"
#include "Ethernet.h"


Midi midi;
Card card;
//Eth eth;

void setup(){
  Serial.begin(9600);
  Serial1.begin(31250);
  Serial2.begin(9600);
  Serial.println("Setup has begun");
  midi.init();
  card.init();
 
  //eth.init();
  midi.blinky();
 
}

void loop(){
midi.rxComm();
}


Card.h:
Code: [Select]
#ifndef Card_h
#define Card_h

#include "Arduino.h"
#include <SD.h>


class Card{


public:
void init();
void midiCommand(int stuff);


private:
int CS_pin;
File myFile;
SdFile root;
SdVolume volume;
boolean cardReady;

//midi command variables
int n;
char d;
char c;
char LineFromFile[255];
int stuff;
int junk;

};


#endif


Card source:
Code: [Select]
#include "Arduino.h"
#include "Card.h"

void Card::init(){
CS_pin = 4;
pinMode(CS_pin, OUTPUT);
if(!SD.begin(CS_pin)){
  Serial.println("Card Failed");
  return;
}
Serial.println("Card Ready");
cardReady = true;
}

void Card::midiCommand(int stuff){
Serial.println("midi command called");
  n = 0;
myFile = SD.open("midiComm.csv");
Serial.println("File should be open");
while (myFile.available()){
 
   c = myFile.read();
     if (c != '\n'){
      LineFromFile[n] = c;
     n++;
    int xyz;
     for (xyz = 0; xyz < n; xyz++){
        if (LineFromFile[xyz] != ','){
          junk += LineFromFile[xyz];
          Serial.print(LineFromFile[xyz]);
          if(junk == stuff){
             Serial.println("GOOOD!!!!  ");
          }
        }else{
          Serial.print(" ");
        }   
     }
     }else{
       Serial.println(" ");
}
n = 0;
 
}

}


Midi.h:
Code: [Select]
#ifndef Midi_h
#define Midi_h

#include "Arduino.h"

class Midi{
 
public:
void init();
void blinky();
void rxComm();

private:
#define STAT1 7
#define STAT2 6

};

#endif


Midi source:

Code: [Select]
#include "Arduino.h"
#include "Midi.h"
#include "Card.h"

void Midi::init(){
pinMode(STAT1,OUTPUT);
pinMode(STAT2,OUTPUT);

}

void Midi::blinky(){
for(int i = 0; i < 10; i++){
  digitalWrite(STAT1,HIGH);
  digitalWrite(STAT2,LOW);
  delay(30);
  digitalWrite(STAT1,LOW);
  digitalWrite(STAT2,HIGH);
  delay(30);
}
digitalWrite(STAT1,HIGH);
digitalWrite(STAT2,HIGH);
}

void Midi::rxComm(){
  Card card;
  if (Serial1.available()){
   Serial.print("MIDI:  ");
    digitalWrite(STAT2,LOW);
   int inByte = Serial1.read();
    Serial.println(inByte);
   Serial1.flush();
  delay(10);
digitalWrite(STAT2,HIGH);

  if(inByte > 191){
   if (inByte <208){
     card.midiCommand(inByte);
  }
  }
}
}

PaulS

Code: [Select]
   Serial1.flush();
Why? Why do you need to block until all serial data has been sent, on a port you only read from?

Why is n a field of the Card class. It is only used in one method. It should be local to that method.

Are the records on the SD card really 255 characters?

Which Arduino are you trying to upload this to? A 328-based Arduino only has 2k or SRAM. The SD class uses more than 1/4 of that. The Card class is using 1/8 of the memory just for the LineFromFile array.

Loren


Code: [Select]
   Serial1.flush();
Why? Why do you need to block until all serial data has been sent, on a port you only read from?


You are right.  That line is gone.


Why is n a field of the Card class. It is only used in one method. It should be local to that method.

Moved to method.


Are the records on the SD card really 255 characters?

No but close to 100 so I've reduced the size of that char to 100


Which Arduino are you trying to upload this to? A 328-based Arduino only has 2k or SRAM. The SD class uses more than 1/4 of that. The Card class is using 1/8 of the memory just for the LineFromFile array.


I'm using a mega 2560.

You bring up some really good points that I need to learn more about.  After the couple of tweaks listed above I'm still having the same problem.   I'll look into memory usage a little later today. 

If this truely is a memory problem why would it lock up on upload when my sketch is only 18,000 bytes of an available 250,000?

Thanks again,

Loren 

PaulS

Quote
If this truely is a memory problem why would it lock up on upload when my sketch is only 18,000 bytes of an available 250,000?

The Arduino has three types of memory - Flash, where your program goes (that 250,000+ value), SRAM, where variables go (8K), and EEPROM. The amount of code space you are using has no correlation with the amount of SRAM you are using.

I'll try loading your code on my Mega later, to see what happens.

Loren

It seemed to me that the last statement could get memory intensive so I modified Midi and Card  like this:

Midi:

Code: [Select]
#include "Arduino.h"
#include "Midi.h"
#include "Card.h"

void Midi::init(){
pinMode(STAT1,OUTPUT);
pinMode(STAT2,OUTPUT);

}

void Midi::blinky(){
for(int i = 0; i < 10; i++){
  digitalWrite(STAT1,HIGH);
  digitalWrite(STAT2,LOW);
  delay(30);
  digitalWrite(STAT1,LOW);
  digitalWrite(STAT2,HIGH);
  delay(30);
}
digitalWrite(STAT1,HIGH);
digitalWrite(STAT2,HIGH);
}

void Midi::rxComm(){
  Card card;
  if (Serial1.available()){
   Serial.print("MIDI:  ");
    digitalWrite(STAT2,LOW);
   int inByte = Serial1.read();
    Serial.println(inByte);
  delay(10);
digitalWrite(STAT2,HIGH);

  if(inByte > 191){
   if (inByte <208){
     //card.midiCommand(inByte);
  }
  }
}
}


Card:
Code: [Select]
#include "Arduino.h"
#include "Card.h"

void Card::init(){
CS_pin = 4;
pinMode(CS_pin, OUTPUT);
if(!SD.begin(CS_pin)){
  Serial.println("Card Failed");
  return;
}
Serial.println("Card Ready");
cardReady = true;
}

void Card::midiCommand(int stuff){
/*Serial.println("midi command called");
  int n = 0;
myFile = SD.open("midiComm.csv");
Serial.println("File should be open");
while (myFile.available()){
 
   c = myFile.read();
     if (c != '\n'){
      LineFromFile[n] = c;
     n++;
    int xyz;
     for (xyz = 0; xyz < n; xyz++){
        if (LineFromFile[xyz] != ','){
          junk += LineFromFile[xyz];
          Serial.print(LineFromFile[xyz]);
          if(junk == stuff){
             Serial.println("GOOOD!!!!  ");
          }
        }else{
          Serial.print(" ");
        }   
     }
     }else{
       Serial.println(" ");
}
n = 0;
 
}*/

}


I basically eliminated the midiCommand method from card. 

So it seems like I should use a computer to do all of the table lookup tasks of this since they seem to be really memory intensive.  Does that seem like a good idea?  I'll also kick around playing with monitoring the memory situation.

Thanks,

Loren

PaulS

It is really
                      difficult to
       read your code
                    when it dances all
        over the place.

The Tools + Auto Format menu item needs to be used BEFORE you post code.

Go Up