Library Issues - #include <U8glib> does not turn orange

Hi,

I've recently downloaded the Marlin firmware from the Arduino 3D printer project from the link https://www.arduino.cc/en/Main/ArduinoMateria101 and was trying to add the library U8glib to my Arduino library. I've tried unzipping only the U8glib file right into the Arduino library, and I've tried to manually add it but when I go to add the library to my code through the drop down menu in the sketch tab, the library name does not turn orange and the code will not compile. I've closed and reopened the IDE as well, but no change. I'm using an Arduino Mega 2560.

I'm kind of new to this stuff and this is my first time posting so if there is any more information that's needed please let me know! I've attached the "Hello World" code that I was testing and the compiling errors that pop up.

Here is my code:

include "U8glib.h"


U8GLIB_SH1106_128X64 u8g(4, 5, 6, 7);

void setup() 
{  
  u8g.setFont(u8g_font_unifont);
  u8g.setColorIndex(1); // Instructs the display to draw with a pixel on. 
}

void loop()
{  
  u8g.firstPage();
  do {  
    draw();
     } 
  while( u8g.nextPage() );
  delay(1000);   
}
  
void draw()
{
  u8g.drawStr( 0, 20, "Hello World");
}

and here are my error messages:

Arduino: 1.6.9 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Hello_World:1: error: 'include' does not name a type

 include "U8glib.h"

 ^

C:\Program Files (x86)\Arduino\libraries\U8glib\Hello_World\Hello_World.ino: In function 'void setup()':

Hello_World:8: error: 'u8g' was not declared in this scope

   u8g.setFont(u8g_font_unifont);

   ^

Hello_World:8: error: 'u8g_font_unifont' was not declared in this scope

   u8g.setFont(u8g_font_unifont);

               ^

C:\Program Files (x86)\Arduino\libraries\U8glib\Hello_World\Hello_World.ino: In function 'void loop()':

Hello_World:14: error: 'u8g' was not declared in this scope

   u8g.firstPage();

   ^

C:\Program Files (x86)\Arduino\libraries\U8glib\Hello_World\Hello_World.ino: In function 'void draw()':

Hello_World:24: error: 'u8g' was not declared in this scope

   u8g.drawStr( 0, 20, "Hello World");

   ^

exit status 1
'include' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Thank you so much in advance for any help!

You forgot the '#' before include.

Code turning orange is just controlled by a keyword file and means nothing. It's can only be there as an aid. Only compiler errors tell you about real problems.

The problem with the code is you don't include it right. It should look like:

#include "U8glib.h"

Spot the difference?

Sorry, that was my mistake posting. When I copied and pasted the code i forgot the # but it is in my code and I am still having some trouble!

There was no '#' in your code. This is the proof:

Hello_World:1: error: 'include' does not name a type

Alrighty, so I've added the # and I've received the following new errors:

Arduino: 1.6.9 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\C748a Computer 2\Desktop\Hello_World\Hello_World.ino: In function 'void setup()':

Hello_World:7: error: 'u8g' was not declared in this scope

   u8g.setFont(u8g_font_unifont);

   ^

C:\Users\C748a Computer 2\Desktop\Hello_World\Hello_World.ino: In function 'void loop()':

Hello_World:13: error: 'u8g' was not declared in this scope

   u8g.firstPage();

   ^

C:\Users\C748a Computer 2\Desktop\Hello_World\Hello_World.ino: In function 'void draw()':

Hello_World:23: error: 'u8g' was not declared in this scope

   u8g.drawStr( 0, 20, "Hello World");

   ^

exit status 1
'u8g' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Thank you all for the help!!!

You should specify which library you are using, and post a link to it.

edit: Let's assume it is this one.

Here is your problem. This is from U8glib.h. Note the "private".

class U8GLIB : public Print
{
  private:
    u8g_t u8g;

I've tried 2 download links. One from the Arduino site that has the library within the firmware which was from https://www.arduino.cc/en/Main/ArduinoMateria101 (clicked on Materia101Firmware.zip and the library was within this file) and I tried downloading the library by its self from GitHub - olikraus/U8glib_Arduino: U8glib library for Arduino and renamed it to just U8glib. The library is called U8glib.

With that library, you cannot reference u8g. See my edit in reply #6. It is private. That means you cannot use that variable outside that library. That is a problem with the library, not the Arduino IDE.

oohhh alrighty thank you so much!!!
Do you know if there is anyway to work around that?

You might try moving that u8g to the public section of the U8glib.h file.

After downloading the library from the link in reply # 6, and adding the # to the include statement, I get only one "error":

Sketch uses 14,124 bytes (49%) of program storage space. Maximum is 28,672 bytes.
Global variables use 392 bytes (15%) of dynamic memory, leaving 2,168 bytes for local variables. Maximum is 2,560 bytes.

using IDE 1.6.6 with a Leonardo selected.

Perfect! Alrighty it's all up and running now!! Thank you both so much for your help!! :slight_smile: