PlatformIO Community

Feerick ISS- here's a crazy one

I couldn’t build the ISS tracker Feerick made, because PIO wouldn’t recognize the Adafruit 1306 declaration starting at line 36. It’s stubborn It won’t budge.

So I moved the OLED block, the whole #ifdef statement ahead of the OLED declaration.
Now PIO has a problem with ‘long,’ now at line 36.

Adafruit_SSD1306 is redlined. ‘Long’ was redlined when I moved it.

ISS

src\main.cpp:33:1: error: expected ‘,’ or ‘;’ before ‘Adafruit_SSD1306’
33 | Adafruit_SSD1306 display(128, 64, &Wire, 8);
| ^~~~~~~~~~~~~~~~
src\main.cpp: In function ‘void loop()’:
src\main.cpp:209:5: error: ‘display’ was not declared in this scope; did you mean ‘delay’?
209 | display.clearDisplay();
| ^~~~~~~

In my original version of the ISS Tracker, which Peter created, I have this at line 36:

#ifdef USE_OLED
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#endif

You appear to have messed with edited this. Goiven that you have simply hard coded the screen dimensions, that’s most likely not the problem. I note from the OLED_RESET comments (where OLED_RESET is defined, near the top of the file,), that it’s the reset pin for the OLED, or -1 if not using a reset. Are you using pin 0 to reset the OLED?

What error do you get which makes you say that it refuses to accept the code you have supplied?

Have you got all the required header files #included? Mine are as follows, I can’t see all of yours from the screen shot:

#include <Arduino.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <Adafruit_NeoPixel.h>

#ifdef USE_OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#endif

#include <TimeLib.h>
#include <Timezone.h>

#include "secrets.h"

It’s possible that you have somehow edited out a required one.

What board are you using please? The platformio.ini file has a few options, D1_MINI, NODEMCU, d1_mini_OLED_17pixels – the latter defining USE_OLED which is required to compile the line you are complaining about!

Here’s my compilation result:

norman@Hubble2:/data/SourceCode/ISS-Notifier$ pio run -e d1_mini_OLED_17pixels
Processing d1_mini_OLED_17pixels (board: d1_mini; platform: espressif8266@2.6.2; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/d1_mini.html
PLATFORM: Espressif 8266 (2.6.2) > WeMos D1 R2 and mini
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20704.0 (2.7.4) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 36 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit BusIO> 1.11.4
|   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <Adafruit GFX Library> 1.10.15
|   |-- <Adafruit BusIO> 1.11.4
|   |   |-- <Wire> 1.0
|   |   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <Adafruit NeoPixel> 1.10.4
|-- <Adafruit SSD1306> 2.5.3
|   |-- <Adafruit GFX Library> 1.10.15
|   |   |-- <Adafruit BusIO> 1.11.4
|   |   |   |-- <Wire> 1.0
|   |   |   |-- <SPI> 1.0
|   |   |-- <Wire> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|-- <ArduinoJson> 6.19.4
|-- <Time> 1.6.1
|-- <Timezone> 1.2.4
|   |-- <Time> 1.6.1
|-- <ESP8266HTTPClient> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
|-- <SPI> 1.0
|-- <Wire> 1.0
Building in release mode
Retrieving maximum program size .pio/build/d1_mini_OLED_17pixels/firmware.elf
Checking size .pio/build/d1_mini_OLED_17pixels/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  35.4% (used 29036 bytes from 81920 bytes)
Flash: [===       ]  29.3% (used 305892 bytes from 1044464 bytes)
================================================================================================================ [SUCCESS] Took 0.65 seconds ================================================================================================================

Environment            Status    Duration
---------------------  --------  ------------
d1_mini_OLED_17pixels  SUCCESS   00:00:00.652

Which actually makes me thing, because you have moved the declaration of the !display variable outside the #ifdef USE_OLED#endif lines, then you are probably compiling for one of the boards without an OLED - NODEMCU or D1_MINI.

It’s obvious that you have been messing editing the original source files, I suspect you have bolloxed something important. I would suggest two things:

  • When you download the original zip files into your source code directory, create a new folder for the source, when you have extracted it, type the command git init which will, if you have git installed, startup a new version control environment.

  • Before starting on an editing session, type git checkout -B working to create a “working” branch, separate from the main branch you downloaded, and now you can do all your work without affecting the original.

If you mess up the working stuff, all you have to do is bin the branch git checkout main then git branch -D working and start again. Never edit in the main branch, that’s your safety net!

Obviously, there’s a little more to git than this, but if you need one, I’ll do you a tutorial to get you started.

HTH

Cheers,
Norm.

1- this was the same program you see, but I modified the OLED display.

2- ‘display’ was not declared when I opened the file after a year away. I did delete the ifdef while poking around, trying to get the stupid ‘display’ to declare. The OLED is always going to be in use anyway. PIO wouldn’t build the as-was file, because it wouldn’t accept the SSD1306 declaration.

So that’s where I am. (the fire has kinda gone out, since the ISS doesn’t pass over me, but I have three built, running on West Coast code that can’t log on to my WiFi).

Can you please zip up your project folder and either send it to me, Private message me for my email, or put it on pastebin, dropbox or similar for me to pick up. Thanks.

Cheers,
Norm.

All you needed was #define USE_OLED in the code above the ifdef, or added as a build flag in the platformio.ini file.

Cheers,
Norm.

I just copied the original program from GitHub.
It still gets hung up here:
39 long riseTime = 0; // Time the ISS will rise for current position

src\main.cpp:39:1: error: expected ‘,’ or ‘;’ before ‘long’
39 | long riseTime = 0; // Time the ISS will rise for current position
| ^~~~
src\main.cpp: In function ‘void loop()’:
src\main.cpp:219:26: error: ‘riseTime’ was not declared in this scope
219 | timeUntilFlyover = riseTime - currentTime;
| ^~~~~~~~
src\main.cpp: In function ‘bool getNextPass()’:
src\main.cpp:438:7: error: ‘riseTime’ was not declared in this scope
438 | riseTime = response[0][“risetime”]; // save start time of the next flyover
| ^~~~~~~~
*** [.pio\build\esp12e\src\main.cpp.o] Error 1
============================= [FAILED] Took 6.23 seconds ===========

Error on line 39, expected ; before long. What’s line 38 like? Or the previous non blank line. There’s a missing ; there I suspect.

Cheers,
Norm.

"```
#endif

long riseTime = 0;

Hmm, notbenough, try posting all the lines above the error line please. There’s possibly something inside the #if... that ends above line 39, or, before the #if... line that opens it, that’s missing a ;. Thank.

Cheers,
Norm.

36 is the first ‘real’ line. Everything above that is #include.

/**
 * Original code written by pollux labs, 2020
 * URL: https://gist.github.com/polluxlabs/1ba7824175c5e011565bd61af2fd1c6b
 */
// #define USE_OLED
#define SCREEN_WIDTH 128   // OLED display width, in pixels
#define SCREEN_HEIGHT 32   // OLED display height, in pixels
#define OLED_RESET -1      // Reset pin # (-1 if sharing Arduino reset pin or no reset pin)
#define OLED_I2C_ADDR 0x3C // Displays I2C address
#define OLED_ROTATION 0    // 0 = 0, 1 = 90, 2 = 180 or 3 = 270 (degree rotation)

#define NEOPIXEL_PIN D3
#ifndef NUM_OF_NEOPIXELS
#define NUM_OF_NEOPIXELS 12
#endif
#define STATUS_LED LED_BUILTIN
#define STATUS_LED_INVERTED true

#include <Arduino.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <Adafruit_NeoPixel.h>
#ifdef USE_OLED
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#endif
#include <TimeLib.h>
#include <Timezone.h>

#include "secrets.h"

#ifdef USE_OLED
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#endif

long riseTime = 0; 

Thanks Joe,

I rather suspect that two things might be happening here, looking at this code you have posted.

  • USE_OLED is not defined, so the code doesn’t attempt to create an Adafruit_SSD1306 display.
  • Something in your secrets.h is missing a semi-colon!

I’m also now wondering if, possibly, it was that missing semi-colon that caused your display errors in a past posting, when USE_OLED was defined (or removed altogether?)

Timezone myTz(usEDT)
The last line in secrets.h lacks the semicolon.

MF just built like a champ.
Thank you. And congratulations on finding the needle in the haystack- and you didn’t see the haystack. Fun

1 Like

Why is there an #ifdef for the OLED? I don’t want that.
The display lines are all grayed out.
Serial is giving me the next passover tiime, but the OLED is stuck on ‘Connect to WiFi.’

All my life I’ve been fixing things! Honda motorbikes, Yamaha Outboard Motors, GRP Boats, Volvo Penta Marine Diesels etc. Then I got into computers when I bought a ZX-81 and taught myself programming. I got a job programming but soon ended up being the “go-to” guru (!) for unsolvable problems. After that, I was “promoted” to Oracle DBA and after learning about those databases, I was once again, fixing stuff.

Looks like I haven’t lost the knack, yet.

Anyway, I’m glad we got that sorted, but it’s just a matter of reading the error messages and working backwards. Usually, the first error you see is the cause of many of those that follow until the compiler gets back on track and the code starts to make sense again. Fix the first error and many of the others will vanish.

However, it’s always good to have an additional pair of eyes, sometimes.

There’s an #ifdef because Peter’s code is different from Pollux Labs original, which was written for some Neopixels, not a screen. Peter changed it to use a screen. If you read the platformio.ini file, you will see quite a few different environments ([end:xxxxx]):

  • Nodemcu - which doesn’t define USE_OLED;
  • D1_mini - which doesn’t use USE_OLED;
  • D1_mini_OLED_17pixels - which does define USE_OLED as part of the build_flags.

The default environment is the D1_mini.

So, Peter amended the code but some boards look to still use only the Neo pixels – D1_mini and nodemcu – but some boards can use the OLED display – D1_mini_OLED_17pixels – which I assume is Peter’s own board.

If the #ifdef USE_OLED line was missing, then the code would always attempt to create an OLED screen device/class/instance and this would barf on those boards that do not have an OLED.

The lines are probably greyed out due to syntax highlighting in VSCode, or, if VSCode has somehow scanned the platformio.ini file, found your default board etc etc, and determined that USE_OLED is not actually defined. I’m not aware of how the syntax highlighting works in VSCode, sorry.

The #ifdef is not harming your code, it’s protecting it is you inadvertently compile the code for a board without an OLED attached.

In the loop() function, and if USE_OLED was defined, this is displayed when the state machine variable, currentState, is still at the WIFI_INIT stage. Once connected to WiFi, this state changes to START.

In the code for the START state, the OLED is not changed in anyway. The stats is changed to GET_TIME.

In the code for GET_TIME, the OLED display should be cleared, just after Serial Monitor says “Getting the current time (UTC)…” – at this point, the OLED is updated to display “Get UTC Time”. This will repeat until the time is successfully obtained over WiFi. The state will then change to GET_NEXT_PASS.

In this state, GET_NEXT_PASS the OLED should be reading “Get Next ISS Pass” and Serial Monitor should display “Looking up next ISS flyover time…”. This will repeat until the next pass time is successfully fetched from the interwebs over WiFi.

If the next pass time is fetched, only the Serial Monitor is updated with the time from now, and the duration of the next pass. The OLED is not changed.

The state then changed to WAIT_FOR_PASS.

The code for which displays a count down to the next ISS pass, in the Serial Monitor, and on the OLED entitled “Next pass in hh:mm:ss”

And so on and on and on. If your OLED is only showing the “Connecting to WiFi” message, then, if you are using Peter’s original code, the chances are that your board is:

  • Not connecting to WiFi;
  • Is in a restart loop, because that’s what the code does when it can’t connect.

Cheers,
Norm.

Grayed out- I searched for ‘display’, and only two instances were reported. But there were actually about 55 'display’s. They were just in the #ifdef sections.

I deleted all the #ifdefs, and the OLED is running well.
This all worked out. Worked out for me. Hooray.

1 Like

Hooray indeed.

Have fun.

Cheers,
Norm.