Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can not use in ESP8266 #6

Closed
HanSeoHyun opened this issue Jun 3, 2019 · 11 comments
Closed

I can not use in ESP8266 #6

HanSeoHyun opened this issue Jun 3, 2019 · 11 comments

Comments

@HanSeoHyun
Copy link

Hello, I tested your PWM code with UNO to MHZ19B. It works very well.
So I want use your library with nodeMCU ESP8266 12E. But It does not work.

my code:
#include <MHZ19PWM.h>

MHZ19PWM mhz(5, MHZ_DELAYED_MODE);

void setup()
{
Serial.begin(115200);
Serial.println(F("Starting..."));
mhz.useLimit(5000);
}

void showValue()
{
unsigned long start = millis();
float co2 = mhz.getCO2();
unsigned long duration = millis() - start;

Serial.print(F("CO2: "));
Serial.println(co2);
Serial.print(F("Duration: "));
Serial.println(duration);
Serial.println();
}

void loop()
{
showValue();
delay(5000);
}

my direction:
nodeMCU ---- sensor
Vin ---- Vin
GND ---- GND
D1(GPIO5) ---- PWM

my serial monitor:
serial monitor

help me please....

@strange-v
Copy link
Owner

Hello.
Seems a lot of things was changed in the Arduino core for esp8266 and I wouldn't say it become more stable.
If you are in harry the easiest way is to use an older core, e.g. 2.1.0 (I've just tested - it works).

I will look at this issue but not sooner than the next weekend.

@HanSeoHyun
Copy link
Author

HanSeoHyun commented Jun 3, 2019

Thank you for your comment.

I changed only esp8266 core version like below image. And another things are all same like above method. Is it right?
image

but it does not work well too...
Serial monitor:
image

Do you think I need to modify something else?
And, Do you think it's better to use Uart?? Did you tested on Uart?

@strange-v
Copy link
Owner

No, everything looks okay.
UART is tested, but you have to take into account that Arduino core for ESP8266 version 2.4 and later has troubles with Software Serial (check plerup/espsoftwareserial#63).
So you have to use version 2.3.

@HanSeoHyun
Copy link
Author

I try to nodeMCU on UART ESP8266 version 2.3, But It does not work.
Actually, my UNO on UART mode does not work same results.
They both print in serial monitor: "Error, code: 5" (infinitely)
Because I try to another board nodeMCU.

So I can test only UNO on PWM...

@strange-v
Copy link
Owner

Error code 5 equals MHZ19_RESULT_ERR_TIMEOUT. The sensor didn't respond for more than 500 milliseconds.
Please show/describe your wairing and what code is used.

@HanSeoHyun
Copy link
Author

HanSeoHyun commented Jun 4, 2019

I try to UNO on UART mode
my serial monitor with code:
image

my connection
MH_Z19B ----- Arduino UNO
Rx ------ 3
Tx ------ 2
GND ---- GND
Vin ----- 5V

First time to test, "Error, code: 5" is not printed infinitely. Sometimes Co2 checked 390~400, but I can not believe this values are real. Because I try to breathe in sensor, but the value is not changed.
Second time to test, "Error, code: 5" is printed infinitely.


I try to UNO on PWM mode
image

my connection
MH_Z19B ----- Arduino UNO
PWM ------ 3
GND ---- GND
Vin ----- 5V

A few days ago, I try to this by same condition(connection, code). At that time, if I breathe in sensor, the value was changed. But Today, the value never changed.

@strange-v
Copy link
Owner

I've no idea how I can help you. The MHZ19 library works without any issues on Arduino Nano (the same ATmega328P that in Uno), just tested it again https://i.imgur.com/zL59nmG.jpg it also works on Mega, esp8266 and esp32 (tested a few weeks ago).

Maybe you have some issues with the sensor itself.

P.S.
The MHZ19PWM library currently has issues on esp8266 (at least), probably I'll move it to a separate repository/library.

@HanSeoHyun
Copy link
Author

HanSeoHyun commented Jun 5, 2019

I am really thank you about your helps.
My goal was to connect two sensors to one boards(nodeMCU).
But I could not do it, So I had no choice.

There are my finally test lists:
UNO - UART ( X )
UNO - PWM ( O )
nodeMCU esp8266 - UART ( X )
nodeMCU esp8266 - PWM ( X )

I tried many tests, then UNO - PWM was works good. maybe, my test was something wrong in yesterday.
Finally I use two board that is UNO, nodeMCU. It was very inefficient, But It was best choice for me...

Thank you so much for your replies.

@strange-v
Copy link
Owner

I've used four sensors simultaneously on Arduino Mega (three via hardware serial + one via software serial) to compare results. You could try esp32 it has one additional hardware serial and supports software one too (AFAIK).

I'm glad you managed to solve your task.

@jwktje
Copy link

jwktje commented Dec 4, 2019

I have this issue. I want to use the library on a Wemos D1 Mini using ports D1 and D2 for software serial. I get Error 3. Any tips on this?

@strange-v
Copy link
Owner

@jwktje this issue was more about the PWM library.
You are trying to use SoftwareSerial on ESP8266 it may work or may not due to this bug. In general, I would recommend using ESP32 instead of ESP8266 in all new projects (at least if they would use Serial communication).

If you think that the MHZ19 library has some bug - please open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants