Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New to SAMD21 - is there no Serial.printf? #457

Closed
beegee-tokyo opened this issue Sep 30, 2019 · 5 comments
Closed

New to SAMD21 - is there no Serial.printf? #457

beegee-tokyo opened this issue Sep 30, 2019 · 5 comments

Comments

@beegee-tokyo
Copy link

Maybe it's just me, but on other architectures I am have no problems using printf like

Serial.printf("\nLoRa begin failed %d\n", state);

But for SAMD21 it throws compile error

src\main.cpp:78:10: error: 'class Uart' has no member named 'printf'; did you mean 'print'?
   Serial.printf("\nLoRa begin failed %d\n\n", state);

Am I missing something

@matthijskooijman
Copy link
Collaborator

No official architecture supports Serial.printf AFAIK (intentionally, there are some discussions on the mailing list and github about this). There might be third-party libraries that make it work, maybe you have some such library installed for other archs? Or maybe you are comparing with third-party architectures?

@beegee-tokyo
Copy link
Author

With other architectures I meant ESP32 Arduino, ESP8266 Arduino, nRF52 Arduino frameworks.
Also printf is standard C++ http://www.cplusplus.com/reference/cstdio/printf/

Surprised it is not on SAMD

@beegee-tokyo
Copy link
Author

Example. on ESP32 it is in Print.cpp

size_t Print::printf(const char * format, ...)
{
  char buf[256];
  int len;

  va_list ap;
  va_start(ap, format);

  len = vsnprintf(buf, 256, format, ap);
  this->write(buf, len);

  va_end(ap);
  return len;
}```

Wondering if that would work on SAMD

@beegee-tokyo
Copy link
Author

I see, that it is not in ArduinoAVR framework. Maybe I was just lucky with the platforms I used before.

@matthijskooijman
Copy link
Collaborator

Yeah, those are third-party platforms that have made this custom addition. It is not part of the official Arduino API, for reasons previously stated elsewhere. See also arduino/ArduinoCore-API#34.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants