Post topics, source code that relate to the Arduino Platform

User avatar
By Franco Picarelli
#26176 Hi there!

Alright, I managed to get the Arduino Uno talking to the ESP8266-01, and creted a Sketch that configures the module and sends UDP messages to another PC. I'm using Hercules to receive the messages.

The problem is that the messages I need to send must be in OSC format, which require filling the end with NULL characters. The exact message is "/PlayVideo\0\0" (total of 12 bytes, 2 null chars at the end), but I haven't found a way to send it, since the SoftwareSerial.write() function seems to ignore NULL chars. The same seems to happend with print() and println().

Does anyone you know any way around this? Do I need to modify the SoftwareSerial.write() function?

Thank you!

Franco
User avatar
By Brian Heim
#55275 Hey! I realize this reply is over a year late but I had the same problem and wanna share the solution in case anyone else finds this thread.

Since the Arduino IDE is based on C, you can't include null chars in a literal string or the compiler will end the string early, i.e. "test\0test\0123" will be interpreted as "test" since the \0 is implicitly the end of the string in C specifications.

The solution is to write the normal parts of the strings as strings using Serial.write and then use literal byte values. For example, here's some of the test code I used that writes a valid OSC message [/oscillator/4/frequency, 440.0]:

Serial1.write("/oscillator/4/frequency");
Serial1.write(0); // end of path tag
Serial1.write(",f"); // one value, float
Serial1.write(0); // padding
Serial1.write(0); // end of types tag
Serial1.write('\x43'); // four 32-bit float bytes
Serial1.write('\xdc');
Serial1.write(0);
Serial1.write(0);

Hope this helps!

-Brian