ArduinoCore-API icon indicating copy to clipboard operation
ArduinoCore-API copied to clipboard

Add printf to print class

Open MCUdude opened this issue 6 years ago • 11 comments

Printf is super useful. This PR will let users use Serial.printf

MCUdude avatar Feb 28 '19 16:02 MCUdude

Didn't Massimo (@mbanzi) say very clearly, only 2 weeks ago on the developers mail list, that this would not be accepted?

PaulStoffregen avatar Feb 28 '19 18:02 PaulStoffregen

That may be true, but I'm not in the developer mailing list 😉 I don't quite see why printf is such a bad thing to have available though.

MCUdude avatar Feb 28 '19 18:02 MCUdude

I'm not going to argue this. My only point is this has been proposed over and over, and the Arduino devs have clearly said it does not belong in Arduino's API. Now that you know this, you can look up what they've said and argue if you like.

PaulStoffregen avatar Feb 28 '19 19:02 PaulStoffregen

Did some google-fu and found the threads you're referring to. It's really weird, but many (most) of the "We should implement printf in print class" discussions ends up with ranting and personal attacks.

Personally I'd love to see this merged because I personally find printf easy to use and understand. However I'd of course respect if the Arduino Gods have a different opinion than me.

I'll leave this open until it's merged or closed by any of the developers.

MCUdude avatar Feb 28 '19 22:02 MCUdude

I believe this is the specific statement from Massimo Banzi that Paul Stoffregen referred to: https://groups.google.com/a/arduino.cc/d/msg/developers/E0pUPWeDE2Y/GPWl9Nw1BwAJ

Related: https://github.com/arduino/Arduino/issues/2416

per1234 avatar Feb 28 '19 22:02 per1234

Clearly a lot of people have strong feelings on this matter. Some of those folks may have more passion than wisdom.

FWIW, I have some printf code similar to what Bill Perry suggested just today, but it uses Arduino's Print class rather than duplicating so much code and allocating big buffers. When I get a break in working on hardware, I'm planning to turn it into a nice library that works on all boards.

PaulStoffregen avatar Feb 28 '19 22:02 PaulStoffregen

@PaulStoffregen

I have some printf code similar to what Bill Perry suggested just today

Paul, could you add a link, please? Just out of interest...

Floessie avatar Mar 01 '19 09:03 Floessie

could you add a link, please? Just out of interest...

I believe this is it: https://groups.google.com/a/arduino.cc/d/msg/developers/sTacUMEXBTw/H2v9GabLBAAJ

per1234 avatar Mar 21 '19 07:03 per1234

Bill's code allocates a 128 byte buffer on the stack.

Sorry, my own no-buffer printf code isn't public at this time. I already maintain a couple dozen libs, which regularly get requests for platform-specific issues (the ESP folks are the worst - so much breaks on those chips...), so I'm not very inclined to release yet another library in an "alpha" quality state.

Edit: Just to be clear, technically any "no buffer" code that relies on Arduino's Print class does involve a 33 byte buffer allocated on the stack, due to Arduino's Print::printNumber() function.

PaulStoffregen avatar Mar 21 '19 12:03 PaulStoffregen

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 09 '21 13:04 CLAassistant

my StreamLib enables to use printf without support in core API. https://github.com/JAndrassy/StreamLib#formatted-printing and the implementation doesn't use a buffer. it has avr, arm end esp implementation. https://github.com/JAndrassy/StreamLib/blob/master/src/PrintPlus.cpp

JAndrassy avatar May 15 '22 07:05 JAndrassy