Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Using stdout rather than arduino Serial print (Read 5712 times)
JoeMcC
Junior Member
**
Offline


Posts: 27
Joined: Oct 30th, 2016
Using stdout rather than arduino Serial print
Mar 26th, 2017 at 3:29pm
Print Post  
Hello, 
First, thank you for creating this awesome program that allows me to program arduino in a professional IDE. I dont think I could last to long with the arduino ide. 

My question is, I would like to use the C library of setting up a stream and my own getchar and putchar  routines  instead of using arduinos serial print commands. 

My goal is to stick with using the C language since i know it, and to keep code size small,  but use Arduino libraries when necessary. 

In an arduino project the compiler chokes on the line
static FILE mystdout = FDEV_SETUP_STREAM(USART_putchar, USART_getchar,_FDEV_SETUP_RW);

giving the err msg
Print.h:24: In file included from
Stream.h:26: from
HardwareSerial.h:29: from
arduino.h:232: from
Test1.ino: from
Test1.ino:16: sorry, unimplemented  non-trivial designated initializers not supported
   FILE mystdout = FDEV_SETUP_STREAM(USART_putchar, USART_getchar,_FDEV_SETUP_RW)
Test1.ino:16: sorry, unimplemented  non-trivial designated initializers not supported
Test1.ino:16: sorry, unimplemented  non-trivial designated initializers not supported

But the code runs fine if it is the project is started as a non-arduino project (ie avr project which uses GCC)

Any help is appreciated.

Joe McCarron
« Last Edit: Mar 26th, 2017 at 4:26pm by JoeMcC »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using stdout rather than arduino Serial print
Reply #1 - Mar 26th, 2017 at 5:30pm
Print Post  
Thanks for the message.

Does this guide help?

http://www.appelsiini.net/2011/simple-usart-with-avr-libc
  
Back to top
IP Logged
 
JoeMcC
Junior Member
**
Offline


Posts: 27
Joined: Oct 30th, 2016
Re: Using stdout rather than arduino Serial print
Reply #2 - Mar 26th, 2017 at 6:21pm
Print Post  
The code is pretty much identical and runs in the avr studio environment with out error messages so the 
redirection of std out is known in that tool chain.

It is just that I get the error msgs that I posted when running as an arduino project.
I looked at that article and I am doing the same except I get errors when building. 
It is like the tools do not know where the stdio.h file is located

If I go to Project->Properties->Toolchain->General      The default include paths include the path to the standard
C library stdio.h and the rest of the .h files so the tools know where those files are.

I do not understand the error msg as it is referencing the arduino files and not standard C files.

 


« Last Edit: Mar 26th, 2017 at 6:23pm by JoeMcC »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using stdout rather than arduino Serial print
Reply #3 - Mar 26th, 2017 at 6:29pm
Print Post  
Hi,

Ignore the toolchain properties they are for intellisense only. 

You should switch on "vMicro>Compiler>Verbose", "show build properties" and "show build folder" to see the actual build info.

I suspect you need to override the arduino main but you could first try initializing your code before the arduino.h is #included. By default, the arduino.h is included automatically in a temp build folder when the .ino files are combined. The c++ prototypes are also added at that stage.

You can add a project_name.cpp to your project. Leave a project_name.ino in the project however it can be empty but will be ignored. All .ino files will be ignored if you have a project_name.cpp

Before adding a project_name.cpp to your project make a build with the options described above enabled. You will then find an example project_name.cpp in the build folder.

Let me know if that makes sense and if it helps to have more control over the project_name.cpp.
  
Back to top
IP Logged
 
JoeMcC
Junior Member
**
Offline


Posts: 27
Joined: Oct 30th, 2016
Re: Using stdout rather than arduino Serial print
Reply #4 - Mar 26th, 2017 at 9:51pm
Print Post  
Ok, so I made the changes to the switches as you recommended.
So I generated a cpp file but I had to open either a project.ino or project.cppproj to be able to compile again.
Yes, even if the project.ino was empty it would still have to be selected. After adding the project.cpp file I did another build but with the same results  error msgs   

Test1.ino: In file included from
stdio.h:395: sorry, unimplemented  non-trivial designated initializers not supported
Test1.ino:10: note  in expansion of macro FDEV_SETUP_STREAM
   static FILE mystdout = FDEV_SETUP_STREAM(USART_putchar, USART_getchar,_FDEV_SETUP_RW)
stdio.h:395: sorry, unimplemented  non-trivial designated initializers not supported
Test1.ino:10: note  in expansion of macro FDEV_SETUP_STREAM
   static FILE mystdout = FDEV_SETUP_STREAM(USART_putchar, USART_getchar,_FDEV_SETUP_RW)
stdio.h:395: sorry, unimplemented  non-trivial designated initializers not supported
Test1.ino:10: note  in expansion of macro FDEV_SETUP_STREAM
   static FILE mystdout = FDEV_SETUP_STREAM(USART_putchar, USART_getchar,_FDEV_SETUP_RW)
Error compiling project sources

Thanks for  your help.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using stdout rather than arduino Serial print
Reply #5 - Mar 27th, 2017 at 12:27am
Print Post  
Yes that is correct that the project_name.ino must still be included in the project. This is how we distinguish between arduino and standard visual studio c++

Click "vMicro>Toggle>Hidden Files". You should see a _micro_api-readonly virtual folder added to the project. It should contain a main.cpp. Maybe that is the place for you to override things, it is loaded before all the other code.
  
Back to top
IP Logged
 
JoeMcC
Junior Member
**
Offline


Posts: 27
Joined: Oct 30th, 2016
Re: Using stdout rather than arduino Serial print
Reply #6 - Apr 2nd, 2017 at 3:21pm
Print Post  
The only way I found to get around the issue was to:

Use sprintf to get desired output as a string, then either use serial.println 
or in my case a function that just sends characters to the serial port

Arduino can not print floats either as it takes to much memory. 

A work around is to use dtostrf  which is from the standard C library and it 
converts a double to a string.  dtostrf increases memory usage by 1.5k so it is rather bloaty.
But if you need to print floating point numbers, that will work.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Using stdout rather than arduino Serial print
Reply #7 - Apr 2nd, 2017 at 3:32pm
Print Post  
Thanks, good update.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint