This should let you do some testing on the Nano, I've taken out the Adafruit display library and replaced it with u8g2. There are several constructors for the SH1106 display, not sure which one will work with your display, and the font is not the same as Adafruit's. This shows 1346 bytes of ram used, if that is still too much you can try the u8x8 library that does not use a display buffer.
// CO2
#include <Arduino.h>
#include <MHZ19.h>
#include <SoftwareSerial.h>
// Temp
#include <DFRobot_DHT20.h>
// Display
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include <Wire.h>
// CO2
#define RX_PIN 5 // Rx pin which the MHZ19 Tx pin is attached to D2
#define TX_PIN 6 // Tx pin which the MHZ19 Rx pin is attached to D3
#define BAUDRATE 9600 // Device to MH-Z19 Serial baudrate (should not be changed)
MHZ19 myMHZ19; // Constructor for library
SoftwareSerial mySerial(RX_PIN, TX_PIN); // (Uno example) create device to MH-Z19 serial
// Temperature
DFRobot_DHT20 dht20;
// Display
// pick the constructor that works with your display
//U8G2_SH1106_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1106_128X64_VCOMH0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range
//U8G2_SH1106_128X64_WINSTAR_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but uses updated SH1106 init sequence
//U8G2_SH1106_128X32_VISIONOX_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//U8G2_SH1106_128X32_VISIONOX_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8G2_SH1106_72X40_WISE_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
void setup()
{
Serial.begin(9600);
// Start Co2
mySerial.begin(BAUDRATE); // (Uno example) device to MH-Z19 serial start
myMHZ19.begin(mySerial); // *Serial(Stream) refence must be passed to library begin().
myMHZ19.autoCalibration(); // Turn auto calibration ON (OFF autoCalibration(false))
// Start Temp
while (dht20.begin()) {
Serial.println(F("Initialize sensor failed"));
delay(1000);
}
u8g2.begin();
}
void loop()
{
//Get CO2
int CO2;
CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm)
//note - get all the data before entering the display loop
// otherwise the data may change between display pages
float dht20Temp = dht20.getTemperature();
float dht20Humidity = dht20.getHumidity();
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
byte lineSpacing = u8g2.getAscent() - u8g2.getDescent() + 1; //u8g2 does not support newline
u8g2.firstPage();
do {
u8g2.setCursor(0, lineSpacing);
u8g2.print(dht20Temp);
u8g2.setCursor(0, 3 * lineSpacing);
u8g2.print(dht20Humidity);
u8g2.print('%');
u8g2.setCursor(0, 5 * lineSpacing);
u8g2.print(CO2);
u8g2.print(F(" ppm"));
} while ( u8g2.nextPage() );
delay(2000);
}