Serial.print Modulo ?


"%d" is a format descriptor. %d denotes: "at this location of the cstring, there will be an int". More info here:

i often see such serial.print with %d or similar

Where have you seen this ?

UKHeliBob: Where have you seen this ?

It is likely to pop up in projects people stumble across out there that do not use the AVR or DUE based Arduinos, since several of the 3rd party cores have added a printf() method to the Print class they provide with their core. Teensy/Teensy3, Chipkit, esp8266, esp32, to name a few. So you likely may see it in espxxx projects.

The developers, even after many requests for it over numerous years, have over and over again refused to add it into the IDE supplied cores. My guess is that is that they are taking their ques on this from the top. Tom Igoe, who still swings a lot of weight over Arduino often seems to be against adding standardized ways of doing things to arduino claiming that they are too "scary" or complicated for arduino users.

I use the printf() method quite often in my personal Arduino projects and I've even written how to add it to the AVR core Print class on the playground printf page for those that want it to work with the AVR. Floating point is a PITA to get enabled given the way the avr libC implemented separate libraries that require specifying linker options These days, this is just one of several reasons why I no longer use AVRs for any of my person Arduino projects.

--- bill

i often see such serial.print with %d or similar.

print() and printf() are not the same thing.
They are different methods in the Print class.
The printf() method, as arduino_new pointed out, works like the standard C printf() function which has existed for a little over 50 years.

So far, as far as I know, the official cores from that come with the IDE (UNO/MEGA, DUE, etc…) do not have support for the printf() method, so you won’t find it mentioned in any documentation from

— bill