Serial1.write shows in console

Hi,

I have a problem since i've uploaded my code with the new 1.0 IDE to my mega 2560 Controller.

I've connected the Serial1 to the sparkfun XBee Shield so i can transfer my commands to all XBee Radios and still habe the Serial Console for debugging.

The code (http://code.google.com/p/techgarden/source/browse/controller_mega/controller_mega.ino) worked fine till I uploaded it through the new IDE.

Before uploading the sketch all commands went to the XBee-Shield, now all the commands are shown in my Serial.console....

The part where all the data should get transfered is:

byte xtrans(byte value){
  if (debug == true){
    Serial1.print(value);
  }
  else{
    Serial.write(value); //Debug-Option
  }
  delay(10);
  return value;
}

I also tried the following: - Commented out the debugging Option to make sure - Change Serial1.print to Serial1.write

Like I said above - the code worked perfectly with the older IDE - a few minutes ago...

Can somebody please help me... thanks a lot in advance...

Bjoern

Can somebody please help me...

Without seeing all of your code? No.

What do you expect this coder to do?

  if (debug == true){
    Serial1.print(value);
  }
  else{
    Serial.write(value); //Debug-Option
  }

Is debug set to true? The demo code shows it is set to false. If debug == false, Serial1 will not get any data. All output goes to Serial, not Serial1.

SurferTim - You're right - I'm a idiot... ;-) thx

PaulS - The code is pretty huge - so i posted the link to my repo - so i dont't fill up the forum with code, which is already online available...

No idiocy there. I'm sure everyone has reversed logic at one time or the other. However, if you want to save program memory when you don't need debug, use a define instead.

Under the includes before setup()

define myDEBUG

Then in your code

#ifdef myDEBUG
   Serial.println("My debug message");
#endif

Then, when you are finished debugging, comment out "#define myDEBUG" and recompile. The resulting code will be smaller.

cool thx for the hint - i will try it when i get my xbee running again :-(

IDE 0.23 - I got no Problems, but in 1.0 the XBee data packets all go wrong... (i see the packet arriving at the shield and get "shot out" to the air - but on the receiver side - they don't seem to arrive...

Example which works in 0.22 - but fails on 1.0:

boolean debug = false;

void setup(){
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop(){
  xwater();
  delay(1000);
}

void xwater(){
  xtrans(0x7E);
  xtrans(0x0);
  xtrans(0x0F);
  long xcsum = 0;
  xcsum += xtrans(0x10);
  xcsum += xtrans(0x01);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x13);
  xcsum += xtrans(0xA2);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x40);
  xcsum += xtrans(0x69);
  xcsum += xtrans(0x6C);
  xcsum += xtrans(0xEB);
  xcsum += xtrans(0x6B);
  xcsum += xtrans(0x6F);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x01);
  xtrans( 0xFF - (xcsum & 0xFF));
}


// Transfer commands to XBee
byte xtrans(byte value){
  if (debug == false){
    Serial1.print(value);
  }
  else{
    Serial.print(value); //Debug-Option
  }
  delay(10);
  return value;
}

Pretty shitty... :-)

Any suggestions, or should i stay in 022 ???

I think i found the solution...

boolean debug = false;

void setup(){
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop(){
  xwater();
  delay(1000);
}

void xwater(){
  xtrans(0x7E);
  xtrans(0x0);
  xtrans(0x0F);
  long xcsum = 0;
  xcsum += xtrans(0x10);
  xcsum += xtrans(0x01);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x13);
  xcsum += xtrans(0xA2);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x40);
  xcsum += xtrans(0x69);
  xcsum += xtrans(0x6C);
  xcsum += xtrans(0xEB);
  xcsum += xtrans(0x6B);
  xcsum += xtrans(0x6F);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x00);
  xcsum += xtrans(0x01);
  xtrans( 0xFF - (xcsum & 0xFF));
}


// Transfer commands to XBee
byte xtrans(byte value){
  if (debug == false){
    Serial1.write((byte)value);
  }
  else{
    Serial.print(value); //Debug-Option
  }
  delay(10);
  return value;
}

at least the packets arrive on xbee on the rx-module

Is there a good reason not to use an array and a for loop, or do you just enjoy typing?

I enjoy writing code g (and using copy/paste)

I'm doing this as a hobby (never wrote real code befor - execpt batch and/or shell scripts - which isn't real code...).

And also as beginner I'm also enjoying to use code which i "invented" by reading books/articles/websites (like the one above) which are easy to understand (for me) - i've "planed" the optimisation of the code in later step... first the whole "thing" should work, than I can crash the "project" with optimisations.

Arrays in special are always a bit of a "nightmare" for me - i love spreadsheets but i think i can't fully understand arrays...

Hope you don't misunderstand the answer as rude...

I'm just a hobbyist, thankful for all input I can get - and yes, I will consider to use arrays in the near future ;-)