-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
93 lines (83 loc) · 7.5 KB
/
index.html
File metadata and controls
93 lines (83 loc) · 7.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>MakerBlog</title>
<link rel="stylesheet" href="https://www.makerblog.info/theme/css/main.css" />
</head>
<body id="index" class="home">
<header id="banner" class="body">
<h1><a href="https://www.makerblog.info/">MakerBlog </a></h1>
<nav><ul>
<li><a href="https://www.makerblog.info/category/hardware.html">Hardware</a></li>
</ul></nav>
</header><!-- /#banner -->
<aside id="featured" class="body">
<article>
<h1 class="entry-title"><a href="https://www.makerblog.info/cjmcu-811-with-raspberry-pi.html">CJMCU-811 with Raspberry Pi</a></h1>
<footer class="post-info">
<abbr class="published" title="2019-11-09T10:20:00+01:00">
Published: Sa 09 November 2019
</abbr>
<address class="vcard author">
By <a class="url fn" href="https://www.makerblog.info/author/marc.html">Marc</a>
</address>
<p>In <a href="https://www.makerblog.info/category/hardware.html">Hardware</a>.</p>
<p>tags: <a href="https://www.makerblog.info/tag/raspberrypi.html">RaspberryPi</a> <a href="https://www.makerblog.info/tag/sensor.html">Sensor</a> <a href="https://www.makerblog.info/tag/physicalcomputing.html">PhysicalComputing</a> <a href="https://www.makerblog.info/tag/python.html">Python</a> <a href="https://www.makerblog.info/tag/i2c.html">I2C</a> </p>
</footer><!-- /.post-info --><h2>How two measure carbon dioxide CO2 with the Raspberry Pi?</h2>
<p>… with a cheap and not very complex Solution.</p>
<p>There are a lot of different gas sensors out there, which are able to measure a specific gas concentration (MQ Gas Sensors). Some of them are not so expensive like the MG-4 methane sensor (about 3,50 €). There is also a sensor for carbon dioxide which is called MG811, but this sensor costs about 60€. So it’s to expensive for the planned use.</p>
<p>Additional there are two technical disadvantage in combination with the Raspberry Pi. One disadvantage is that all of these gas sensors measures analog values, which can’t be read by the Raspberry Pi directly. So we need a additional analog to digital converter (a/b) like the (MCP3008). They are not very expensive, but makes our solution a little bit more complex. The other disadvantage is the required heating voltage of 6V. This results in two additional challenges. We need a external power solution (Raspberry Pi has only 5V) and we need a logic level converter to reduce the voltage from 6 (or 5V for normal operation) to 3,3 V which is required for the uses with the Raspberry Pi GPIO Ports.</p>
<p>For this reasons I searched for another solution and found the sensor “CJMCU-811”, which can measure the temperature, air quality (VOC) and the CO2 concentration. The required a/b converter is also integrated. So we have an all in one board/sensor! The connection to the Raspberry Pi works over I2C.
The tempature is required for calibration of the sensor. The CO2 concentration is measured as eCO2 value (equivalent calculated carbon-dioxide) within a range of 400 to 8192 parts per million (ppm).</p>
<p>There is a similar sensor from Adafruit with the name CCS811. This sensor looks a little bit different (blue and not red) and has a different pinout, but it’s the same sensor.</p>
<h2>Connection to the Raspberry Pi</h2>
<p>To connect the sensor with a Raspberry Pi we need to enable the I2C Interface. Additional we need to slow down the speed/baudrate of the I2C bus to 10khz, because the RaspberryPi doesn't support "Clock Stretching". Clock Stretching will hold the line down until the sensor (slave) has processed the information. Because this is nt supported we need to slow down the speed to be sure the information is processed until the signal goes to high. Good description about the problem: https://github.com/paulvha/ccs811/blob/master/documents/CCS811_clock_stretch.odt
To change the bus speed we need to add an addtional line to the config.txt file.</p>
<div class="highlight"><pre><span></span>sudo nano /boot/config.txt
</pre></div>
<p>Change bus speed with the additonal line:</p>
<blockquote>
<p>dtparam=i2c_baudrate=10000</p>
</blockquote>
<p>During my test I found some information about problems and inconsistent bus speeds with some Raspberry Pi models, but with my Raspberry Pi 3 B/B+ I can’t figure out any issues regarding the connection to the sensor.</p>
<p>After a reboot we can connect the sensor with the Pi:</p>
<p><img src="https://www.makerblog.info/images/sketch_CJMCU811.png" alt="Sketch" width="750"/></p>
<p>You can check if the Pi can connect to the sensor with the terminal command “i2cdetect -y 1”. If you see the number “5a” with the output table.</p>
<h2>The Python code</h2>
<p>There is an Adafruit code which can be easily installed over “pip” and from GitHub: <a href="https://learn.adafruit.com/adafruit-ccs811-air-quality-sensor?view=all#install-python-software-8-1">https://learn.adafruit.com/adafruit-ccs811-air-quality-sensor?view=all#install-python-software-8-1</a></p>
<p>But during my research I found a good Youtube video with an Gist code: <a href="https://www.youtube.com/watch?v=XNtbV1Z5W3o">https://www.youtube.com/watch?v=XNtbV1Z5W3o</a></p>
<p>The author of this code has integrated an connection to the Thinkspeak API, a data collection cloud service with a dashboard for your values. So you can deploy a dashboard with your values with an Thinkspeak account very easily.</p>
<p>You can download the code with “git” and start it with Python (Version 2).</p>
<div class="highlight"><pre><span></span>git clone https://gist.github.com/xxlukas42/60ae08f75e68a0cfcdb7c9dd60145d34
<span class="nb">cd</span> CJMCU-811
python ccs811.py
</pre></div>
<p>If everthing works correctly you should see an output like this (default measure interval 60 seconds):
<img alt="CJMCU-811 Output" src="https://www.makerblog.info/images/output.png"></p> </article>
</aside><!-- /#featured -->
<section id="extras" class="body">
<div class="blogroll">
<h2>links</h2>
<ul>
<li><a href="https://www.raspberrypi.org/">Raspberry Pi</a></li>
<li><a href="http://python.org/">Python</a></li>
<li><a href="https://pages.github.com/">GitHub Pages</a></li>
</ul>
</div><!-- /.blogroll -->
<div class="social">
<h2>social</h2>
<ul>
<li><a href="https://twitter.com/mb_log">twitter</a></li>
</ul>
</div><!-- /.social -->
</section><!-- /#extras -->
<footer id="contentinfo" class="body">
<address id="about" class="vcard body">
<p align="center">
| <a href="https://www.makerblog.info/pages/impressum.html">Impressum</a> | <a href="https://www.makerblog.info/pages/privacy-policy.html">Privacy Policy</a> |</p></address><!-- /#about -->
Proudly powered by <a href="http://getpelican.com/">Pelican</a>, which takes great advantage of <a href="http://python.org">Python</a>.
<p>The theme is by <a href="http://coding.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/">Smashing Magazine</a>, thanks!</p>
</footer><!-- /#contentinfo -->
</body>
</html>