difference between arduino uno and mega

i use mindwave mobile with HC-05 when wrote code on mega " no response " ... when wrote it on uno or nano it response !!

Take a hard look at line 119. Oh wait...you didn't post your code.

is a general question .. i think the code not importa if the there's no difference between them

Well, the general differences are:

They have different names.
One weighs more
One costs less
Some of the pins do different things
The compiler knows the difference and it works very hard to make all programs work on all boards but it can't do everything for you.

i ask about the difference in code
meanly if write code in arduino uno .. can i use the same code in arduino mega

this code work only with nano and uno not mega

Which code ?

The two arduinos have a few differences that will affect whether the same code will work on both units.

Differences in the number of I/O, serial ports, memory, flash and bootloaders top the list.

Unless your code is top secret, it is probably best to post it as requested if you want any help. The experienced guys here will soon sort out what is relevant and what is not. Sometimes there is something that you may not think as important in the code that is stopping it working. The result is a lot of posts backwards and forwards using up peoples time when the mistake could have been dealt with in one post if the code had been posted in the first place.

this code work on arduino nano and uno but not work on mega
when open serial monitor in nano it is show all data
but in mega not show any thing

#define LED 13
#define BAUDRATE 57600
#define DEBUGOUTPUT 0

#define GREENLED1 3
#define GREENLED2 4
#define GREENLED3 5
#define YELLOWLED1 6
#define YELLOWLED2 7
#define YELLOWLED3 8
#define YELLOWLED4 9
#define REDLED1 10
#define REDLED2 11
#define REDLED3 12

#define powercontrol 10

// checksum variables
byte generatedChecksum = 0;
byte checksum = 0;
int payloadLength = 0;
byte payloadData[64] = {
0};
byte poorQuality = 0;
byte attention = 0;
byte meditation = 0;

// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;

//////////////////////////
// Microprocessor Setup //
//////////////////////////
void setup() {

pinMode(GREENLED1, OUTPUT);
pinMode(GREENLED2, OUTPUT);
pinMode(GREENLED3, OUTPUT);
pinMode(YELLOWLED1, OUTPUT);
pinMode(YELLOWLED2, OUTPUT);
pinMode(YELLOWLED3, OUTPUT);
pinMode(YELLOWLED4, OUTPUT);
pinMode(REDLED1, OUTPUT);
pinMode(REDLED2, OUTPUT);
pinMode(REDLED3, OUTPUT);

pinMode(LED, OUTPUT);
Serial.begin(BAUDRATE); // USB

}

////////////////////////////////
// Read data from Serial UART //
////////////////////////////////
byte ReadOneByte() {
int ByteRead;

while(!Serial.available());
ByteRead = Serial.read();

#if DEBUGOUTPUT
Serial.print((char)ByteRead); // echo the same byte out the USB serial (for debug purposes)
#endif

return ByteRead;
}

/////////////
//MAIN LOOP//
/////////////
void loop() {

// Look for sync bytes
if(ReadOneByte() == 170) {
if(ReadOneByte() == 170) {

payloadLength = ReadOneByte();
if(payloadLength > 169) //Payload length can not be greater than 169
return;

generatedChecksum = 0;
for(int i = 0; i < payloadLength; i++) {
payloadData = ReadOneByte(); //Read payload into memory
_ generatedChecksum += payloadData*;_
_
} _
_
checksum = ReadOneByte(); //Read checksum byte from stream _
_
generatedChecksum = 255 - generatedChecksum; //Take one's compliment of generated checksum*_
* if(checksum == generatedChecksum) { *
* poorQuality = 200;*
* attention = 0;*
* meditation = 0;*
* for(int i = 0; i < payloadLength; i++) { // Parse the payload*
_ switch (payloadData*) {
case 2:
i++;
poorQuality = payloadData;
bigPacket = true;
break;
case 4:
i++;
attention = payloadData;
break;
case 5:
i++;
meditation = payloadData;
break;
case 0x80:
i = i + 3;
break;
case 0x83:
i = i + 25;
break;
default:
break;
} // switch*

* } // for loop*
#if !DEBUGOUTPUT
// *** Add your code here
if(bigPacket) {

if(poorQuality == 0)
digitalWrite(LED, HIGH);
else*

* digitalWrite(LED, LOW);
Serial.print("PoorQuality: ");
Serial.print(poorQuality, DEC);
Serial.print(" Attention: ");
Serial.print(attention, DEC);
Serial.print(" Time since last packet: ");
Serial.print(millis() - lastReceivedPacket, DEC);
lastReceivedPacket = millis();
Serial.print("\n");
switch(attention / 10) {
case 0:
digitalWrite(GREENLED1, HIGH);
digitalWrite(GREENLED2, LOW);
digitalWrite(GREENLED3, LOW);
digitalWrite(YELLOWLED1, LOW);
digitalWrite(YELLOWLED2, LOW);
digitalWrite(YELLOWLED3, LOW);
digitalWrite(YELLOWLED4, LOW);
digitalWrite(REDLED1, LOW);
digitalWrite(REDLED2, LOW);
digitalWrite(REDLED3, LOW);
break;
case 1:
digitalWrite(GREENLED1, HIGH);
digitalWrite(GREENLED2, HIGH);
digitalWrite(GREENLED3, LOW);
digitalWrite(YELLOWLED1, LOW);
digitalWrite(YELLOWLED2, LOW);
digitalWrite(YELLOWLED3, LOW);
digitalWrite(YELLOWLED4, LOW);
digitalWrite(REDLED1, LOW);
digitalWrite(REDLED2, LOW);
digitalWrite(REDLED3, LOW);
break;*_

* } *
* }*
*#endif *
* bigPacket = false; *
* }*
* else {*
* // Checksum Error*
* } // end if else for checksum*
* } // end if read 0xAA byte*
} // end if read 0xAA byte
}

Please use [ code ] tags. The forum software has eaten some of your code because it thinks you wanted to make the text italic with [ i ].

this code work on arduino nano and uno but not work on mega
when open serial monitor in nano it is show all data
but in mega not show any thing

#define LED 13
#define BAUDRATE 57600
#define DEBUGOUTPUT 0

#define GREENLED1  3
#define GREENLED2  4
#define GREENLED3  5
#define YELLOWLED1 6
#define YELLOWLED2 7
#define YELLOWLED3 8
#define YELLOWLED4 9
#define REDLED1    10
#define REDLED2    11
#define REDLED3    12

#define powercontrol 10

// checksum variables
byte generatedChecksum = 0;
byte checksum = 0; 
int payloadLength = 0;
byte payloadData[64] = {
  0};
byte poorQuality = 0;
byte attention = 0;
byte meditation = 0;

// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;

//////////////////////////
// Microprocessor Setup //
//////////////////////////
void setup() {

  pinMode(GREENLED1, OUTPUT);
  pinMode(GREENLED2, OUTPUT);
  pinMode(GREENLED3, OUTPUT);
  pinMode(YELLOWLED1, OUTPUT);
  pinMode(YELLOWLED2, OUTPUT);
  pinMode(YELLOWLED3, OUTPUT);
  pinMode(YELLOWLED4, OUTPUT);
  pinMode(REDLED1, OUTPUT);
  pinMode(REDLED2, OUTPUT);
  pinMode(REDLED3, OUTPUT);

  pinMode(LED, OUTPUT);
  Serial.begin(BAUDRATE);           // USB

}

////////////////////////////////
// Read data from Serial UART //
////////////////////////////////
byte ReadOneByte() {
  int ByteRead;

  while(!Serial.available());
  ByteRead = Serial.read();

#if DEBUGOUTPUT  
  Serial.print((char)ByteRead);   // echo the same byte out the USB serial (for debug purposes)
#endif

  return ByteRead;
}

/////////////
//MAIN LOOP//
/////////////
void loop() {


  // Look for sync bytes
  if(ReadOneByte() == 170) {
    if(ReadOneByte() == 170) {

      payloadLength = ReadOneByte();
      if(payloadLength > 169)                      //Payload length can not be greater than 169
          return;

      generatedChecksum = 0;        
      for(int i = 0; i < payloadLength; i++) {  
        payloadData[i] = ReadOneByte();            //Read payload into memory
        generatedChecksum += payloadData[i];
      }   

      checksum = ReadOneByte();                      //Read checksum byte from stream      
      generatedChecksum = 255 - generatedChecksum;   //Take one's compliment of generated checksum

        if(checksum == generatedChecksum) {    

        poorQuality = 200;
        attention = 0;
        meditation = 0;

        for(int i = 0; i < payloadLength; i++) {    // Parse the payload
          switch (payloadData[i]) {
          case 2:
            i++;            
            poorQuality = payloadData[i];
            bigPacket = true;            
            break;
          case 4:
            i++;
            attention = payloadData[i];                        
            break;
          case 5:
            i++;
            meditation = payloadData[i];
            break;
          case 0x80:
            i = i + 3;
            break;
          case 0x83:
            i = i + 25;      
            break;
          default:
            break;
          } // switch
        } // for loop

#if !DEBUGOUTPUT
        if(bigPacket) {
          if(poorQuality == 0)
            digitalWrite(LED, HIGH);
          else
            digitalWrite(LED, LOW);
          Serial.print("PoorQuality: ");
          Serial.print(poorQuality, DEC);
          Serial.print(" Attention: ");
          Serial.print(attention, DEC);
          Serial.print(" Time since last packet: ");
          Serial.print(millis() - lastReceivedPacket, DEC);
          lastReceivedPacket = millis();
          Serial.print("\n");

          switch(attention / 10) {
          case 0:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, LOW);
            digitalWrite(GREENLED3, LOW);
            digitalWrite(YELLOWLED1, LOW);
            digitalWrite(YELLOWLED2, LOW);
            digitalWrite(YELLOWLED3, LOW);
            digitalWrite(YELLOWLED4, LOW);
            digitalWrite(REDLED1, LOW);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);           
            break;
          case 1:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, LOW);
            digitalWrite(YELLOWLED1, LOW);
            digitalWrite(YELLOWLED2, LOW);
            digitalWrite(YELLOWLED3, LOW);
            digitalWrite(YELLOWLED4, LOW);
            digitalWrite(REDLED1, LOW);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);
            break;
          case 2:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);
            digitalWrite(YELLOWLED1, LOW);
            digitalWrite(YELLOWLED2, LOW);
            digitalWrite(YELLOWLED3, LOW);
            digitalWrite(YELLOWLED4, LOW);
            digitalWrite(REDLED1, LOW);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);
            break;
          case 3:              
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);              
            digitalWrite(YELLOWLED1, HIGH);
            digitalWrite(YELLOWLED2, LOW);
            digitalWrite(YELLOWLED3, LOW);
            digitalWrite(YELLOWLED4, LOW);
            digitalWrite(REDLED1, LOW);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);             
            break;
          case 4:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);              
            digitalWrite(YELLOWLED1, HIGH);
            digitalWrite(YELLOWLED2, HIGH);
            digitalWrite(YELLOWLED3, LOW);
            digitalWrite(YELLOWLED4, LOW);
            digitalWrite(REDLED1, LOW);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);              
            break;
          case 5:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);              
            digitalWrite(YELLOWLED1, HIGH);
            digitalWrite(YELLOWLED2, HIGH);
            digitalWrite(YELLOWLED3, HIGH);
            digitalWrite(YELLOWLED4, LOW);
            digitalWrite(REDLED1, LOW);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);               
            break;
          case 6:              
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);              
            digitalWrite(YELLOWLED1, HIGH);
            digitalWrite(YELLOWLED2, HIGH);
            digitalWrite(YELLOWLED3, HIGH);
            digitalWrite(YELLOWLED4, HIGH);
            digitalWrite(REDLED1, LOW);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);              
            break;
          case 7:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);              
            digitalWrite(YELLOWLED1, HIGH);
            digitalWrite(YELLOWLED2, HIGH);
            digitalWrite(YELLOWLED3, HIGH);
            digitalWrite(YELLOWLED4, HIGH);
            digitalWrite(REDLED1, HIGH);
            digitalWrite(REDLED2, LOW);
            digitalWrite(REDLED3, LOW);              
            break;    
          case 8:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);              
            digitalWrite(YELLOWLED1, HIGH);
            digitalWrite(YELLOWLED2, HIGH);
            digitalWrite(YELLOWLED3, HIGH);
            digitalWrite(YELLOWLED4, HIGH);
            digitalWrite(REDLED1, HIGH);
            digitalWrite(REDLED2, HIGH);
            digitalWrite(REDLED3, LOW);
            break;
          case 9:
            digitalWrite(GREENLED1, HIGH);
            digitalWrite(GREENLED2, HIGH);
            digitalWrite(GREENLED3, HIGH);              
            digitalWrite(YELLOWLED1, HIGH);
            digitalWrite(YELLOWLED2, HIGH);
            digitalWrite(YELLOWLED3, HIGH);
            digitalWrite(YELLOWLED4, HIGH);
            digitalWrite(REDLED1, HIGH);
            digitalWrite(REDLED2, HIGH); 
            digitalWrite(REDLED3, HIGH);
            break;
          
          }                     
        }
#endif        
        bigPacket = false;        
      }
      else {
        // Checksum Error
      }  // end if else for checksum
    } // end if read 0xAA byte
  } // end if read 0xAA byte
}
while(!Serial.available());
  ByteRead = Serial.read();

Is this part right? Thats a ; after the while. Wouldn't this cycle infinitely if Serial has available data?

No, it waits indefinitely until data arrives. Then not-available is false and it exits the while. (The original indenting was correct.)

I always put something like Serial.println("Starting!"); in my setup(), just after Serial.begin(). This way I know that I've plugged into the correct serial port and it is communicating, even if there's an error further down in my code. Yahia, can you add this and let us know if this works? That will rule out some simple problems.

  int ByteRead;
  ...
  ByteRead = Serial.read();
  ...
  Serial.print((char)ByteRead);

Don't create an int called "byte". If it's a byte, then declare it as a byte. You can get odd things happening when you do these conversions. If it's a char, then declare it as a char and you don't need to use cast expressions everywhere.

Does this debug output work? Can you see that you have two-way communication? (Rules out some more simple problems.)

I think the conversion to int may be the real problem here. As I found out recently, mixing signed and unsigned variables causes some really unexpected problems. For those who don't want to read that whole thread, here's the gist of it:

 char c = 0xE7;
  if(c == 0xE7) Serial.println("True"); else Serial.println("False");

This prints false!

The reason is that putting a number larger than 128 into a char overflows the char into negative numbers. 0xE7 is 231 in decimal and -25 does not equal 231.

This example seems similar, as you're looking for the decimal value 170 in a variable that's been through several conversions from char to int and byte.

but this code work with me when use arduino nano and uno and give me the output in serial port
but when use mega no output in serial port

I don't see how integer conversion could be the problem since it works on uno/nano....

We need to find things that are different between mega and Uno.

Does it work... with a different baud rate... by any chance? some old versions of the firmware on the 16u2 (or 8u2) serial converter for the mega don't work at that specific baud rate...

as u see in the code the baudrate = 57600 cant change it to can read the mind wave

OK, I went and got a brand-new Mega out of its box and tested it. It functions exactly the same as the Uno I tested.

To diagnose this further, I need more information than "it doesn't work!" I've added some debug prints to the code below so I can get more information about which part is and isn't working. Since I don't have an example of the not-specified thing this connects to, I've only been copy-pasting the codes into the serial monitor but I can get it to report the checksum and do the big-packet thing that the original code does.

#define LED 13
#define BAUDRATE 57600
#define DEBUGOUTPUT 0

#define GREENLED1  3
#define GREENLED2  4
#define GREENLED3  5
#define YELLOWLED1 6
#define YELLOWLED2 7
#define YELLOWLED3 8
#define YELLOWLED4 9
#define REDLED1    10
#define REDLED2    11
#define REDLED3    12

#define powercontrol 10

// checksum variables
byte generatedChecksum = 0;
byte checksum = 0;
int payloadLength = 0;
byte payloadData[64] = {
  0
};
byte poorQuality = 0;
byte attention = 0;
byte meditation = 0;

// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;


void setup() {

  pinMode(GREENLED1, OUTPUT);
  pinMode(GREENLED2, OUTPUT);
  pinMode(GREENLED3, OUTPUT);
  pinMode(YELLOWLED1, OUTPUT);
  pinMode(YELLOWLED2, OUTPUT);
  pinMode(YELLOWLED3, OUTPUT);
  pinMode(YELLOWLED4, OUTPUT);
  pinMode(REDLED1, OUTPUT);
  pinMode(REDLED2, OUTPUT);
  pinMode(REDLED3, OUTPUT);

  pinMode(LED, OUTPUT);
  Serial.begin(BAUDRATE);           // USB
  Serial.println("Starting!");
  Serial.print("Example valid string (cut and paste into the serial monitor):");
  Serial.write((char)170);
  Serial.write((char)170);
  Serial.write((char)2); //payload size
  Serial.write((char)2); //if first payload is 2, then 'big packet' will be set and it uses the next char for the poorQuality variable
  Serial.write((char)5); //poor quality
  Serial.write((char(255 - 2 - 5)); //construct checksum manually


}

byte ReadOneByte() {
  int ByteRead;

  while (!Serial.available());
  ByteRead = Serial.read();

#if DEBUGOUTPUT
  Serial.print((char)ByteRead);   // echo the same byte out the USB serial (for debug purposes)
#endif

  return ByteRead;
}


void loop() {


  // Look for sync bytes
  if (ReadOneByte() == 170) {
    if (ReadOneByte() == 170) {

      payloadLength = ReadOneByte();
      if (payloadLength > 169)                     //Payload length can not be greater than 169
        return;

      generatedChecksum = 0;
      for (int i = 0; i < payloadLength; i++) {
        payloadData[i] = ReadOneByte();            //Read payload into memory
        generatedChecksum += payloadData[i];
      }

      checksum = ReadOneByte();                      //Read checksum byte from stream
      generatedChecksum = 255 - generatedChecksum;   //Take one's compliment of generated checksum

      if (checksum == generatedChecksum) {
        Serial.println("Checksum OK!");

        poorQuality = 200;
        attention = 0;
        meditation = 0;

        for (int i = 0; i < payloadLength; i++) {   // Parse the payload
          switch (payloadData[i]) {
            case 2:
              i++;
              poorQuality = payloadData[i];
              bigPacket = true;
              break;
            case 4:
              i++;
              attention = payloadData[i];
              break;
            case 5:
              i++;
              meditation = payloadData[i];
              break;
            case 0x80:
              i = i + 3;
              break;
            case 0x83:
              i = i + 25;
              break;
            default:
              break;
          } // switch
        } // for loop

#if !DEBUGOUTPUT
        if (bigPacket) {
          if (poorQuality == 0)
            digitalWrite(LED, HIGH);
          else
            digitalWrite(LED, LOW);
          Serial.print("PoorQuality: ");
          Serial.print(poorQuality, DEC);
          Serial.print(" Attention: ");
          Serial.print(attention, DEC);
          Serial.print(" Time since last packet: ");
          Serial.print(millis() - lastReceivedPacket, DEC);
          lastReceivedPacket = millis();
          Serial.print("\n");

          switch (attention / 10) {
            case 0:
              digitalWrite(GREENLED1, HIGH);
              digitalWrite(GREENLED2, LOW);
              digitalWrite(GREENLED3, LOW);
              digitalWrite(YELLOWLED1, LOW);
              digitalWrite(YELLOWLED2, LOW);
              digitalWrite(YELLOWLED3, LOW);
              digitalWrite(YELLOWLED4, LOW);
              digitalWrite(REDLED1, LOW);
              digitalWrite(REDLED2, LOW);
              digitalWrite(REDLED3, LOW);
              break;
            case 1:
              digitalWrite(GREENLED1, HIGH);
              digitalWrite(GREENLED2, HIGH);
              digitalWrite(GREENLED3, LOW);
              digitalWrite(YELLOWLED1, LOW);
              digitalWrite(YELLOWLED2, LOW);
              digitalWrite(YELLOWLED3, LOW);
              digitalWrite(YELLOWLED4, LOW);
              digitalWrite(REDLED1, LOW);
              digitalWrite(REDLED2, LOW);
              digitalWrite(REDLED3, LOW);
              break;
            case 2:
              digitalWrite(GREENLED1, HIGH);
              digitalWrite(GREENLED2, HIGH);
              digitalWrite(GREENLED3, HIGH);
              digitalWrite(YELLOWLED1, LOW);
              digitalWrite(YELLOWLED2, LOW);
              digitalWrite(YELLOWLED3, LOW);
              digitalWrite(YELLOWLED4, LOW);
              digitalWrite(REDLED1, LOW);
              digitalWrite(REDLED2, LOW);
              digitalWrite(REDLED3, LOW);
              break;
            case 3:
              digitalWrite(GREENLED1, HIGH);
              digitalWrite(GREENLED2, HIGH);
              digitalWrite(GREENLED3, HIGH);
              digitalWrite(YELLOWLED1, HIGH);
              digitalWrite(YELLOWLED2, LOW);
              digitalWrite(YELLOWLED3, LOW);
              digitalWrite(YELLOWLED4, LOW);
              digitalWrite(REDLED1, LOW);
              digitalWrite(REDLED2, LOW);
              digitalWrite(REDLED3, LOW);
              break;
            case 4:
              digitalWrite(GREENLED1, HIGH);
              digitalWrite(GREENLED2, HIGH);
              digitalWrite(GREENLED3, HIGH);
              digitalWrite(YELLOWLED1, HIGH);
              digitalWrite(YELLOWLED2, HIGH);
              digitalWrite(YELLOWLED3, LOW);
              digitalWrite(YELLOWLED4, LOW);
              digitalWrite(REDLED1, LOW);
              digitalWrite(REDLED2, LOW);
              digitalWrite(REDLED3, LOW);
              break;
            case 5:
              digitalWrite(GREENLED1, HIGH);
              digitalWrite(GREENLED2, HIGH);
              digitalWrite(GREENLED3, HIGH);
              digitalWrite(YELLOWLED1, HIGH);
              digitalWrite(YELLOWLED2, HIGH);
              digitalWrite(YELLOWLED3, HIGH);
              digitalWrite(YELLOWLED4, LOW);
              digitalWrite(REDLED1, LOW);
              digitalWrite(REDLED2, LOW);
              digitalWrite(REDLED3, LOW);
              break;
            case 6:
              digitalWrite(GREENLED1, HIGH);
              digitalWrite(GREENLED2, HIGH);
              digitalWrite(GREENLED3, HIGH);
              digitalWrite(YELLOWLED1, HIGH);
              digitalWrite(YELLOWLED2, HIGH);
              digitalWrite(YELLOWLED3, HIGH);
              digitalWrite(YELLOWLED4, HIGH);
              digitalWrite(REDLED1, LOW);
              digitalWrite(REDLED2, LOW);
              digitalWrite(REDLED3, LOW);
              break;
            case 7:
              //deleted due to forum character count limie
              break;
            case 8:
              //deleted due to forum character count limie
              break;
            case 9:
              //deleted due to forum character count limie
              break;

          }
        }
#endif
        bigPacket = false;
      }
      else {
        // Checksum Error
        Serial.println("Fail Checksm");
      }  // end if else for checksum
    } // end if read 0xAA byte
  } // end if read 0xAA byte
}

ok ... i said there is no error in the code .. just when use this code in arduino nano or uno it work meanly it gives output in serial monitor like :
PoorQuality: 0 Attention:0 Time since last packet: 300
....
.....
...
all change with time

but when use arduino mega and upload this code " same code that uploaded in uno and nano " the serial monitor give nothing mean no out in serial monitor

That's probably because you have connected the Mega incorrectly somehow.

Write another sketch and see if it runs on the Mega.

Where are these serial char 170's supposed to be coming from ? The PC using serial monitor and USB ? Or somewhere else ?

Make sure you didn't connect the wires to the Mega's "Serial1" inputs. The Mega has 4 serial ports, they are called Serial, Serial1, Serial2, and Serial3.

If you want to call it "Serial" inside the sketch, you need to connect it to "Serial" on the board, which is pins 0 and 1.