C stdout to OpenMV ide serial port?

Sorry to disturb you again.
Is there a way to send C stdout to the screen? I’m trying to debug some of the code I’ve written on the c side and the only way I currently know of accessing intermediate variables is through defining them in on the python side then outputting them there, which takes a while.

Thanks!

#include “stdio.h”

Then put printf anywhere in your code. This get printed out the same serial port regular messages go - as in they will show up in the IDE.

Also, make sure to add \n to the end of the string.

Dumb mistake, I didn’t have “stdio.h” in my code yet.
Still though it’s not printing out to the screen. My IDE is just the generic one installed from the .run, would that affect this?

That one should work. The print statements go to the serial terminal in the IDE.

I was looking in the terminal but must not have been actually executing the part of the code with the print in it. I was trying to call it in apriltag.c in a place I thought got executed.
As a test I switched back to master branch, added #include “stdio.h” and printf(“in fast_roundf\n”); to fmath.c, line 57 (in the fast_roundf function). Recompiled, re-flashed the firmware to my OpenMV M7, and it would print out to the serial terminal so much it actually would slow down the IDE to the point it wouldn’t really work.
So back to find out why that part of the code isn’t executing (which also explains the bug I’m trying to fix!)
Thanks!

Yeah, don’t put print statements in loops :slight_smile:.

OK this took me way longer than it should have and I still don’t quite understand, but I can now print from apriltag.c.
I was correct initially about the printf statements I added being executed in apriltag.c, but no printing was happening.
The problem was about line 220 in apriltag.c: #define printf(format,…)
Removing that #define statement I tried on day 1, but it caused a bunch of errors with implicit conversions which I wasn’t able to fix elegantly.
I eventually “fixed” it by commenting out any of the printf’s where problems occured (the two main ones being in printing matd’s).

That’s some lovely code right? Only took a week to port to the OpenMV Cam.

It was the first OpenMV cam code I looked at - terrified me, and to some extent still does.
I give up for now. No matter what I seem to do, I can’t use apriltag.c to print values from my matrix (I’m trying to implement a pseudo-inverse). It always gives me that same double conversion error (which should really just be a warning).
Anyways I’ve tried typecasting, I’ve tried just declaring a float or double variable and even things as easy as passing:
float dummy = 10.0;
printf(“%f”, dummy);

or
double dummy = 10.0;
printf(“%f”, dummy);

Still gives me that error. It’s baffled me. I can only assume something in one of the #include statements is messing with printf. For now I’ll just multiply my values by 10000 and use them as "int"s

Hi, the float gets converted to double implicitly when calling printf, you just need to convert to double explicitly (Cast):

printf("%f", (double) dummy);

Okay I see the problem:

#define double float

Don’t comment that.

Thanks iabdalkader, I should have seen that. That gave a large number of errors for conversion types. Fixed those by typecasting to doubles.
It’s now giving 520 errors about undefined references to “__aeabi_dadd”, “__aeabi_dsub”, etc. From online help, looks like we’re not using the libgcc.a file, which I guess should be a part of the gcc-arm-none-eabi package?
I think we’ve pushed this one about as far as it needs to go, this isn’t a high priority. Still, if you care to look at those errors, I pushed my changes to a branch on my git fork: GitHub - jkairborne/openmv at printf_apriltag_fix

Best

Sorry, the
#define double float

line was never commented out in my code. I commented out the
#define printf(format, …)
line but that was it. In my post from a few minutes ago I commented out the printf and the "double float’ defines.
Anyways like I said, this should be very low on the priority list. By multiplying out to an integer I’m able to print out the values from my matrix I need.

Yes I understand. I meant this line is the main problem:

#define double float

This replaces every double with float, so even if you cast to double printf expands to:

printf("%f", (float) dummy);

That’s why you still get errors. There’s no easy fix for now.