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.
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:
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.
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.
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.