Newbie gas sensor help

Greetings
Iam trying to set up gas monitoring system for air quality with different types of gas sensors. I have a a mics6814 triple gas sensor that I would to set up for air quality gas ppm. I have the gas.py example program from PimoroniI as shown below which gives resistance values only.

#!/usr/bin/env python3
import time
from mics6814 import MICS6814
import logging

gas = MICS6814()

logging.basicConfig(
    format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
    level=logging.INFO,
    datefmt='%Y-%m-%d %H:%M:%S')

print("""gas.py - Print readings from the MICS6814 Gas sensor.

Press Ctrl+C to exit!

""")

try:
    while True:
        readings = gas.read_all()
        logging.info(" | ".join(str(readings).splitlines()))
        time.sleep(1.0)
except KeyboardInterrupt:
    pass

I came across the following three equations resistance to ppm from(Roscoe) on the forum. I am a beginner in python programming and want to be able to integrate these equations into the example program to display ppm gas readings.

1.-- red_in_ppm = math.pow(10, -1.25 * math.log10(red_rs/red_r0) + 0.64)

2.-- oxi_in_ppm = math.pow(10, math.log10(oxi_rs/oxi_r0) - 0.8129)

3.-- nh3_in_ppm = math.pow(10, -1.8 * math.log10(nh3_rs/nh3_r0) - 0.163)

Can anyone help me with this ?
Thanks in advance
Tom

Heya, could you edit your post to repair the formatting? Like many places on the web, this forum uses Markdown, which uses a few symbols to format text. This means that code can’t be pasted directly into the editor - it needs a slight tweak. Specifically, a block of code needs to start and end with a “code fence”, which is three backticks on their own line.

So try adding them to your code, by clicking on the pencil icon to edit:

```
your code goes here
your code goes here
your code goes here
```

This will ensure readers can see your Python indentation too, which is important.

Halfer
I am sorry for the mess in formatting.
I do not know how to edit the post that I created.
How do I enter the edit mode?
thanks
Tom

Find the post you wish to edit, and find a grey pencil icon ✏️ under it. Click the icon, edit the post, save.

Hey Tom

I’ve fixed the formatting for you :)

Are you using a Raspberry Pi or a Raspberry Pi Pico?

What issues do you run into when you try and add those lines into your code?

1 Like

Hi Hel

I am using a Raspberry Pi3g with mics6814.
I also have a few other environmental sensors working fine.
I am not sure how to incorporate those three equations into to the example program and then display the ppm readings on screen. Do I get rid of the “all” reading, are there single “read” commands for each of the three sensors in the mics6814?
Not sure how to proceed.
Thanks for correcting the formatting.
Thanks
Tom

You should be able to get the gas sensor readings separately by doing something like this, if that helps?

import time
from mics6814 import MICS6814

gas = MICS6814()

try:
    while True:
        oxi_rs  = gas.read_oxidising()
        red_rs = gas.read_reducing()
        nh3_rs = gas.read_nh3()
        print(oxi_rs)
        print(red_rs)
        print(nh3_rs)
        time.sleep(1.0)
except KeyboardInterrupt:
    pass

I’m not sure why your formulas use two readings each though - perhaps the original code might tell you what red_rs and red_r0 (for example) refer to?

1 Like