Hi,
I have MQ2 gas sensor with digital and analog pins (4 pins, D0, A0, Gnd, Vcc).
Is there anyone do thw program to read this senso with pure micropython on ESP8266 Lolin board?
Thanx in advance,
Jadro
MQ2 gas sensor
Re: MQ2 gas sensor
Have you seen https://github.com/kartun83/micropython-MQ -- Looks like it should be exactly what you need.
Re: MQ2 gas sensor
Yes I try this scripts but does not work for me, shows some errors, same as reported...jimmo wrote: ↑Mon Jul 12, 2021 3:27 pmHave you seen https://github.com/kartun83/micropython-MQ -- Looks like it should be exactly what you need.
Re: MQ2 gas sensor
What are the errors you see? What do you mean by "same as reported" ?
Re: MQ2 gas sensor
Errors that is present on start using uPyCraft:
exec(open('test.py').read(),globals())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 3, in <module>
ImportError: no module named 'MQ2'
I dont see why it does not see MQ2?!?! I copy MQ2.py and BaseMQ.py in root folder with main test script test.py but unseccessfuly...
I try import folder as import MQ then from MQ2 import MQ2, even from MQ.MQ2 import MQ2 and from .MQ2 import MQ2...
Can somebody try this?
exec(open('test.py').read(),globals())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 3, in <module>
ImportError: no module named 'MQ2'
I dont see why it does not see MQ2?!?! I copy MQ2.py and BaseMQ.py in root folder with main test script test.py but unseccessfuly...
I try import folder as import MQ then from MQ2 import MQ2, even from MQ.MQ2 import MQ2 and from .MQ2 import MQ2...
Can somebody try this?
Re: MQ2 gas sensor
At least, test.py does not work as is, it must have import MQ as module:
import MQ
from MQ import MQ2
import utime
class App:
def __init__(self, pin = 0):
self.sensor = MQ2.MQ2(pinData = pin, baseVoltage = 3.3)
def Run(self):
print("Calibrating")
self.sensor.calibrate()
print("Calibration completed")
print("Base resistance:{0}".format(self.sensor._ro))
while True:
print("Smoke: {0}".format(self.sensor.readSmoke()))
print("LPG: {0}".format(self.sensor.readLPG()))
print("Methane: {0}".format(self.sensor.readMethane()))
print("Hydrogen: {0}".format(self.sensor.readHydrogen()))
utime.sleep(5)
App().Run() # or app = App() and app.Run()
import MQ
from MQ import MQ2
import utime
class App:
def __init__(self, pin = 0):
self.sensor = MQ2.MQ2(pinData = pin, baseVoltage = 3.3)
def Run(self):
print("Calibrating")
self.sensor.calibrate()
print("Calibration completed")
print("Base resistance:{0}".format(self.sensor._ro))
while True:
print("Smoke: {0}".format(self.sensor.readSmoke()))
print("LPG: {0}".format(self.sensor.readLPG()))
print("Methane: {0}".format(self.sensor.readMethane()))
print("Hydrogen: {0}".format(self.sensor.readHydrogen()))
utime.sleep(5)
App().Run() # or app = App() and app.Run()
Re: MQ2 gas sensor
Can you try doing this at the REPL:
and show the output? It doesn't sound like the files are being copied to the right place?
FWIW, it seems that a lot of people run into these sorts of problems with uPyCraft... it appears to be unmaintained. Maybe you could try mpremote (https://pypi.org/project/mpremote/), rshell (https://github.com/dhylands/rshell) or Thonny (https://thonny.org/)
Code: Select all
>>> import os
>>> os.listdir()
>>> import MQ2
FWIW, it seems that a lot of people run into these sorts of problems with uPyCraft... it appears to be unmaintained. Maybe you could try mpremote (https://pypi.org/project/mpremote/), rshell (https://github.com/dhylands/rshell) or Thonny (https://thonny.org/)
Re: MQ2 gas sensor
Thanx jimmo, I use Thonny for ESP32 and it is great and dont have this issues, is the best for such a things.