Hello, I am new to the world of coding and don't have much experience. I am working on a project that uses two sensors, an OLED screen as well as an inventr.io HERO board. When testing the sensors alone i have been able to get the SHT30 sensor and the SH1106 screen to work together. The problem i am having is when i try to use the DPS310 sensor with the same screen. I tested the DPS310 sensor without the screen first, and got the measurements to show in the serial monitor. This tells me that the sensor is working.
```cpp
#include <U8g2lib.h>
#include <MUIU8g2.h>
#include <U8x8lib.h>
#include <Adafruit_DPS310.h>
#include <Wire.h>
Adafruit_DPS310 dps;
U8G2_SH1106_128X64_NONAME_F_HW_I2C screen(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
#define DPS310_I2CADDR_DEFAULT (0x77)
// Can also use SPI!
#define DPS310_CS 10
void setup() {
Serial.begin(9600);
while (!Serial) delay(10);
Serial.println("DPS310");
if (!dps.begin_I2C(0x77)) { // Can pass in I2C address here
//if (! dps.begin_SPI(DPS310_CS)) { // If you want to use SPI
Serial.println("Failed to find DPS");
while (1) yield();
}
Serial.println("DPS OK!");
dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
}
void loop() {
sensors_event_t temp_event, pressure_event;
while (!dps.temperatureAvailable() || !dps.pressureAvailable()) {
return; // wait until there's something to read
}
dps.getEvents(&temp_event, &pressure_event);
Serial.print(F("Temperature = "));
Serial.print(temp_event.temperature);
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(pressure_event.pressure);
Serial.println(" hPa");
Serial.println();
do {
screen.clearBuffer();
screen.setCursor(0, 20);
screen.print("T: ");
screen.print(temp_event.temperature);
screen.print(" *C");
screen.setCursor(0, 20);
screen.print("Pressure = ");
screen.print(pressure_event.pressure);
screen.print(" hPa");
} while (screen.nextPage());
screen.sendBuffer();
}
In the code provided i don't have the lines dedicated for the screen commented out. however, when i do comment them out so the code doesn't read them, the sensor starts working again. I could be wrong, but this leads me to believe that there is a conflict with the libraries. If this is the case, I dont know enough to figure this out on my own. Any help would be greatly appreciated
I am getting mixed messages.
Do you want to use the 8x8 mode, which is very memory efficient.
Or do you want to use the graphical mode with pages, which should be memory efficient, but still use a fair amount of SRAM.
Please, don't download libraries from their website.
They might be old and have bugs. It is better to select the libraries with the Library Manager in the Arduino IDE. Can you delete all those libraries from your computer ?
Those old libraries might not work together with new libraries, for example Adafruit has a complete system of libraries that should all work together if they are all the newest version.
It is a Arduino Uno clone, if you want to add more things and more libraries, then it is best to use the 8x8 mode.
Where is the screen.begin(); and where do you set the font ?
For the libraries i am using, they're all installed directly from the arduino IDE. As for the use of the 8x8 or graphical mode, im not sure of their importance or difference when it comes to the code. You are right about the initialization of the screen with the screen.begin(); as well as the font, i can add those for sure. But even without the screen being initialized, why would the sensor not be able to be found after including the screen?
The Uno has only a small amount SRAM.
The 8x8 mode uses almost no SRAM, but the graphical page buffer mode uses a buffer in SRAM.
If you select on of them, then the code can be fixed for it. That is just one step.
Adafruit uses their "Adafruit BusIO" library for I2C. I assume that it can be used together with the OLED display. You could add a I2C Scanner to the sketch to check if they both can be found before and after initializing the devices.
to select which mode i want, are you saying i should only include 1 of the "U8...." libraries? Sorry if that seems like a straightforward answer, im still learning. I will add the "Adafruit BusIO" to the sketch as well.
So my code doesn't have either mode, ok. How do I go about actually writing the mode into the code. I think the 8x8 would work best, so lets just pick that one.
Good choice! (the other option was also a good choice ).
You need to add the u8g2 library to the Arduino IDE, you already have that.
Include only #include <U8x8lib.h>, please remove the MUIU8g2.h and U8g2lib.h.
Create a object in U8x8 mode, with a SH1106 display, and 128x64 resolution, and hardware I2C:
Remove the do { .. } while (screen.nextPage()); in the loop(). That was for the page mode.
Keep the U8x8 functions nearby: https://github.com/olikraus/u8g2/wiki/u8x8reference
Don't forget the u8x8.begin(); and setting an u8x8 font in setup().
Maybe the drawString() is the easiest to write text.
This is very helpful thank you! I do have another quick question. Where im removing the
do { .. } while (screen.nextPage()); is there a way to have multiple pages/screens with the 8x8 library? Just because id like to have the measurements displayed with a bigger font and just have one per page.
The nextPage() is not to show different pages on the display. It is to build only one screen, which is build from a number of smaller pieces. That way a small buffer can be used.
Those small pieces for one screen output are called "pages".
You can read about the three different modes of the u8g2 library here: https://github.com/olikraus/u8g2/wiki/setup_tutorial#u8g2-full-buffer--page-buffer-and-u8x8-mode
If you want a few different screens or pages, then you have to create the different screens or pages in code, regardless of which mode the u8g2 library is used in.