4

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.

3
  • 1
    Ask at electronics.stackexchange.com Commented Jun 12, 2012 at 1:16
  • @powtac good point. I should have. Commented Jun 12, 2012 at 1:18
  • I accidentally clicked close, can't withdraw it - sorry. Commented Jun 12, 2012 at 1:20

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

Thank you, that also saves me the hassle of making a function to do some bitwise shifting on integers.
1

Back to the future!

Yes, standard UART serial will handle binary just fine. Make sure you have a stop bit configured on the UART (universal asynchronous receive/transmit) device at each end of the serial line and you should be all set.

This kind of thing takes a certain amount of goofing around to get right, in my experience. If you set both UARTs to 8 bits, one stop bit, no parity, and the same bits/sec rate, you should be good.

You could try hooking one end of the serial line to a terminal emulator on your PC if you're really puzzled. SecureCRT by Van Dyke Software has a 30-day free trial and will handle ordinary serial.

Comments

0

Same Issue I found sending following uart packet via Software Serial: a[10]={0x12,0x32,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x14} mySerial.write(a) will send only 0x12,0x32,0x30 and wont send the null character. To solve this I had to send null characters using mySerial.write((byte)0). So Arduino Serial Library sends null character only if it is sent alone :P

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.