Go Down

Topic: serial does not name a type error on compiling (Read 8167 times) previous topic - next topic

DKenp

Im trying to compile a script and i get the error "serial does not name a type" and the line Serial.begin(9600); gets highlighted. The script is one for displaying to an Oled which i butchered from an example script because i was just wanting the bit in the script which out puts a value (which I'm taking from a GPS unit)

The script is from the Makerhawk Oled example library.

Cheers

TheMemberFormerlyKnownAsAWOL

Does it say "serial" or "Serial"?

Post your code.

Post the exact error message.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

DKenp

I've so butchered the code I don't know what the original was when I first posted. what's left is the following.

Which of course won't compile. It gets the error message "expected initialiser before void"



Code: [Select]


void setup()
{
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);



 

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
{display.begin(SSD1306_SWITCHCAPVCC, 0x3C); { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

void loop()


 
void testdrawchar(void) {
  display.clearDisplay();

  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.setCursor(0, 0);     // Start at top-left corner
  display.cp437(true);         // Use full 256 char 'Code Page 437' font

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  for(int16_t i=0; i<256; i++) {
    if(i == '\n') display.write(' ');
    else          display.write(i);
  }

  display.display();
  delay(2000);
}

void testdrawstyles(void) {
  display.clearDisplay();

  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(0,0);             // Start at top-left corner
  display.println(F("Hello, world!"));

  display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
  display.println(3.141592);

  display.setTextSize(2);             // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.print(F("0x")); display.println(0xDEADBEEF, HEX);

  display.display();
  delay(2000);
}


      }
    }
  }
}

TheMemberFormerlyKnownAsAWOL

#3
May 07, 2020, 10:35 pm Last Edit: May 07, 2020, 10:37 pm by TheMemberFormerlyKnownAsAWOL
Again, post the exact error message.
All of it.

Unusual to put your includes inside a function, but, what the heck.

And please, use the auto format tool before you post code.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

DKenp

I cant re run the compiling of the script because i don't have my first attempt at editing out all the stuff from the old example script. This is because i think the script became autosave as i messed with it further to try and fix it so my original question is redundant now. Sorry.

My latest attempt to extract a hello world script from the example script is the following.

Code: [Select]



#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

display.clearDisplay();

display.setTextSize(1);             // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE);        // Draw white text
display.setCursor(0, 0);            // Start at top-left corner
display.println(F("Hello, world!"));

display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
display.println(3.141592);

display.setTextSize(2);             // Draw 2X-scale text
display.setTextColor(SSD1306_WHITE);
display.print(F("0x")); display.println(0xDEADBEEF, HEX);

display.display();
delay(2000);
}


}


This, of course does not compile either getting an error "display does not name a type" and the line "display.display();" is highlighted as the problem line.

I think I'm just down a rabbit hole of endlessly trying to correct something i don't understand.

All I'm trying to do is get some code I can use to display some output from some values I get from a GPS unit.

TheMemberFormerlyKnownAsAWOL

What part of "post the exact error message" did you find so hard to understand?
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

DKenp

What part of "post the exact error message" did you find so hard to understand?
I don't know what the original error message said exactly, for the reasons i explained.

Go Up