Customer:
I updated the ESP core on my Arduino installation to version 3.0.7 and the MQ-137-ALL-easyC.ino example no longer compiles. It generates these errors:
In file included from C:\Users[user]\AppData\Local\Temp. -18836-oc0n2e.gqzk\MQ-137-ALL-easyC\MQ-137-ALL-easyC.ino:18:
c:\Users[user]\Documents\Arduino\libraries\Soldered_MQ-X_Gas_Sensor_Arduino_Library\src/MQ-Sensor-SOLDERED.h: In constructor ‘MQ_Sensor::MQ_Sensor(int, int, String)’:
c:\Users[user]\Documents\Arduino\libraries\Soldered_MQ-X_Gas_Sensor_Arduino_Library\src/MQ-Sensor-SOLDERED.h:37:86: error: ‘VOLTAGE_RES’ was not declared in this scope
37 | MQ_Sensor(int _aPin, int _dPin, String type) : MQUnifiedsensor(_aPin, “Arduino”, VOLTAGE_RES, ADC_RES, type)
| ^~~~~~~~~~~
c:\Users[user]\Documents\Arduino\libraries\Soldered_MQ-X_Gas_Sensor_Arduino_Library\src/MQ-Sensor-SOLDERED.h:37:99: error: ‘ADC_RES’ was not declared in this scope
37 | MQ_Sensor(int _aPin, int _dPin, String type) : MQUnifiedsensor(_aPin, “Arduino”, VOLTAGE_RES, ADC_RES, type)
I reinstalled the MQ sensor library from the zip archive on Github but the compilation still fails. Can you check if there are issues with the library on later ESP32 cores or suggest why these errors are occurring?
Originally submitted via email support on 20 November 2024. Migrated to the forum for community visibility.
Soldered Support:
I think I see what could be causing the issue. It’s this define in the MQ-Sensor-SOLDERED.h:
#ifdef __AVR__
#define VOLTAGE_RES 5
#define ADC_RES 10
#elif ESP32
#define VOLTAGE_RES 3.3
#define ADC_RES 12
#elif ESP8266
#define VOLTAGE_RES 3.3
#define ADC_RES 10
#endif
I guess the board definition you’re using is not setting any of these ifs to true. These are parameters to calculate correctly the voltage reading as the ADCs between these three devices are different.
Could you please delete this in the file and just leave:
#define VOLTAGE_RES 3.3
#define ADC_RES 12
It could fix the issue.
Customer:
I tried many permutations of this with the latest ESP32 Core 3.0.7 in Arduino and it failed to compile every time. I downgraded my ESP32 Core to 3.0.5 and the compilation completed without error, which suggests this is a problem caused by changes within the compiler toolchain with 3.0.7. I don’t know why it should cause such a problem with the latest ESP32 core and I cannot see any changes in the ESP32 update logs that suggest why it would create an error. I also could not compile any of the other examples either with this ESP Core version.
Using the easyC version of the board, the assigned output pin is not relevant anyway, because the analogue output of the MQ137 is sampled by the ATTiny and this also provides the I2C connectivity providing measured data rather than an analogue value.
Attachment omitted in migration: ~WRD0000.jpg
Soldered Support:
You have the easyC version so the VOLTAGE_RES and ADC_RES parameters will not actually affect your readings as this is done by the ATTiny and transferred over I2C, but the compiler still needs those defines to compile.
Is using core 3.0.5 problematic for you at this moment? Addressing the root issue here might take some time to fix, as it will require investigating the library.