Serial.write null character

Is there a way to write the null character to a serial stream. I tried both print and write with char or unsigned char but none of the combinations actually writes the null character. In fact if I do

case GETMODEBYTE:
Serial.print('s');
Serial.print('t');
Serial.print('m');
Serial.write(0x00);
Serial.write(0x01);
Serial.write(0x02);

The output on the other end of the serial connection would be:

0x73 0x74 0x6d 0x01 0x02

The output on the other end of the serial connection would be

Difficult to tell from that statement which end is at fault.
I don't see any problem with a "Serial.write (0);"

I can see no special handling of 0 in the serial write code (as you would expect), so it has be the receiving end. Can you post that code?


Rob

Hmmm, I've looked at it with my scope and I guess the 0 is being sent, however it isn't received by windows. Strange...

ow yeah, that is with following code:

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

	

}

void loop()
{
	Serial.write('a');
	Serial.write(0x00);
	Serial.write('a');

	delay(1000);
}

Well who know what's happening in Windows? That's why I like embedded work :slight_smile:

Does that terminal program have a binary or HEX mode or something, it looks to be in ASCII mode and in that case you won't see any control characters.


Rob

The program is a serial monitor, it spies on an already open serial port. The port is opened by the arduino serial monitor. The before last column displays the hex values :slight_smile:

Anyway, normally I send the data with a bluegiga chip to my android phone, so my hope is that java(android) will be able to interpret the null character correctly, otherwise I'll have to adjust my protocol :slight_smile: