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

Converted c++ code into python #19

Open
davidtme opened this issue Jul 29, 2019 · 10 comments
Open

Converted c++ code into python #19

davidtme opened this issue Jul 29, 2019 · 10 comments
Labels
notice This issue is resolved, but left open for posterity/visibility

Comments

@davidtme
Copy link

I'm trying to converted a bit of c++ code which uses a MiCS6814 to estimate the ppm of the detectable gasses but I'm not sure how to get the equivalent enviroplus-python values for resistance & base resistance with in the getCurrentRatio function which is then used with in the measure function. Could anyone give me any pointers please?

@Gadgetoid
Copy link
Member

Looks like the code you're using talks - via i2c - to an ATmega168 which is what actually handles reading the gas sensor. I can't find the firmware for the ATmega168, so I can't figure out what it actually does.

If I were to hazard a guess, then the baseResistance is just the currently sensed system voltage since their schematic shows a 3V3_SENSE line connected to an ADC channel. The "ratio" in this case, would then be the difference between the gas sensor output voltage and the system voltage.

IE if 3V3_SENSE reads 2048 then we can assume that 2048==3.3v, so if your gas reading reads 1024 and you divide that by 2048 you get 0.5 which you can assume means 1.65v.

This is all pretty much guesswork, but I'd suggest that the ratio value can be calculated from our code by reading adc.get_voltage('in0/gnd') which gives you a voltage, and then dividing that by 3.3 to give you a ratio.

Hopefully working example:

from enviroplus import gas
gas.setup()
ox_ratio = gas.adc.get_voltage('in0/gnd') / 3.3

@davidtme
Copy link
Author

Thanks @Gadgetoid for spending some time on this, any help is much appreciated :)

Looking at set_multiplexer function, would I be able to use the following rather than / 3.3

from enviroplus import gas
gas.setup()
ox_ratio = gas.adc.get_voltage('in0/ref')

@Andermutu
Copy link

Hi @davidtme, @Gadgetoid;

I am also trying to measure gas concentrations, I need to get ppm values for CO, NO2, CH4... and the other detectable gases.

I think that the correct way to do it is as @Gadgetoid says, ox_ratio = gas.adc.get_voltage('in0/gnd') / 3.3. Doing by these way I can measure CO ppm (CO: 5.2351ppm)

But trying the same with ox_ratio = gas.adc.get_voltage('in0/ref') gives a negative ratio, so I would say it is wrong.

Thanks for your ideas and have a nice day.

@davidtme
Copy link
Author

@Andermutu I've tried the adc.get_voltage('in0/gnd') / 3.3 and I get some numbers :)

@psycik
Copy link

psycik commented Oct 23, 2019

This seems to work for me. Do wish I knew how accurate it was though.

ox_ratio = gas.adc.get_voltage('in0/gnd') / 3.3
red_ratio = gas.adc.get_voltage('in1/gnd') / 3.3
nh3_ratio = gas.adc.get_voltage('in2/gnd') / 3.3
co = pow(red_ratio, -1.179) * 4.385
no2 = pow(ox_ratio, -1.007) * 6.855
nh3 = pow(nh3_ratio, -1.67) * 1.47
c3h8 = pow(nh3_ratio, -2.518) * 570.164
c4h10 = pow(nh3_ratio, -2.138) * 398.107
ch4 = pow(red_ratio, -4.363) * 630.957
h2 = pow(red_ratio, -1.8) * 0.73
c2h50h = pow(red_ratio, -1.552) * 1.622
print( 'co: %s ppm' % co)
print( 'no2: %s ppm' % no2)
print( 'nh3: %s ppm' % nh3)
print( 'c3h8: %s ppm' % c3h8)
print( 'c4h10: %s ppm' % c4h10)
print( 'ch4: %s ppm' % ch4)
print( 'h2: %s ppm' % h2)
print( 'c2h50h: %s ppm' % c2h50h)

co: 5.092087296056288 ppm
no2: 33.4387090215078 ppm
nh3: 2.0514111798875017 ppm
c3h8: 942.387572099747 ppm
c4h10: 609.9521573344416 ppm
ch4: 1097.1484880657024 ppm
h2: 0.9171637782593127 ppm
c2h50h: 1.9747757943785347 ppm

@nophead
Copy link

nophead commented Oct 23, 2019

I have two Enviro+ boards and the gas sensors give very different readings in the same room. Not only that they are extremely dependent on a few degrees change in room temperature. The OX sensor also has a slow climb over a month and seems no sign of stopping. I.e. started around 7K but is now 127K.

I don't see how any meaningful absolute readings can be made unless there is some temperature compensation and a calibration procedure to account for the large difference between sensors.

@psycik
Copy link

psycik commented Oct 24, 2019

I have two Enviro+ boards and the gas sensors give very different readings in the same room. Not only that they are extremely dependent on a few degrees change in room temperature. The OX sensor also has a slow climb over a month and seems no sign of stopping. I.e. started around 7K but is now 127K.

I don't see how any meaningful absolute readings can be made unless there is some temperature compensation and a calibration procedure to account for the large difference between sensors.

Interesting, after 24 hours of running this code the values are still relatively close with no climb. I will keep it going but I'd imagine I would have seen a climb by now.

@nophead
Copy link

nophead commented Oct 24, 2019

This is what my first board has done over about 7 weeks, sampled every day. The cyan line is the OX sensor. My second board is on a similar trajectory.

image

@Alexcirlan
Copy link

beautiful chart, I will use it from now on :-)
thank you very much!

@nophead
Copy link

nophead commented Oct 24, 2019

The code is here: https://github.com/nophead/EnviroPlusWeb

@Gadgetoid Gadgetoid added the notice This issue is resolved, but left open for posterity/visibility label Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notice This issue is resolved, but left open for posterity/visibility
Projects
None yet
Development

No branches or pull requests

6 participants