Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Arduino transmit null characters via Serial?

I'm going to set up a binary driven serial communications between two Arduinos via the built-in hardware serial library. Since my packets are structured in a binary format, it is very likely that several characters in the packet are null characters for instances of integers with a 0 value. I'm not sure how the Arduinos will handle null characters or if at all. I would certainly like to know before I go any further on my project.

like image 625
jakebird451 Avatar asked Sep 15 '25 00:09

jakebird451


2 Answers

Binary data can be transmitted using the write() method in the following form:

Serial.write(buf, len)

where...

buf: an array to send as a series of bytes.
len: the number of bytes to be sent from the array.

In this way all the specified characters are transmitted, included the null ones. Otherwise, if just the buffer parameter is passed to the method, it treats the parameter as a string and stops transmitting at the first null character it encounters.

like image 117
Gengis Avatar answered Sep 17 '25 20:09

Gengis


Yes. The Arduino documentation for write() talks about "binary data" and bytes.

like image 21
vz0 Avatar answered Sep 17 '25 19:09

vz0