Redirecting Stdout to Arduino Serial / RF24's printf.h library

Hi !

I downloaded the code & examples of the RF24 library : https://github.com/maniacbug/RF24/blob/master/nRF24L01.h When I tried to compile, I got those "assembler messages" : http://pastebin.com/LtiH2Fk1

When I comment the "#include printf.h" and the printf instructions, everything is fine, but obviously I don't get any messages on the serial out.... and it pains me since there is useful debug infos inside the RF24 lib. The printf.h 's source : http://pastebin.com/BuFxQT8T

I guess that the code was written for windows, and I have to modify it in order to make it works on my Ubuntu .... but I don't get compiler errors that I could process. Or I have to modify my computer's stdout config ... and don't have a clue where to begin. I'm very new to Arduino, and very very older than I was when I got my C++ classes ^^

Bonus question : How can the compiler fail on the assembled code ? Isn't it itself that's generating this source ?

My config : OS : Ubuntu 12.04 Arduino IDE : 1.0.5

I can't figure out any cause for your problem. ManiacBug's printf code is quite neat and works in my experience. I can't see any reason why it wouldn't work for you, and I can't think of any reason why the failure symptoms would include assembler errors. Is it possible you have done a copy/paste into a non-ASCII file, or something like that?

I tried to copy the code and paste in a plain text editor : same result. I got the code from the github repo. Tried also to remove an reinstall libavr, witch contains fdevopen if I'm not wrong, but I got the same errors.

But I'm short on ideas now ...

Now I'm confused.

I removed completely avr-libc & gcc-avr, which removed arduino-core, then rebooted, and tried to compile a sketch : the IDE doesn't complaint about it, and there is the same error messages.

Now, I'm REALLY confused.

I renamed the file "printf.h", witch was in the same dir than the test code, and modified the include statement accordingly : it's compiling, but the output on the serial monitor is unreadable, filled with char like these : "ò¸Ø²Ó°?Ð?Û?ZU#?;@?".

If I let the file renamed, and put in the include statement the old name "printf.h", I get the assembler messages.... where does it get it ??

When I put the same baudrate in the serial monitor than in the code, mysteriously, the output became readable ..... :roll_eyes:

So I will go on with this renaming "fix", but if somebody is passing by and want to explain why and how it's working, he will make al least one person very happy.

Based on my reading for this problem of Printf causing problems it is because Printf is not enabled as part of the default IDE, you have to modify some of the core files to get printf to work. Like yourself I want the program to work without having to do all the hacking, it is driving me crazy. I know open source brings everyone from different background and different installed IDE setups too! I am trying to learn to code with the downloaded files, but when My head hits a hacking brickwall I am completed stumped. So yes if there is an easyway around it do help, once I get mine working I then need to modify a friends who has less programming skills than me.
Cheers Dave

There is no need to modify any core files. The RF24 lib’s print functions are built on the standard AVR libc functions.

If you need to rename printf.h before it works correctly then this implies that there is another copy of printf.h somewhere which is conflicting with the copy provided by the RF24 lib example. If you want, it should be easy enough to find that by a file search.

Obviously, you have to configure the serial monitor to use the same serial settings as the Arduino in order to get sensible output, and if you have the settings wrong that’s nothing to do with this problem.