Comments (4)
What board are you using?
I was not able to reproduce the problem on an Uno. I suspect that you may have an Arduino with an integrated USB controller like an ATMega32u4 that's on the nano and many others. The UARTS on my ATMega328P just blast out the bits whether or not anyone is listening and I don't see any change in cycle time. I measured with millis() as well as looked.
However, if the problem also exists (to a different degree) when using Serial.print() there's probably nothing I can do about it. The printf() function is implemented using Serial.write(). Here's the code that printf uses from ArduinoSTL.cpp
static int arduino_putchar(char c, FILE* f) {
Stream *uart = __stdio_wrapper.getUart();
if (c == '\n') uart->write('\r');
return uart->write(c) == 1? 0 : 1;
}
As you can see I call write for every character --because that's what printf needs-- which isn't particularly efficient. That might explain why printf() has a greater delay.
from arduinostl.
Yes that's right, I'm using an Arduino Micro.
The printf() function is implemented using Serial.write().
This explains why it seemed to completely lock the whole device up in my production code (where much more text is being printed).
What seems to work is to count how long a printf takes and if it takes too long restart the program like so:
int tic = millis();
printf("running... ");
if (millis() - tic > 500){
asm volatile("jmp 0");
}
Thanks for the quick answer, I think you can close this issue as unfixable.
from arduinostl.
This might work too:
https://www.arduino.cc/en/Serial/IfSerial
It looks like you can determine if the serial port is attached. Try this instead:
if (Serial) {
printf("running...");
}
The documentation doesn't make it clear if this should only be used to time initialization or to more generally detect the presence of a serial monitor.
from arduinostl.
Ok I tried this, but it doesn't seem to be working. if(Serial)
is still true after the serial Monitor disconnected. Not to worry, thanks for your help!
from arduinostl.
Related Issues (20)
- Initializing vector<string> Beyond a Number of Entries Crashes Sketch HOT 2
- in file .src\limits line24 there throw an err HOT 1
- Mistake in seekoff function of basic_stringbuf HOT 1
- Wont compile with VS Code and PlatformIO HOT 1
- deque - Popping front crashes the arduino HOT 1
- Failed compilation of code using ArduinoSTL.h and array on Arduino Uno AVR Boards 1.8.3 HOT 11
- ISO C++1z does not allow dynamic exception specifications error HOT 1
- Accessing Inner pointer for std::vector
- Doesn't work with Teensyduino core
- Will Heap Data Structure be Implemented? HOT 1
- a lot of issues during compilation on plateformio / stm32 boards / arduino HOT 2
- Fails with latest IDE and Arduino HOT 2
- std::function not supported ??
- fails on wokwi.com due to the following
- multiple definition of `std::nothrow' HOT 13
- can be used in ESP32? HOT 1
- Doesn't compile with Arduino Nano 33 BLE (Nordic nRF52 platform)
- class object does not populate well outside scope
- This project is dead? HOT 2
- Multiple definitions of `std::nothrow` on `__AVR_ARCH__` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinostl.