#๐ Help with micropython (Im new) (pls help) (urgent)
6 messages ยท Page 1 of 1 (latest)
@old folio
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
I have an assignment to make a bunch of sensors work for tomorrow (In like 8 hours). Pls I would really appreciate it if someone could check my functions and tell me if they would work properly and tell me the mistakes.
class MQ7(object):
# The load resistance on the board
RLOAD = 10.0
# Parametros para calcular CO
PARA = 116.6020682
PARB = 2.769034857
def __init__(self, pin):
self.pin = pin
def get_resistance(self):
adc = ADC(Pin(self.pin))
value = adc.read_u16()
if value == 0:
return -1
return (1023./value - 1.) * self.RLOAD
def get_ppm(self):
#10=R0 at 1000ppm, placeholder for now
return self.PARA * (self.get_resistance()/ 10)**-self.PARB
mq7 = MQ7(2) #GPIO pin
while True:
ppm = mq7.get_ppm()
print("MQ7 PPM: " + str(ppm) + "ppm")
def medirCH4():
class MQ4(object):
# The load resistance on the board
RLOAD = 10.0
# Parametros para calcular CH4
PARA = 116.6020682
PARB = 2.769034857
def __init__(self, pin):
self.pin = pin
def get_resistance(self):
adc = ADC(Pin(self.pin))
value = adc.read_u16()
if value == 0:
return -1
return (1023./value - 1.) * self.RLOAD
def get_ppm(self):
#10=R0 at 1000ppm, placeholder for now
return self.PARA * (self.get_resistance()/ 10)**-self.PARB
mq4 = MQ4(0) #GPIO pin
while True:
ppm = mq4.get_ppm()
print("MQ4 PPM: " + str(ppm) + "ppm") ```
ZERO = -15.01019 # Resistencia calibrada al CO2 de la atmรยณsfera
class MQ135(object):
# The load resistance on the board
#check this
RLOAD = 10.0
# Parametros para calcular
PARA = 116.6020682
PARB = 2.769034857
def __init__(self, pin):
self.pin = pin
def get_resistance(self):
adc = ADC(Pin(self.pin))
value = adc.read_u16()
if value == 0:
return -1
return (1023./value - 1.) * self.RLOAD
def get_ppm(self):
return self.PARA * (self.get_resistance()/ ZERO)**-self.PARB
mq135 = MQ135(4) #GPIO pin
while True:
ppm = mq135.get_ppm()
print("MQ135 RZero: " + str(ZERO) + "\t PPM: " + str(ppm) + "ppm")
def medirtempyhum():
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print('Temperature: %3.1f C' %temp)
print('Humidity: %3.1f %%' %hum)
time.sleep(300)
sensor = dht.DHT11(Pin(21)) #GPIO pin
while True:
medirtempyhum(sensor)
time.sleep(300)```
@old folio
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.