Giter VIP home page Giter VIP logo

arduino-printf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-printf's Issues

Add Meson Documentation

I need to add documentation on using the meson build system + using this project as a meson subproject.

printf does not output anything with the %c format charater

Problem

printf("%c", 'A'); outputs nothing

Environment

Arduino UNO
Windows 10
Arduino IDE 1.18.13
LibPrintf 1.1.3

Expected Behavior

Given the following program compiled and uploaded to the Arduino I would expect the serial console to show a single "A" character

#include <LibPrintf.h>\\LibPrintf 1.1.3

void setup() {
  Serial.begin(9600);
  printf("%c", "A");
}

void loop() {
  
}

Actual Behavior

nothing outputs to the serial console.
Installing LibPrintf Version 1.1.2 results in the correct and expected behavior.

Support Arduino Uno Wifi Rev 2

It appears that it doesn’t support the standard SDK.

In file included from /Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.cpp:1:0:
/Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.h:13:18: error: variable or field 'printf_init' declared void
void printf_init(Print& StreamClass);
^~~~~
/Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.h:13:18: error: 'Print' was not declared in this scope
/Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.h:13:18: note: suggested alternative:
In file included from /Users/phillip/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/api/deprecated/Print.h:23:0,
from /Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.h:4,
from /Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.cpp:1:
/Users/phillip/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/cores/arduino/api/deprecated/../Print.h:34:7: note: 'arduino::Print'
class Print
^~~~~
In file included from /Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.cpp:1:0:
/Users/phillip/Documents/Arduino/libraries/LibPrintf/src/LibPrintf.h:13:25: error: 'StreamClass' was not declared in this scope
void printf_init(Print& StreamClass);
^~~~~~~~~~~
exit status 1
Error compiling for board Arduino Uno WiFi Rev2.
Changing the namespace gets us past this:

void printf_init(arduino::Print& StreamClass);

PlatformIO version of LibPrintf appears broken.

Hello. I've used your installable library in the Arduino IDE and I love it. Thanks for this.

Unfortunately, I'm unable to use it "as is" in PlatformIO as the extras directory is missing. The library in question is at https://registry.platformio.org/libraries/embeddedartistry/LibPrintf.

I see it was last updated 4 months ago, so maybe that directory was somehow dropped from the installed source code? I've copied mine over from the Arduino version, so no major problems, but I thought I better let you know.

Cheers,
Norm.

Hex # flag not printed for zero value

printf() does not print leading "0x" with # flag for a zero value parameter.

Code sample:

printf("%#X %#X %#X\n", 0xffff, 0xa5, 0x0000);
printf("%#4.4X %#4.4X %#4.4X\n", 0xffff, 0xa5, 0x0000);

Results:

0XFFFF 0XA5 0 // expected 0XFFFF 0XA5 0X0
0XFFFF 0X00A5 0000 // expected 0XFFFF 0X00A5 0X0000

PlatformIO doesn't like the reference to files in the "extras" folder

PlatformIO can include this library in the plaformio.ini file like this:

lib_deps = embeddedartistry/LibPrintf@^1.1.3

But compilations fails as there are references to an "extras" library that is not part of (or subordinate to) the "src" folder and is thus considered outside of the source files and not downloaded.

Please consider putting the extras files (config stuff, it looks like) in the src folder so PlatformIO can find it.

Workaround: copy the entire GitHub repository into the "lib" folder; this however, freezes the library and will not get updates.

include error when using in platformio

When using inside of PlatformIO I get this error about dependency.

cannot open source file "../extras/printf/printf.h" (dependency of "LibPrintf.h")C/C++(1696)
.pio\libdeps\nanoatmega328new\LibPrintf\src\LibPrintf.h:5:37: fatal error: ../extras/printf/printf.h: No such file or directory

error: '::printf', '::sprintf', '::vprintf' has not been declared for ESP8266

Hello

I am using an apparently Arduino compatible ESP8266 module (https://github.com/esp8266/Arduino). When building with this library I get the following error message:

In file included from c:\users\user\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\random:39:0,
                 from c:\users\user\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_algo.h:65,
                 from c:\users\user\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\algorithm:62,
                 from C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/Arduino.h:238,
                 from C:\Users\user\Documents\Arduino\libraries\LibPrintf\src\LibPrintf.cpp:2:
c:\users\user\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\cstdio:121:11: error: '::printf' has not been declared
   using ::printf;
           ^
c:\users\user\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\cstdio:131:11: error: '::sprintf' has not been declared
   using ::sprintf;
           ^
c:\users\user\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\cstdio:137:11: error: '::vprintf' has not been declared
   using ::vprintf;
           ^
exit status 1
Error compiling for board Generic ESP8266 Module.

It does work when building for Arduino modules.
Is there any way to get this library running on ESP8266?

Thank you very much!

Not compatible with Teensy!

This does not work with PIO and Teensy 3.2.

At first I thought my teensy got bricked (not responding), even my host system (ubuntu) crashed.
Turns out that teensy uses the HID protocol and the lib somehow messes with that, therefore all HID devices on my ubuntu started behaving weirdly.
After rebooting the system, holding down the "programming button" on the teensy before an while plugging it in, I could re-flash the microcontroller which now works perfectly fine again.

Somehow - however - this event messed with a USB-hub. I have a Dell-da300 port replicator (which still works fine btw) and if connected, the kernel now gives me an error message every five seconds:
"[ ... ] usb usb4-port1: Cannot enable. Maybe the USB cable is bad?"

Not sure how this is related, but it didn't happen before...

Implement printf/puts workaround that does not rely on undefined behavior

I suspect the mpaland approach to the definitions resulted in printf_ being used as the actual name instead of printf w/ the Aliasing option, which avoided the optimization in the past. One workaround is to supply a puts that forwards to printf (what I will do for now, though I suspect that might be undefined behavior). The other workaround is to NOT alias the standard library using the preprocessor option, but instead have LibPrintf.h provide macros like: #define printf printf_ to recreate the old behavior and work with the non-aliased names.

Commented function in code:

/// This works around a problem where GCC is replacing
/// printf("string with no args") with puts("string with no args"), which
/// is not actually implemented in a way that is suitable for us, resulting
/// in an infinite reboot loop or simply not printing that output, depending
/// on my luck.
///
/// This is probably NOT the right way to go about this (expecting it to be undefined
/// behavior, but I have fewer tools available in Arduino land, so I am
/// sticking with this for now.
///
/// If this causes problems in the future, the next thing to try is
/// NOT using the Aliasing option (currently defined in LibPrintf.h) and instead
/// then providing definitions in the mpaland style in our LibPrintf.h header:
/// #define printf printf_
/// #define vprintf vprintf_
/// etc.
extern "C" int puts(const char * str)
{
	return printf("%s\n", str);
}

Library uses substantially more storage than PrintEx?

I use PrintEx in a lot of my projects, but it's not maintained any more (last update was 2016). Researching your printf() implementation looks promising but it uses a significant amount of storage.

Any idea why this implementation is so much larger?

PrintEx

Sketch uses 5486 bytes (17%) of program storage space. Maximum is 32256 bytes.
Global variables use 264 bytes (12%) of dynamic memory, leaving 1784 bytes for local variables. Maximum is 2048 bytes.

arduino-printf

Sketch uses 9876 bytes (30%) of program storage space. Maximum is 32256 bytes.
Global variables use 254 bytes (12%) of dynamic memory, leaving 1794 bytes for local variables. Maximum is 2048 bytes.

How to print a String

I have a

String  s = "Hello" 

Serial.print(s); // works
printf("%s\n",s). << Does not work :(

Refactor library to move extras/ files back into src/

From #37:

Second, the library's .cpp file includes the printf.c file directly in order to supply default compile-time configuration options (e.g., to make it suitable for AVR targets). Including the printf.c source file in the src tree causes the Arduino IDE to automatically compile the files a second time, generating multiple definition errors at link time. Moving to the extras folder gave me a pattern that worked to achieve the goals above (at least with the Arduino IDE, CMake, and Meson builds) and passes the Arduino library linter that is run to determine whether your library can be included in the library manager. (All my headaches are caused by the "helpful" features like auto-compiling source files or auto-deleting "unnecessary" folders to save space or configuration options 😅).

After this recent filing, I looked into refactoring the Arduino library code to use the recently provided configuration header support in printf.c to supply the default options, but its inclusion is dependent on another preprocessor definition instead of something like __has_include, so I cannot get around it without updating the upstream library. Ideally, I will work with the maintainer to get these changes rolled in (ideal scenario), otherwise I will have to deviate further on my own fork or in this library. One of those will happen, but not in the next few weeks, so again a stopgap would be welcome.

Issues building in platformio for ESP32.

I am running into an issue building an ESP32 project in platformio with some error messages that I have never seen before.

I have attempted to rollback the Espressif32 platform version from 6.0.1 to various other versions up to 2 years in the past, which also would have downgraded the toolchain versions, but with no improvement.

Is this something anyone has seen before?

Error output below:

In file included from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\ext\string_conversions.h:43,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6400,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\string:52,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\stdexcept:39,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\array:39,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\tuple:39,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\functional:54,
                 from C:/Users/Destari/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:49,
                 from C:/Users/Destari/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:174,
                 from .pio/libdeps/adafruit_feather_esp32_v2/LibPrintf/src/LibPrintf.cpp:4:
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:127:11: error: '::printf' has not been declared
   using ::printf;
           ^~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:137:11: error: '::sprintf' has not been declared
   using ::sprintf;
           ^~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:145:11: error: '::vprintf' has not been declared
   using ::vprintf;
           ^~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:146:11: error: '::vsprintf' has not been declared
   using ::vsprintf;
           ^~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:175:11: error: '::snprintf' has not been declared
   using ::snprintf;
           ^~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:178:11: error: '::vsnprintf' has not been declared
   using ::vsnprintf;
           ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:185:22: error: '__gnu_cxx::snprintf' has not been declared
   using ::__gnu_cxx::snprintf;
                      ^~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\cstdio:188:22: error: '__gnu_cxx::vsnprintf' has not been declared
   using ::__gnu_cxx::vsnprintf;
                      ^~~~~~~~~
In file included from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\string:52,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\stdexcept:39,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\array:39,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\tuple:39,
                 from c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\functional:54,
                 from C:/Users/Destari/.platformio/packages/framework-arduinoespressif32/cores/esp32/HardwareSerial.h:49,
                 from C:/Users/Destari/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:174,
                 from .pio/libdeps/adafruit_feather_esp32_v2/LibPrintf/src/LibPrintf.cpp:4:
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(int)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6454:50: error: 'vsnprintf' is not a member of 'std'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int),
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6454:50: note: suggested alternative: 'isprint'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int),
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(unsigned int)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6459:50: error: 'vsnprintf' is not a member of 'std'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6459:50: note: suggested alternative: 'isprint'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(long int)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6465:50: error: 'vsnprintf' is not a member of 'std'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long),
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6465:50: note: suggested alternative: 'isprint'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long),
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(long unsigned int)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6470:50: error: 'vsnprintf' is not a member of 'std'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6470:50: note: suggested alternative: 'isprint'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(long long int)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6476:50: error: 'vsnprintf' is not a member of 'std'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6476:50: note: suggested alternative: 'isprint'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(long long unsigned int)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6482:50: error: 'vsnprintf' is not a member of 'std'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6482:50: note: suggested alternative: 'isprint'
   { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf,
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(float)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6491:50: error: 'vsnprintf' is not a member of 'std'
     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6491:50: note: suggested alternative: 'isprint'
     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(double)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6500:50: error: 'vsnprintf' is not a member of 'std'
     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6500:50: note: suggested alternative: 'isprint'
     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
                                                  ^~~~~~~~~
                                                  isprint
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h: In function 'std::__cxx11::string std::__cxx11::to_string(long double)':
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6509:50: error: 'vsnprintf' is not a member of 'std'
     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
                                                  ^~~~~~~~~
c:\users\destari\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:6509:50: note: suggested alternative: 'isprint'
     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
                                                  ^~~~~~~~~
                                                  isprint

*** [.pio\build\adafruit_feather_esp32_v2\lib99a\LibPrintf\LibPrintf.cpp.o] Error 1

Arduino Uno not working with snprintf and %E or %G

Hi there, I've been trying to use snprintf with the %G format specifier and depending on the float I inputted this resulted in the Arduino getting hung up and not sending anything over serial (for example when using 2.4455345e12 as input float), it writing 00000000000000000000 or infe-249 with %e format specifier.

I am using the Arduino IDE on Artix Linux and an Arduino Uno Rev. 3

As test sketch i used

#include <LibPrintf.h>

void setup() {
  Serial.begin(9600);
  delay(500);
}

void loop() {
  char buf[21] {0};
  snprintf(buf, 21, "% 18G", 2.4455345);
  Serial.println(buf);
  delay(50);
}

and in my platform.local.txt I have

compiler.cpp.extra_flags=-DPRINTF_PREVENT_DEFAULT_AVR_SETTINGS -DPRINTF_DISABLE_SUPPORT_LONG_LONG
compiler.c.extra_flags=-DPRINTF_PREVENT_DEFAULT_AVR_SETTINGS -DPRINTF_DISABLE_SUPPORT_LONG_LONG
Build Output
/usr/share/arduino/arduino-builder -dump-prefs -logger=machine -hardware /usr/share/arduino/hardware -hardware /home/skylar/.arduino15/packages -tools /usr/share/arduino/tools-builder -tools /home/skylar/.arduino15/packages -libraries /home/skylar/documents/programming/Arduino/libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10817 -build-path /tmp/arduino_build_624533 -warnings=all -build-cache /tmp/arduino_cache_997480 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=/home/skylar/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/skylar/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=/home/skylar/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/skylar/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -verbose /home/skylar/documents/programming/Arduino/Printf_Test/Printf_Test.ino
/usr/share/arduino/arduino-builder -compile -logger=machine -hardware /usr/share/arduino/hardware -hardware /home/skylar/.arduino15/packages -tools /usr/share/arduino/tools-builder -tools /home/skylar/.arduino15/packages -libraries /home/skylar/documents/programming/Arduino/libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10817 -build-path /tmp/arduino_build_624533 -warnings=all -build-cache /tmp/arduino_cache_997480 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=/home/skylar/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/skylar/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=/home/skylar/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/skylar/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -verbose /home/skylar/documents/programming/Arduino/Printf_Test/Printf_Test.ino
Using board 'uno' from platform in folder: /home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4
Using core 'arduino' from platform in folder: /home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4
Detecting libraries used...
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10817 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -DPRINTF_PREVENT_DEFAULT_AVR_SETTINGS -DPRINTF_DISABLE_SUPPORT_LONG_LONG -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/variants/standard /tmp/arduino_build_624533/sketch/Printf_Test.ino.cpp -o /dev/null
Alternatives for LibPrintf.h: [[email protected]]
ResolveLibrary(LibPrintf.h)
 -> candidates: [[email protected]]
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10817 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -DPRINTF_PREVENT_DEFAULT_AVR_SETTINGS -DPRINTF_DISABLE_SUPPORT_LONG_LONG -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/variants/standard -I/home/skylar/documents/programming/Arduino/libraries/LibPrintf/src /tmp/arduino_build_624533/sketch/Printf_Test.ino.cpp -o /dev/null
Using cached library dependencies for file: /home/skylar/documents/programming/Arduino/libraries/LibPrintf/src/LibPrintf.cpp
Generating function prototypes...
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10817 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -DPRINTF_PREVENT_DEFAULT_AVR_SETTINGS -DPRINTF_DISABLE_SUPPORT_LONG_LONG -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/variants/standard -I/home/skylar/documents/programming/Arduino/libraries/LibPrintf/src /tmp/arduino_build_624533/sketch/Printf_Test.ino.cpp -o /tmp/arduino_build_624533/preproc/ctags_target_for_gcc_minus_e.cpp
/usr/bin/arduino-ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_624533/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10817 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -DPRINTF_PREVENT_DEFAULT_AVR_SETTINGS -DPRINTF_DISABLE_SUPPORT_LONG_LONG -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/cores/arduino -I/home/skylar/.arduino15/packages/arduino/hardware/avr/1.8.4/variants/standard -I/home/skylar/documents/programming/Arduino/libraries/LibPrintf/src /tmp/arduino_build_624533/sketch/Printf_Test.ino.cpp -o /tmp/arduino_build_624533/sketch/Printf_Test.ino.cpp.o
Compiling libraries...
Compiling library "LibPrintf"
Using previously compiled file: /tmp/arduino_build_624533/libraries/LibPrintf/LibPrintf.cpp.o
Compiling core...
Using precompiled core: /tmp/arduino_cache_997480/core/core_arduino_avr_uno_26f9e2aa5e5a8259cb599b0504c5f6ad.a
Linking everything together...
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -Wall -Wextra -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o /tmp/arduino_build_624533/Printf_Test.ino.elf /tmp/arduino_build_624533/sketch/Printf_Test.ino.cpp.o /tmp/arduino_build_624533/libraries/LibPrintf/LibPrintf.cpp.o /tmp/arduino_build_624533/../arduino_cache_997480/core/core_arduino_avr_uno_26f9e2aa5e5a8259cb599b0504c5f6ad.a -L/tmp/arduino_build_624533 -lm
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino_build_624533/Printf_Test.ino.elf /tmp/arduino_build_624533/Printf_Test.ino.eep
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -R .eeprom /tmp/arduino_build_624533/Printf_Test.ino.elf /tmp/arduino_build_624533/Printf_Test.ino.hex
Using library LibPrintf at version 1.1.3 in folder: /home/skylar/documents/programming/Arduino/libraries/LibPrintf 
/home/skylar/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-size -A /tmp/arduino_build_624533/Printf_Test.ino.elf
Sketch uses 8160 bytes (25%) of program storage space. Maximum is 32256 bytes.
Global variables use 248 bytes (12%) of dynamic memory, leaving 1800 bytes for local variables. Maximum is 2048 bytes.

printf_init(Serial3) does not work

(Using RobotDyn MEGA+WiFi R3 ATmega2560+ESP8266, flash 32MB, USB-TTL CH340G, Micro-USB)
the switches are set in a way that ATmega2560 talks to ESP8266 using Sereal3.
I tried the example (specify_print_class.ino), (of course changing Serial1 to Serial3 inn two places) but it did not work, it did not switch to using Serial3.

On the other hand, if I go and edit LibPrintf/src/LibPrintf.cpp , line 15, and hard-code Serial3 there all the text is correctly sent to Serial3.

Add meson build system notes

  • I need to add documentation on using the meson build system + using this project as a meson subproject.
  • Add installation notes to arduino-printf project for meson build system (pip3 install meson ninja)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.