Serial Communication with Arduino with << syntax


So I saw the Serial management like it is done in the ODrive example for the first time.

odrive_serial << “w axis” << axis << ".controller.config.vel_limit " << 10.0f << ‘\n’;

I understand how it is working, but i cant finde any references and I don’t know what it is called.
I would like to use it with the normal Serial communication on the arduino, but that doesn’w wan’t to work anymore somehow. (I had it working with a teensy and my ODrive)

I think it is a interesting concept, because it is very compact in comparison to Serial.print…
I am often working with serial and serial parsers, so it would be nice to make my code more professional i guess…

I think tis syntax comes from C or C++, but i am not sure.

Does anybody know something?
For example wich libraries it requires to work?

THX for answering

Greetings from Switzerland

@marvinhotz Check out the odrive arduino example. At the top of the script you can put a template like so:

// Printing with stream operator helper functions
template<class T> inline Print& operator <<(Print &obj,     T arg) { obj.print(arg);    return obj; }
template<>        inline Print& operator <<(Print &obj, float arg) { obj.print(arg, 4); return obj; }

This is known in C++ as the “Stream” operator

thanks for the answer.
Interesting stuff, makes serial communication a lot more efficient.
I got it working now :slight_smile:
Interestingly there are no real Arduino references to this.
Best regards

1 Like

Yeah, @Samuel just decided to overload the stream operator because he can lol. Not really an Arduino thing, just pure C++.