crisap94 / MHZ19

MH-Z19 CO2 sensor library for ESP8266 or Arduino
Other
68 stars 24 forks source link

Getting this to work on Wemos D1 (esp8266) #15

Open quintendewilde opened 3 years ago

quintendewilde commented 3 years ago

Hi,

Do I need to make alteration in the code (except for the pins ofcourse) to get this to work on an ESP8266 board.

I only get a question mark for the moment..

/*----------------------------------------------------------
    MH-Z19 CO2 sensor  SAMPLE
  ----------------------------------------------------------*/

#include "MHZ19.h"

const int rx_pin = 3; //Serial rx pin no
const int tx_pin = 1; //Serial tx pin no

const int pwmpin = 2;

MHZ19 *mhz19_uart = new MHZ19(rx_pin,tx_pin);
MHZ19 *mhz19_pwm = new MHZ19(pwmpin);

/*----------------------------------------------------------
    MH-Z19 CO2 sensor  setup
  ----------------------------------------------------------*/
void setup()
{
    Serial.begin(115200);
    mhz19_uart->begin(rx_pin, tx_pin);
    mhz19_uart->setAutoCalibration(false);
    while (mhz19_uart->isWarming())
    {
        Serial.print("MH-Z19 now warming up...  status:");
        Serial.println(mhz19_uart->getStatus());
        delay(1000);
    }
}

/*----------------------------------------------------------
    MH-Z19 CO2 sensor  loop
  ----------------------------------------------------------*/
void loop()
{
    measurement_t m = mhz19_uart->getMeasurement();

    Serial.print("co2: ");
    Serial.println(m.co2_ppm);
    Serial.print("temp: ");
    Serial.println(m.temperature);

    int co2ppm = mhz19_pwm->getPpmPwm();
    Serial.print("co2: ");
    Serial.println(co2ppm);

    delay(5000);
}
crisap94 commented 3 years ago

I will strongly recommend you use what Issue #14 proposes as a workaround.