Weird Serial.println MEGA BUG!...

Hi everyone,

I am dealing with a weird bug related to Serial.println with Arduino MEGA 2560. I have opened this new topic which includes what I've done in the following link.

http://forum.arduino.cc/index.php?topic=143987.msg2689342#msg2689342

Somehow, my MEGA is working fine although I failed many times to upload the bootloader.

I want to share my code and I don't think my problem is not related with this weird bug anymore because I tried a new similar sketch with my code. Thus I realized bootloader upgrade is not necessary. My similar sketch is working fine but my main code is still giving the avrdude error.

This my main code and the next one is similar code which is working fine.

#include <Stepper.h>
#include "IGUS.h"

//Stepper IGUS(1, STEPPER_STEP_PIN, STEPPER_DIR_PIN);
Stepper IGUS_1(STEPS_1, STEPPER_1_STEP_PIN, STEPPER_1_DIR_PIN);
Stepper IGUS_2(STEPS_2, STEPPER_2_STEP_PIN, STEPPER_2_DIR_PIN);
Stepper IGUS_3(STEPS_3, STEPPER_3_STEP_PIN, STEPPER_3_DIR_PIN);
Stepper IGUS_4(STEPS_4, STEPPER_4_STEP_PIN, STEPPER_4_DIR_PIN);
Stepper IGUS_5(STEPS_5, STEPPER_5_STEP_PIN, STEPPER_5_DIR_PIN);

int XVal = 0;
int YVal = 0;
int ZVal = 0;
int X_prev = 0;
int Y_prev = 0;
int Z_prev = 0;

void setup() {
  Serial.begin(57600);
  pinMode(ledPin, OUTPUT);
  pinMode(IGUS_1_Hall, INPUT);
  pinMode(IGUS_1_Encoder_Index, INPUT);
  pinMode(IGUS_1_Encoder_A, INPUT);
  pinMode(IGUS_1_Encoder_B, INPUT);
  pinMode(IGUS_2_Hall, INPUT);
  pinMode(IGUS_2_Encoder_Index, INPUT);
  pinMode(IGUS_2_Encoder_A, INPUT);
  pinMode(IGUS_2_Encoder_B, INPUT);
  pinMode(IGUS_3_Hall, INPUT);
  pinMode(IGUS_3_Encoder_Index, INPUT);
  pinMode(IGUS_3_Encoder_A, INPUT);
  pinMode(IGUS_3_Encoder_B, INPUT);
  pinMode(IGUS_4_Hall, INPUT);
  pinMode(IGUS_4_Encoder_Index, INPUT);
  pinMode(IGUS_4_Encoder_A, INPUT);
  pinMode(IGUS_4_Encoder_B, INPUT);
  pinMode(IGUS_5_Hall, INPUT);
  pinMode(IGUS_5_Encoder_Index, INPUT);
  pinMode(IGUS_5_Encoder_A, INPUT);
  pinMode(IGUS_5_Encoder_B, INPUT);
  // set the speed of the motors
  IGUS_1.setSpeed(90);
  IGUS_2.setSpeed(90);
  IGUS_3.setSpeed(90);
  IGUS_4.setSpeed(90);
  IGUS_5.setSpeed(90);
}

void loop() {
  XVal = analogRead(XAxis);
  YVal = analogRead(YAxis);
  ZVal = analogRead(ZAxis);

  int i1_hall = digitalRead(IGUS_1_Hall);

  if (i1_hall == LOW){
    Serial.println("HALL OK!!!");
    digitalWrite(ledPin,HIGH);
  }
  else{
    Serial.println("NO HALL!!!");
    digitalWrite(ledPin,LOW);
  }
}

What is the differences? I have tried to copy the structure of my main code but I dont understand.

#define BRK 12
int a = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(57600);
  pinMode(53,OUTPUT);
  pinMode(BRK,INPUT);

}

void loop() {
  digitalWrite(53,HIGH);
  delay(300);
  digitalWrite(53,LOW);
  delay(300);
  a++;
  int BRKState = digitalRead(BRK);
  if (BRKState == LOW){
    Serial.println("BURAK SUNAN");
  }
  else{
    Serial.println("SUNAN BURAK");
  }
}

Looking forward to your help!!!
P.S. My main code is working perfectly on UNO.

"HALL OK!!!"

Sending three exclamation marks in a row is a signal to the bootloader to start a reboot.
Not a mega bug in anything but a known "feature".

Pete

I am laughing to myself. Thank you so much!!!...

Burak