'display' does not name a type (error message)

  • Thread starter Deleted member 750607
  • Start date

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
I got some new hardware...esp8266 12 e. My sketch is meant to parse data from a web site that tracks the International space station and print it in my small OLED. I have it working but only doing one reading in the serial monitor, then disconnecting. Getting updates automatically is ideal, but first I am trying to print the coordinates to my OLED. I have made some code for this purpose...theres a header file too...listed after the main code excerpt.

Im getting 'display' does not name a type for an error. Ive fiddled a lot with semi colons and brackets, so I don't think that's the issue. Also I am confident I have all my libraries downloaded, because the sketch worked when I was just printing to serial monitor...and it also the same corresponding libraries worked when I was printing other stuff on my OLED in other sketches that had nothing to do with this project.

Here's my code: (the error is on the last line which is "display.display ();"

MAIN code:
#include "USE_ESP8266.h"
#include <TimeLib.h>
char server [] = "api.open-notify.org";
void digitalClockDisplay();

#include <Adafruit_SSD1306.h>
#include <splash.h>
#include <Adafruit_GrayOLED.h>
#include <gfxfont.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <SPI.h>
#include <Wire.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C

const int OLEDPin = D2;

void setup ()
{
display.begin(SSD1306_SWITCHCAPVCC, 0X3C);
display.clearDisplay ();

  Serial.begin(115200);
  if (!configureNetwork()) //start the network
  {
    Serial.println("Failed to configure the network");
    while(1)
    {
      delay(0); //halt; ESP8266 does not like infinity loop without a delay
    }
   }
int ret = client.connect(server, 80);
if (ret == 1)
{
  Serial.println("Connected");
  client.println("GET /iss-now.json HTTP/1.0"); //the http request
  client.print("Host: "); client.println(server);
  client.println("Connection: close");
  client.println();
}
else
{
  Serial.println("Connection failed, error was: ");
  Serial.print(ret, DEC);
  while(1)
  {
    delay(0); //halt; esp8266 does not like infinite loop without a delay

  }
}
}

char timestampMarker[] = "\"timestamp\":";
char posMarker[] = "\"iss_position\":";

void loop ()
{
  if (client.available())
  {
    String id = client.readStringUntil('"');
    if (id.equals("timestamp")) //start of timestamp
    {
      if (client.find(':')) //a ":" follows each identifier
      {
      unsigned long timestamp = client.parseInt();
      setTime(timestamp);
      digitalClockDisplay();
  
      }
      else
      {
        Serial.println("failed to parse timestamp.");
      }
    }
    if (id.equals("iss_position")) //start of position data
    {
      if (client.find(':'))
      {
       while(client.peek () != '}' && client.find('"'))
       {
        String id = client.readStringUntil ('"');
        float val = client.parseFloat ();
        client.find ('"');
        Serial.print(id + ":"); Serial.println(val, 4);
       }
      }
      else
      {
        Serial.print("Failed to parse position data.");
      }
    }
  }
if (!client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while(1)
  {
    delay (0); //halt, esp8266 does not like loop w/o delay
  }
}
}
String padDigits(int digit)
{
  String str = String("0") + digit; //put a zero in front of digit
  return str.substring(str.length() - 2);
}

void digitalClockDisplay ()
{
  String datestr = String(year()) + "-" + padDigits(month()) +
                   "-" + padDigits(day());
  String timestr = String(hour()) + ":" + padDigits(minute()) +
                   ":" + padDigits(second());
  Serial.println(datestr + " " + timestr);
}

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println(datestr + " " + timestr);
  display.display();
  }
}
}


HEADER file:
#include <SPI.h>
#include <ESP8266WiFi.h>

#include <Adafruit_SSD1306.h>
#include <splash.h>
#include <Adafruit_GrayOLED.h>
#include <gfxfont.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <SPI.h>
#include <Wire.h>


const char ssid[] = "Home25";
const char password[] = "6033216098";
WiFiClient client;

bool configureNetwork()
{
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay (1000);
    Serial.print("Waiting for connection to "); Serial.println(ssid);
  }
    return true;
  }
 
Last edited by a moderator:

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
Also... I switched the problematic section to this

Code:
{
  Adafruit_SSD1306 display.setTextSize(1);
  Adafruit_SSD1306 display.setTextColor(WHITE);
  Adafruit_SSD1306 display.setCursor(0,0);
  Adafruit_SSD1306 display.println(datestr + " " + timestr);
  Adafruit_SSD1306 display.display();
}

and when I do that, the error is "expected unqualified-id before '{' token" ...on the line of the top bracket
 

djsfantasi

Joined Apr 11, 2010
7,843
The object display must be declared before you can use its methods. In your first sketch, before you reference “display” as in “display.begin()”, you need to define display. Like this:
Adafruit_SSD1306 display;​

Then you can use the methods associated with “display”.

display.begin(SSD1306_SWITCHCAPVCC, 0X3C);​
display.clearDisplay ();​
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
The object display must be declared before you can use its methods. In your first sketch, before you reference “display” as in “display.begin()”, you need to define display. Like this:
Adafruit_SSD1306 display;​

Then you can use the methods associated with “display”.

display.begin(SSD1306_SWITCHCAPVCC, 0X3C);​
display.clearDisplay ();​
now it says "stray '\342' in program"
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
Sounds like another problem.
I got past that point, but its saying error compiling for NODE MCU....etc...so im assuming my code is somehow flawed probably in structure...I really just slapped together some different parts from other sketches and hoped for the best. I think something is really wrong with the whole thing...
 

djsfantasi

Joined Apr 11, 2010
7,843
I got past that point, but its saying error compiling for NODE MCU....etc...so im assuming my code is somehow flawed probably in structure...I really just slapped together some different parts from other sketches and hoped for the best. I think something is really wrong with the whole thing...
I agree. That line appears to be the object definition I was referring to. This, if you added the line from my post, you’re duplicating the definition.

Sorry, I can’t help much more today... it’s late and bedtime and I’m on vacation so can only respond in the evening (my time).
 

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
I agree. That line appears to be the object definition I was referring to. This, if you added the line from my post, you’re duplicating the definition.

Sorry, I can’t help much more today... it’s late and bedtime and I’m on vacation so can only respond in the evening (my time).
thanks for the help. im also retiring for the night, until tomorrow. surprisingly difficult to find the help im looking for online.
 
How about the whole code? The stray '\342' in program pretty much means somewhere there is the combination '\342' in the program and the compiler doesn't know what to make of it.

'expected unqualified-id before '{' token' is usually due to either a function declaration missing, or a missing if, else, for, etc...

More or less your formatting is off somewhere and until you get that right it's going to show more errors than there really are.
 
Top