Oled display 2.42" 128 x 64


#1

OK,

As a newbie here I am just learning the Web IDE and learning how to build apps. I decided to tackle adding a display to a Particle Photon or Boron, Xenon Argon etc. In this case I am using the Photon. I bought an OLED white monochrome display from DIY More 128 x 64 display. It uses the SPI Serial For Arduino C51 STM32.

[https://www.diymore.cc/products/2-42-inch-12864-oled-display-module-iic-i2c-spi-serial-for-arduino-c51-stm32-green-white-blue-yellow?variant=17060396433466](http://DISPLAY I AM USING)

I have the device wired on a particle dev board with the Photon. Here is what I have tried to do:

1.) Open the WEB IDE and created a new App called Demo_display
2.) Tried to add the libraries for the Adafruit_SSD1306 & Adafruit_GFX because I understand that these are required.
3.) I tried to load one of the examples in the libraries. EXAMPLE: ssd1306_128x64_spi.ino
4.) Click Include in Project, select the project and click confirm.
5.) when I do, the save button is grayed out and I cannot save anything.
6.) I expected to see multiple tabs in the project for the Adafruit_GFX.cpp, Adafruit_GFX.h, Adafruit_SSD1306.cpp & Adafruit_SSD1306.h however, the only thing that is added is the include to call the library like this:

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_SSD1306.h>

The code will NOT compile.

I noticed that the Code from the Demo file ssd1306_128x64_spi.ino included the following includes declared:

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

But the app also added this at the very top:

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_SSD1306.h>

The save button is STILL grayed out.

I refreshed the screen and the save button became usable again. I saved the display_demo project.

Only 1 tab is visible: demodisplay.ino.

The code will not compile:

I get two errors:

lib/Adafruit_SSD1306/Adafruit_SSD1306.h:109:7: redefinition of 'class Adafruit_SSD1306’
lib/Adafruit_SSD1306/Adafruit_SSD1306.h:109:7: previous definition of ‘class Adafruit_SSD1306’

It is VERY frustrating when example libraries will not compile that are pulled directly from the Particle IDE. Why is this happening???

Help!


#2

OK, I am going to add that the WEB IDE is broken. It does NOT add the libraries as it should I think. The demo files are stupid because they do not work. They will not even compile!

I used the “ssd1306_128x64_spi.ino” demo file right from the Particle

This code will NOT compile in the IDE. The system is Hokie, odd, does not load the selected libraries into the file to build the app. What the heck, am I missing something?


#3

I have had success using the library called oled-wing-adafruit.h

#include <oled-wing-adafruit.h>
OledWingAdafruit oled;

void setup()
{
   oled.setup(); 
    // Clear the buffer.
    oled.clearDisplay();
    oled.display();
}
void loop()
{
    displayVoltage();
    delay(3*1000);
}
void displayVoltage(){
    oled.clearDisplay();
    oled.setTextSize(4);
    oled.setTextColor(WHITE);
    oled.setCursor(0,0);
    float voltage = analogRead(BATT) * 0.0011224;
    oled.print(voltage);
    oled.display();
}

#4

With the oled-wing-adafruit library you do not need to add the gfx library. You shouldn’t have needed to for the Adafruit_SSD1306 either, I believe it is included.


#5

If you want to use the example, you should use the “use this example” button, which will create a new project for you with that code. You can’t add it to existing code.

If you want only the library, you use the “include in project option”

The Web IDE adds the files to your project in the background, showing you in the files overview. Files then are (unfortunately) not editable. If you do want to play with the library, you’ll have to copy-paste the relevant files to new tabs. This will hopefully be made a lot smoother in the future.

What code? There’s nothing for us to look at, so nothing to comment about either. When discussing code, either paste it, or preferably give us a share link from the IDE if you’d like input on your issues.

The fact that you seem to have duplicate includes is problematic, which unsurprisingly, the compiler will complain about:

That duplicate include didn’t come from the IDE if used correctly, so I’d have to write that of as user-error.

Multiple reasons, some of which:

  • library error: unless they’re specifically marked as Particle, libraries are contributed by the community and as such can contain bugs.
  • incompatible library: with the release of a new generation of devices, a lot of libraries haven’t been updated to support these yet (see previous point). Little Particle can do about it directly, and issues should be taken to the community member that contributed it. (This will hopefully change in the future).
  • user error: incorrect usage will lead to incorrect results.

Ready for a refresh? Sure. Broken? Not really. At least, not because you can’t get a library example to compile, for reasons mentioned above.
Again, we’re missing the actual code you tried to compile, so it’s hard to accurately comment on the issue.

All that being said, I tried the “use this example” with the spi demo you mentioned. Upon compiling it gave me an error that “random(int)” was being redefined. I changed all the mentions of to “random1(int)” and it compiled successfully.
In conclusion: adding the library (examples) does work if done correctly, but that doesn’t mean there can’t be errors in the example itself. Haven’t looked into the why&how of this particular error, just tried to get it to compile for a photon running the latest firmware.

Here’s the share link if you want to give it a shot: https://go.particle.io/shared_apps/5c16088af6223860be0002ca

For better file/library/project management, do take a look at Particle Workbench, the new VSCode based Dektop IDE.


#6

You can actually just remove that function entirely since it was added to the stock set of functions after the library had been contributed but the contributor hasn’t updated the library since - hence the redefinition error.


#7

Ok, explain how… I got this:

// This #include statement was automatically added by the Particle IDE.
#include <oled-wing-adafruit.h>

void setup()
{
   oled.setup(); 
    // Clear the buffer.
    oled.clearDisplay();
    oled.display();
}
void loop()
{
    displayVoltage();
    delay(3*1000);
}
void displayVoltage(){
    oled.clearDisplay();
    oled.setTextSize(4);
    oled.setTextColor(WHITE);
    oled.setCursor(0,0);
    float voltage = analogRead(BATT) * 0.0011224;
    oled.print(voltage);
    oled.display();
}

display2.ino:8:4: ‘oled’ was not declared in this scope error
display2.ino:19:5: ‘oled’ was not declared in this scope error
display2.ino:23:32: ‘BATT’ was not declared in this scope


#8

OK, I used the project. It compiled. the display is still blank/black like no power. Am I missing something? Should I see anything or should I have to add something still?


#9

After a LOT of playing, a lot of frustration, I learned a few things and managed to get the library to compile and to display the Adafruit demo graphics.

Now I realize that I have to modify the library to make it display something I want to display on the screen.

Anybody tried that yet? Any demo for showing a logo other than the Adafruit one?


#10

You need to create the object first

OledWingAdafruit oled;

I also misread your original post, I originally thought you were using the mesh like a xenon and not the photon. The BATT variable is for mesh. The photon code is slightly different and will probably need that first library you used. The oled you linked is set up for spi, but if you have the adafruit logo showing up then you are wired correctly. Showing another logo other than adafruit one requires converting an image into an array for each pixel.

Try this in the loop.

int count =0;
void loop(){
    oled.clearDisplay();
    oled.setTextSize(2);
    oled.setTextColor(WHITE);
    oled.setCursor(0,0);
    oled.print(count);
    oled.display();
    count++;
}

#11

I tried creating the array but then you also have to actually include the library files. Whenever I try that, it will not compile. Not sure why calling to the included libraries works but when actually grabbing the libraries and adding them in the project it won’t compile…


#12

If you could provide a link to your project that doesn’t build we could actually see why it’s not building.
Or at least post the error messages after correcting the issues pointed out by @Moors7.

But I’d say you are still having duplicates, which was already pointed out. Since you have dedicated file tabs for the library you mustnot also have the library imported.
When you open the <> drawer you will see the Adafruit_SSD1306 library under Included Libraries. You need to remove it from there via the delete button (image)


#13

Thank you for this discussion. I had similar problems with compiling… I added the library, which caused no complaint & complied but did not run.

I removed the line:

“// This #include statement was automatically added by the Particle IDE.
#include <oled-wing-adafruit.h>”

Then I made sure the library was linked & the web-IDE put the “same” line back in the code. This time it works?!

Many thanks! _Todd