0

Installed arduino 2.04 on new pc.win 10 pro. added all the libraries i need for my sketch. Specifically, Adafruit HX8357 v 1.1.15 Teensy 4 connected to this display https://www.adafruit.com/?q=hxd8357&sort=BestMatch

started writing code.

#include "Adafruit_HX8357.h"
#include <Bounce.h>

#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8 6
Adafruit_HX8357 tft = Adafruit_HX8357 (TFT_CS, TFT_DC, TFT_RST);

did a verify/compile on this. got this error:

C:\Users\Stefan\AppData\Local\Temp\.arduinoIDE-unsaved202331-9772-phra3o.j87e8\sketch_apr1a\sketch_apr1a.ino:7:39: error: expected primary-expression before '(' token
    7 | Adafruit_HX8357 tft = Adafruit_HX8357 (TFT_CS, TFT_DC, TFT_RST);
      |                                       ^
C:\Users\Stefan\AppData\Local\Temp\.arduinoIDE-unsaved202331-9772-phra3o.j87e8\sketch_apr1a\sketch_apr1a.ino:6:19: error: expected ')' before numeric constant
    6 | #define TFT_RST 8 6
      |                   ^
C:\Users\Stefan\AppData\Local\Temp\.arduinoIDE-unsaved202331-9772-phra3o.j87e8\sketch_apr1a\sketch_apr1a.ino:7:56: note: in expansion of macro 'TFT_RST'
    7 | Adafruit_HX8357 tft = Adafruit_HX8357 (TFT_CS, TFT_DC, TFT_RST);
      |                                                        ^~~~~~~
C:\Users\Stefan\AppData\Local\Temp\.arduinoIDE-unsaved202331-9772-phra3o.j87e8\sketch_apr1a\sketch_apr1a.ino:7:39: note: to match this '('
    7 | Adafruit_HX8357 tft = Adafruit_HX8357 (TFT_CS, TFT_DC, TFT_RST);
      |                                       ^

exit status 1

Compilation error: expected primary-expression before '(' token

Perhaps the syntax has changed? The same code compiled fine on previous machine with Arduino 1.89

aquagremlin
  • 3,515
  • 2
  • 29
  • 51

1 Answers1

0

Macros are simple text replacements, so Adafruit_HX8357 (TFT_CS, TFT_DC, TFT_RST) in the original post will expand to Adafruit_HX8357 (10, 9, 8 6) which is obviously invalid

Replacing #define TFT_RS 8 6 with #define TFT_RST (8, 6) gives this error:

C:\Users\Stefan\AppData\Local\Temp\.arduinoIDE-unsaved202331-9772-phra3o.j87e8\sketch_apr1a\sketch_apr1a.ino:6:18: warning: left operand of comma operator has no effect [-Wunused-value]
    6 | #define TFT_RST (8, 6)
      |                  ^
C:\Users\Stefan\AppData\Local\Temp\.arduinoIDE-unsaved202331-9772-phra3o.j87e8\sketch_apr1a\sketch_apr1a.ino:7:56: note: in expansion of macro 'TFT_RST'
    7 | Adafruit_HX8357 tft = Adafruit_HX8357 (TFT_CS, TFT_DC, TFT_RST);
      |                                                        ^~~~~~~

As the warning already says clearly, the macro will now be replaced to Adafruit_HX8357 (10, 9, (8, 6)) which is equivalent to Adafruit_HX8357 (10, 9, 8) because left operand of comma operator has no effect. However that's only a warning and compilation will complete successfully because the code still matches the second constructor even though it's not what you expected. The error in this case is different because they're all linker errors (undefined reference to ...):

c:/users/stefan/appdata/local/arduino15/packages/teensy/tools/teensy-compile/11.3.1/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Stefan\AppData\Local\Temp\arduino\sketches\FAF4EC7B25DF20D04735FE9464C6799E/..\..\cores\teensy_avr_teensy41_usb_serialhid,speed_600,opt_o2std,keys_en-us_300b8394b6e6311256a6e28440722b2d\core.a(main.cpp.o): in function `main':
C:\Users\Stefan\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\cores\teensy4/main.cpp:51: undefined reference to `setup'
c:/users/stefan/appdata/local/arduino15/packages/teensy/tools/teensy-compile/11.3.1/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Stefan\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.58.0\cores\teensy4/main.cpp:53: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status

The same linker issue occurred when you change #define TFT_RS 8 6 with #define TFT_RST 8, 6. You need to fix the linking issue. See What is an undefined reference/unresolved external symbol error and how do I fix it?

phuclv
  • 37,963
  • 15
  • 156
  • 475