Pages: [1]   Go Down
Author Topic: printf on DUE  (Read 1683 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,

I want printf support in my Due sketches and
have followed instructions as given at this link: http://playground.arduino.cc/Main/Printf
but I get compile failures ...
    '_FDEV_SETUP_WRITE' was not declared in this scope
    'fdev_setup_stream' was not declared in this scope

I have included stdio.h in the sketch (where the above are defined) but to no avail. If I change the
target board to, say, the Uno then the compile passes. What am I missing?

Thanks.
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It looks like stdout is already redirected to the programming port UART on the due - try this:
Code:
#include <stdio.h>

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

void loop() {
  printf("hello world!\n");
}

Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. You are right it works!
Any ideas on how I can add floating point printf() support?

Thanks.
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#undef printf
#include <stdio.h>
void setup() {
  Serial.begin(9600);
}

float q=0.1;
void loop() {
  q+=0.1;
  printf("hello world! %f\n",q);
}
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes working again. Thanks.
Where are you getting all this wonderful information from?

Thanks again.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have another issue with printf(). I only get output if the string is terminated with "\n"
how do I get output regardless of whether the string is terminated with a NEWLINE?

Where is the DUE printf support documented?
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

fflush(stdout); - this is standard printf behaviour and is not a bug.

There is no proper documentation (yet) as the Due is too new, but there is some documentation here: http://sourceware.org/newlib/ Not all of it will be relevant to the Due.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am unable to get an output with printf() using the code as suggested in earlier post for this message.

#include <stdio.h>

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

void loop() {
  printf("hello world!\n");
}

Can you tell me what particular file to include in my arduino sketch to get printf() support. I am using Arduino IDE 1.5.2 with Eclipse.
Logged

Pages: [1]   Go Up
Jump to: