Hello, I am new to Arduino and I am trying to write some temperature and humidity data on a 128 x 32 OLED display. However, I see there are two libraries: U8GLIB and U8G2, the second being newer. I am using a SSD1306 based OLED, so I tried the "Hello Wolrd" example, but I am getting the error shown below.
I am laso including the code after that.
I have two questions:
- Is there a way to fix this?
- Is there an easy to understand reference to learn how to use this dysplay ? Available references include many many other drivers and it becomes confusing to understand what applies to the one I am using.
Please see the details below.
----------Error message starts-------------
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:47:26: error: expected ')' before ',' token
U8GLIB_SSD1306_128X32(sck, mosi, cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:47:40: error: expected initializer before ')' token
U8GLIB_SSD1306_128X32(sck, mosi, cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:48:25: error: expected ')' before ',' token
U8GLIB_SSD1306_128X32(cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:48:29: error: expected initializer before ')' token
U8GLIB_SSD1306_128X32(cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:50:29: error: expected ')' before ',' token
U8GLIB_SSD1306_128X32_2X(sck, mosi, cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:50:31: error: conflicting declaration 'U8GLIB_SSD1306_128X32_2X mosi'
U8GLIB_SSD1306_128X32_2X(sck, mosi, cs, a0);
^~~~
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:47:28: note: previous declaration as 'U8GLIB_SSD1306_128X32 mosi'
U8GLIB_SSD1306_128X32(sck, mosi, cs, a0);
^~~~
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:50:37: error: conflicting declaration 'U8GLIB_SSD1306_128X32_2X cs'
U8GLIB_SSD1306_128X32_2X(sck, mosi, cs, a0);
^~
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:47:34: note: previous declaration as 'U8GLIB_SSD1306_128X32 cs'
U8GLIB_SSD1306_128X32(sck, mosi, cs, a0);
^~
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:50:43: error: expected initializer before ')' token
U8GLIB_SSD1306_128X32_2X(sck, mosi, cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:51:28: error: expected ')' before ',' token
U8GLIB_SSD1306_128X32_2X(cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:51:32: error: expected initializer before ')' token
U8GLIB_SSD1306_128X32_2X(cs, a0);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:52:33: error: conflicting declaration 'U8GLIB_SSD1306_128X32_2X options'
U8GLIB_SSD1306_128X32_2X(options);
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:49:23: note: previous declaration as 'U8GLIB_SSD1306_128X32 options'
U8GLIB_SSD1306_128X32(options);
^~~~~~~
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:62:26: error: redefinition of 'U8GLIB_SSD1306_128X32 u8g'
U8GLIB_SSD1306_128X32 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:61:23: note: 'U8GLIB_SSD1306_128X32 u8g' previously declared here
U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
^~~
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:63:26: error: redefinition of 'U8GLIB_SSD1306_128X32 u8g'
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
^
C:\Users\Marco\AppData\Local\Temp.arduinoIDE-unsaved2024614-10300-1l3c8ad.1k7z\HelloWorld\HelloWorld.ino:61:23: note: 'U8GLIB_SSD1306_128X32 u8g' previously declared here
U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
^~~
exit status 1
Compilation error: expected ')' before ',' token
----------Error message ends -------------
I tried removing all the unnnecesary constructor information of other devices and tried to leave the code as simple as possible. Here it is:
----------Code starts -------------
#include "U8glib.h"
// setup u8g object, please remove comment from one of the following constructor calls
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported
// devices with all constructor calls is here: https://github.com/olikraus/u8glib/wiki/device
U8GLIB_SSD1306_128X32(sck, mosi, cs, a0);
U8GLIB_SSD1306_128X32(cs, a0);
U8GLIB_SSD1306_128X32(options);
U8GLIB_SSD1306_128X32_2X(sck, mosi, cs, a0);
U8GLIB_SSD1306_128X32_2X(cs, a0);
U8GLIB_SSD1306_128X32_2X(options);
U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
U8GLIB_SSD1306_128X32 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 22, "Hello World!");
}
void setup(void) {
// flip screen, if required
// u8g.setRot180();
// set SPI backup if required
//u8g.setHardwareBackup(u8g_backup_avr_spi);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
pinMode(8, OUTPUT);
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
//delay(50);
}
----------Code ends -------------
I added the following lines beacuse I think this is what was suggested in the following libarry link:
U8GLIB_SSD1306_128X32(sck, mosi, cs, a0);
U8GLIB_SSD1306_128X32(cs, a0);
U8GLIB_SSD1306_128X32(options);
U8GLIB_SSD1306_128X32_2X(sck, mosi, cs, a0);
U8GLIB_SSD1306_128X32_2X(cs, a0);
U8GLIB_SSD1306_128X32_2X(options);
But I really have no idea how the code is working.
I have two questions:
- Is there a way to fix this?
- Is there an easy to understand reference to learn how to use this dysplay ? Available references include many many other drivers and it becomes confusing to understand what applies to the one I am using.
Any help would be greatly appreciated.