Hey all! I'm moderately new to Arduino coding and attempting to measure the CO2 concentration, temperature, and humidity of a controlled environment for a project. I've been reading the forums regarding the U8glib by Oliver to control the two OLED screens separately, but I keep getting the following error: "undefined reference to `I2C_SLA' collect2.exe: error: ld returned 1 exit status." I've tried uninstalling Arduino, the other used libraries, and even tried testing the code on a different laptop that has never had Arduino installed, and I get the same error message. I tested the code from post #7 on this forum on the new laptop before installing any other libraries and get the same error.
Here is the code I am attempting to use for the project:
#include <Adafruit_SCD30.h>
#include <Adafruit_SSD1306.h>
#include <U8glib.h>
Adafruit_SCD30 scd30;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
U8GLIB_SSD1306_128X32 u8g1(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);
U8GLIB_SSD1306_128X64 u8g3(U8G_I2C_OPT_NO_ACK);
extern uint8_t I2C_SLA;
float str;
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Adafruit SCD30 test!");
// Try to initialize!
if (!scd30.begin()) {
Serial.println("Failed to find SCD30 chip");
while (1) { delay(10); }
}
Serial.println("SCD30 Found!");
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 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);
//I2C_SLA = 0x07A;
//u8g3.begin();
u8g1.begin();
I2C_SLA = 0x03c;
}
void loop() {
if (scd30.dataReady()){
display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(1);
Serial.println("Data available!");
if (!scd30.read()){
Serial.println("Error reading sensor data");
display.println("READ ERR");
display.display();
return;
}
Serial.print("Temperature: ");
Serial.print(scd30.temperature);
Serial.println(" degrees C");
Serial.print("Relative Humidity: ");
Serial.print(scd30.relative_humidity);
Serial.println(" %");
Serial.print("CO2: ");
Serial.print(scd30.CO2, 3);
Serial.println(" ppm");
Serial.println("");
display.print("CO2: ");
display.print(scd30.CO2, 0);
display.println(" ppm");
display.print("TEMP: ");
display.print(scd30.temperature, 2);
display.println(" C");
display.print("HUMID: ");
display.print(scd30.relative_humidity, 2);
display.println("%");
display.display();
}
delay(100);
}
