Arduino 1.0 Serial.write() question

How can you send a byte value 0x00 using Serial.write() function. I've tried Serial.write(0), but it returns a compiler error "error: call of overloaded 'write(int)' is ambiguous"; however, Serial.write(1) works fine. How can I send value zero to a serial port. Thanks.

Try

Serial.write((byte) 0x00);

The below has some 1.0 changes.

http://blog.makezine.com/archive/2011/12/arduino-1-0-is-out-heres-what-you-need-to-know.html

Thanks to both Aeturnalus and Zoomkat

Hi all,
I am still confuse with the Serial.write() function. If we use this function to send a int value as byte, will the serial monitor print the value as a byte representation or a character?

thanks

What do you mean by "a byte representation"?

I presume that if you cast to byte type, it goes to the serial monitor untranslated (and casting would throw away any higher-order bytes).

Hi Mr Nick, actually I send a int value using the Serial.write.

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

void loop() {
  int x = 123;
  int digit1;
  int digit2;
  int digit3;

  digit1 = x/100;
  digit2 = (x-(digit1*100))/10;
  digit3 = x-(digit1*100)-(digit2*10);
  
  //Serial.print(x);
  //Serial.print(" ");
  Serial.write(digit1);
  Serial.print(" ");
  Serial.write(digit2);
  Serial.print(" ");
  Serial.write(digit3);
  Serial.println("");
}

Does the code send the digit1, digit2 and digit3 as byte? because the serial monitor didnt show anything. It was scrolling but didnt show any number or character.

Have a look at the ASCII table: http://www.asciitable.com/

You are sending characters 1 (SOH), 2 (STX) and 3 (ETX). These are non-printable characters. If you want to see the characters '1', '2' and '3', use Serial.print() instead.

Actually I want to send byte data of digit1, digit2 and digit3 using the serial function. Any suggestions how to do that? Should I make those values into byte and then send them using Serial.print?

Thanks

That's what you are doing. If you want to be certain, you could:

Serial.write((byte)digit1);
Serial.write((byte)digit2);
Serial.write((byte)digit3);

hanlee: How can you send a byte value 0x00 using Serial.write() function. I've tried Serial.write(0), but it returns a compiler error "error: call of overloaded 'write(int)' is ambiguous"; however, Serial.write(1) works fine. How can I send value zero to a serial port. Thanks.

The problem with 0 in particular is that it is also a valid value for every pointer type... The null pointer.

Okay, thaks to all of you guys