Code for SCD30 and 128x64 OLED screen featherwing

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Olivialovesbread
 
Posts: 2
Joined: Mon Apr 17, 2023 8:26 pm

Code for SCD30 and 128x64 OLED screen featherwing

Post by Olivialovesbread »

I'm not sure if anyone's already written code that combines the instructions necessary to readout from the SCD30 and display on 128x64 OLED screen but when I've tried combining the two, I keep getting the error code "
Compilation error: invalid cast to abstract class type 'Adafruit_SH110X'". I'll attach my code here but if there is a working code, I would love to have it for a project, thank you!
Code

Code: Select all

#include <Adafruit_SCD30.h>
#include <Adafruit_SH110X.h>

Adafruit_SCD30  scd30;
Adafruit_SH110X display = Adafruit_SH110X(128, 64, &Wire);

void setup(void) {
  Serial.begin(115200);
  while (!Serial) delay(10);     // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("SCD30 OLED CO2 meter!");

  // Try to initialize!
  if (!scd30.begin()) {
    Serial.println("Failed to find SCD30 chip");
    while (1) { delay(10); }
  }
  Serial.println("SCD30 Found!");


  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SH110X_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    Serial.println(F("SH1100X allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  if (!scd30.setMeasurementInterval(2)){
    Serial.println("Failed to set measurement interval");
    while(1) {delay(10);}
  }
  Serial.print("Measurement Interval: "); 
  Serial.print(scd30.getMeasurementInterval()); 
  Serial.println(" seconds");
  
  display.display();
  delay(500); // Pause for half second

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setRotation(0);
}


void loop() {
  if (scd30.dataReady()) {
    display.clearDisplay();
    display.setCursor(0,0);
    display.setTextSize(2);

    Serial.println("Data available!");

    if (!scd30.read()){
      Serial.println("Error reading sensor data");
      display.println("READ ERR");
      display.display();
      return;
    }

    Serial.print("CO2: ");
    Serial.print(scd30.CO2, 3);
    Serial.println(" ppm");
    Serial.println("");

    display.println("CO2:");
    display.print(scd30.CO2, 2);

    display.setTextSize(1);

    display.setCursor(100, 20);
    display.println(" ppm");
    display.display();
  }

  delay(100);
}

User avatar
mikeysklar
 
Posts: 14180
Joined: Mon Aug 01, 2016 8:10 pm

Re: Code for SCD30 and 128x64 OLED screen featherwing

Post by mikeysklar »

What model of Controller board are you using?

Which version of the Arduino IDE?

Which version of the libraries?

You can grab a library summary and details of the full error message by enabling this setting and attempting to re-compile.

File --> Preferences --> Verbose Compilation

More than likely some libraries are out of date.

User avatar
Olivialovesbread
 
Posts: 2
Joined: Mon Apr 17, 2023 8:26 pm

Re: Code for SCD30 and 128x64 OLED screen featherwing

Post by Olivialovesbread »

I'm using the Arduini Uno and version of Arduino IDE is 2.1.0. I'm using the most current version of the libraries. I'll try that right now with the settings right now, thanks!

User avatar
mikeysklar
 
Posts: 14180
Joined: Mon Aug 01, 2016 8:10 pm

Re: Code for SCD30 and 128x64 OLED screen featherwing

Post by mikeysklar »

The 2.1.0 IDE was just released, but I’d like to confirm with you that the Adafruit example code is running correctly for each device.

Are you able to use the SCD-30 standalone?

Are you able to use the SH110X on its own with the Adafruit provided example code?

Please send over the verbose compiler error as well.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”