Go Down

Topic: Problems when using GFX Library with EPD (Read 84 times) previous topic - next topic

cweinhofer

I'm creating a device that downloads temperature data from a IoT logging server and displays it on a small screen. The hardware is the LOLIN D32 Pro and the LOLIN 2.13 EPD (Electronic Paper Display). The libraries used are ThingSpeak, LOLIN_EPD, and Adafruit_GFX.

In programing the display, I am encountering two strange problems.

1) I want the display to have large numbers, so I used the included tool to created a 60pt version of the FreeSans font that is part of the GFX library. If I try to put the custom font file in the sketch folder and include it with
Code: [Select]
#include "FreeSansBold60pt7b.h"
 I get the error:

Code: [Select]
sketch\7_EPD.h: In function 'void writeEPD()':

7_EPD.h:7:15: error: 'FreeSansBold60pt7b' was not declared in this scope

  EPD.setFont(&FreeSansBold60pt7b);

               ^


However, if I copy the custom font file to the Fonts folder of the GFX library and include it as if it were one of the provided fonts with
Code: [Select]
#include <Fonts\FreeSansBold60pt7b.h>
, it works just fine. Any idea of what's going on here?

2) When the numbers are displayed on the screen, they are mostly off the screen. I used the
Code: [Select]
EPD.getTextBounds
 function provided in the library to see what was going on and the function reports that the text is using the start coordinates of 5,-85 (even though the current cursor position is set to 0,0). If I use the numbers from
Code: [Select]
EPD.getTextBounds
 to set
Code: [Select]
EPD.setCursor
 at 0,85 the text displays fine, but I would like to know why it's starting out at a high negative number?

For reference, the problem didn't just happen with my custom font, it was happening the same way when I was using one of the provided fonts
Code: [Select]
EPD.setFont(&FreeSansBold12pt7b);
EPD.setTextSize(5);


In case you need it for reference, I've attached the complete sketch below.

david_prentice

#1
Mar 24, 2019, 04:02 pm Last Edit: Mar 24, 2019, 04:11 pm by david_prentice
It would find "FreeSansBold60pt7b.h" in your sketch.

You have broken all the conventions.
e.g.  putting executable code in H files
e.g.  including "FreeSansBold60pt7b.h" after it was referenced

The Arduino will happily insert "Arduino.h" and make forward references etc from the main INO file.

You can have multiple INO files.   They will be concatenated to the main INO but the "forward references" do not work.

You can have CPP files, INO files, H files, C files, even S files.

Only the main INO file gets the Arduino kludge treatment.
Subsequent INO files will get concatenated to the main INO.

CPP files must obey all the rules for C++.   e.g. declare references etc.
C files must obey the rules for C.
S files must obey the rules for ASM.

I suggest that you rename your executable files with the appropriate extension e.g. INO or CPP

Regarding BIG fonts.   The GFX code uses int8_t for yOffset.   e.g. you draw FreeFonts from the Base Line.   The top of letter H will be -85 pixels from the base line. Underscore _ starts below the base line.

David.

p.s. I like the idea that Arduino parses the main INO file to locate libraries from the header file locations.    Adding search paths,  libraries etc to a regular C++ project is painful for newcomers.

Inserting forward references is WRONG.   A newcomer should learn about the C++ rules.
Multiple INO mean that it is not obvious which functions or symbols were declared in which order.

cweinhofer

Thanks for the help.

I didn't stop to think through the logic of the part of the sketch where the font file is being referenced coming a few lines before the file itself was included (I'm new to programing and still getting used to the idea of everything being executed in precise order.) Nor did it dawn on me that the include for the built-in fonts being a few lines earlier would make the difference. I moved the custom font include up and the error went away.

Same goes for the font baseline issue. I started out using the classic font and added the custom font as the last thing in the sketch development. I guess I must have missed the part where the documentation says that these two use different baselines (despite the nice little graphic :( ).

I want to understand more of what you were saying about my sketch's structure, but it's kind of off topic for this thread. Would you prefer I put follow up questions about that in a new thread or a PM?

Go Up