<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Raspberry Pi - Devhour</title>
	<atom:link href="https://www.devhour.net/category/raspberry-pi/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.devhour.net</link>
	<description>Taking time to write about development</description>
	<lastBuildDate>Wed, 20 Mar 2024 08:42:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>

<image>
	<url>https://www.devhour.net/wp-content/uploads/2024/03/cropped-devhourlogo-32x32.png</url>
	<title>Raspberry Pi - Devhour</title>
	<link>https://www.devhour.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Monitoring air quality with a Raspberry Pi &#038; PMS5003 Sensor</title>
		<link>https://www.devhour.net/monitoring-air-quality-with-a-raspberry-pi-pms5003-sensor/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=monitoring-air-quality-with-a-raspberry-pi-pms5003-sensor</link>
					<comments>https://www.devhour.net/monitoring-air-quality-with-a-raspberry-pi-pms5003-sensor/#respond</comments>
		
		<dc:creator><![CDATA[Jamie]]></dc:creator>
		<pubDate>Wed, 20 Mar 2024 07:05:52 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Air Quality]]></category>
		<category><![CDATA[BME680]]></category>
		<category><![CDATA[Humidity]]></category>
		<category><![CDATA[PM10]]></category>
		<category><![CDATA[PM2.5]]></category>
		<category><![CDATA[PMS5003]]></category>
		<category><![CDATA[Pressure]]></category>
		<category><![CDATA[Temperature]]></category>
		<guid isPermaLink="false">https://www.devhour.net/?p=118</guid>

					<description><![CDATA[<p>Unfortunately my family and I live in a country that doesn&#8217;t have the greatest air quality. In order to see how bad it really is I have decided to pull out the Raspberry Pi yet again. Once attached to a Particle Matter sensor I&#8217;ll have my own basic Air Quality/Weather station. This somewhat flows on [&#8230;]</p>
<p>The post <a href="https://www.devhour.net/monitoring-air-quality-with-a-raspberry-pi-pms5003-sensor/">Monitoring air quality with a Raspberry Pi & PMS5003 Sensor</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Unfortunately my family and I live in a country that doesn&#8217;t have the greatest air quality. In order to see how bad it really is I have decided to pull out the Raspberry Pi yet again. Once attached to a Particle Matter sensor I&#8217;ll have my own basic Air Quality/Weather station. This somewhat flows on from my previous series &#8211; <a href="https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2-revised/" title="Raspberry Pi and Motion (Weather App Pt 2) (Revised)">Raspberry Pi and Motion (Weather App Pt 2) (Revised)</a>.</p>



<h2 class="wp-block-heading">Particulate Matter and Air Quality Index</h2>



<p>Air Quality Index (AQI) serves as a crucial tool to convey the current level of air pollution. Health risks increase as the AQI rises. The common pollutants tracked by AQI include ground-level ozone, particulate matter, carbon monoxide, sulfur dioxide, and nitrogen dioxide.</p>



<p>Particulate matter (PM) refers to a mixture of solid particles and liquid droplets found in the air. Particulate matter can be categorized based on the size of the particles:</p>



<ul class="wp-block-list">
<li><strong>PM1.0</strong> refers to particles that are 1.0 micron or smaller in diameter. These particles are so small that they can penetrate the lungs and may even enter the bloodstream, posing significant health risks.</li>



<li><strong>PM2.5</strong>, also known as fine particulate matter, includes particles that are 2.5 microns or smaller in diameter. Because of their size, they can penetrate deep into the lung tissue and have been linked to a variety of health problems, from minor eye and throat irritation to more serious conditions such as heart attacks and decreased lung function.</li>



<li><strong>PM10</strong> includes particles that are 10 microns or smaller in diameter. These particles can cause health issues by irritating the eyes, nose, and throat, and can affect the heart and lungs, making pre-existing lung and heart conditions worse.</li>
</ul>



<h2 class="wp-block-heading">Components Required</h2>



<p>So, to get started, here is a short list of the key components you&#8217;ll need &#8211; at the very least &#8211; to get this small project up and running.</p>



<ul class="wp-block-list">
<li><a href="https://amzn.to/3To5eqb" target="_blank" rel="noopener" title="Raspberry Pi Zero 2 W">Raspberry Pi Zero 2 W</a> (also tested and working on the Raspberry Pi 4 Model B and original Model B)</li>



<li><a href="https://amzn.to/3VGDJej" target="_blank" rel="noopener" title="">PMS5003 Particulate Matter Sensor w/ Breakout Board</a>
<ul class="wp-block-list">
<li><a href="https://shop.pimoroni.com/products/pms5003-particulate-matter-sensor-with-cable?variant=29075640352851" target="_blank" rel="noopener" title="PMS5003 Particulate Matter Sensor">PMS5003 Particulate Matter Sensor</a> (I have also had success with this sensor and breakout from Pimoroni)</li>



<li><a href="https://shop.pimoroni.com/products/particulate-matter-sensor-breakout?variant=29493578301523" target="_blank" rel="noopener" title="Particulate Matter Sensor Breakout">Particulate Matter Sensor Breakout</a></li>
</ul>
</li>



<li><a href="https://amzn.to/3IFOSnI" target="_blank" rel="noopener" title="BME680 Sensor">BME680 Sensor</a> Temperature, Pressure, and Humidity Sensor (Not necessary but can also provide useful additional data)</li>



<li><a href="https://amzn.to/43qo0BB" target="_blank" rel="noopener" title="">Jumper Cables</a> &#8211; Extremely useful for connecting the sensors to the Raspberry Pi</li>
</ul>



<p>I went with the Raspberry Pi Zero because the end goal of this is to stick it outside in a weatherproof enclosure so space will be a limiting factor in the final revision. Key an eye out for future parts where I do that as well as try my hand at PCB design for the ultimate Weather HAT (Hardware Attached on Top).</p>



<h2 class="wp-block-heading">Raspberry Pi Wiring Guide</h2>



<p>Fortunately for us, the wiring for this project is super straight forward. No additional resistors will be required so it&#8217;s as simple as attaching the pins of the sensor to the corresponding pins on the Raspberry Pi.</p>



<p>The two tables below show the pin-out from the sensor boards and the pin that it will be plugged into on the Pi.</p>



<figure class="wp-block-table"><table><tbody><tr><td><strong>Raspberry Pi GPIO Pin</strong></td><td><strong>PMS5003 Breakout Board</strong></td></tr><tr><td>Pin #2 5v</td><td>Pin #1 5v</td></tr><tr><td>Pin #6 Ground</td><td>Pin #2 GND</td></tr><tr><td>Pin #8 GPIO 14 (TXD)</td><td>Pin #3 TX</td></tr><tr><td>Pin #10 GPIO 15 (RXD)</td><td>Pin #4 RX</td></tr><tr><td>Pin #11 GPIO 17</td><td>Pin #5 Reset</td></tr><tr><td>&#8211;</td><td>Pin #6 EN</td></tr></tbody></table><figcaption class="wp-element-caption">Mapping between Raspberry Pi and PMS5003 Sensor</figcaption></figure>



<p></p>



<figure class="wp-block-table"><table><tbody><tr><td>Raspberry Pi GPIO Pin</td><td>BME680 Breakout Board</td></tr><tr><td>Pin #1 3.3v</td><td>Pin #1 2-5v</td></tr><tr><td>Pin #3 GPIO 2 SDA</td><td>Pin #2 SDA</td></tr><tr><td>Pin #5 GPIO 3 SCL</td><td>Pin #3 SCL</td></tr><tr><td>&#8211;</td><td>Pin #4 N/A</td></tr><tr><td>Pin #9 Ground</td><td>Pin #5 GND</td></tr></tbody></table><figcaption class="wp-element-caption">Mapping between Raspberry Pi and BME680 Sensor</figcaption></figure>



<p>And here is a simple diagram for those who are more visually inclined!</p>


<div class="wp-block-image">
<figure class="aligncenter"><img fetchpriority="high" decoding="async" width="624" height="504" src="https://www.devhour.net/wp-content/uploads/2024/03/rpi.png" alt="Raspberry Pi Wiring Diagram" class="wp-image-152" srcset="https://www.devhour.net/wp-content/uploads/2024/03/rpi.png 624w, https://www.devhour.net/wp-content/uploads/2024/03/rpi-300x242.png 300w" sizes="(max-width: 624px) 100vw, 624px" /><figcaption class="wp-element-caption">Wiring Diagram of the Raspberry Pi and PMS5003/BME680 Sensors</figcaption></figure></div>


<h2 class="wp-block-heading">Software Installation</h2>



<h3 class="wp-block-heading">Raspberry Pi Setup</h3>



<p>Firstly, you will need to enable I2C and Serial Port Interfaces on the Pi. Do this by opening the configuration screen:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo raspi-config" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">raspi-config</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>Choose &#8216;Interface Options&#8217; and do the following:</p>



<ol class="wp-block-list">
<li>Enable I2C</li>



<li>Serial Port &#8211; Disable Login Shell</li>



<li>Serial Port &#8211; Enable Serial Port Hardware</li>
</ol>



<p>Next, we need to manually adjust some of the other config settings of the Pi. </p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo nano /boot/config.txt" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">nano</span><span style="color: #575279"> </span><span style="color: #EA9D34">/boot/config.txt</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>Add the following lines to the bottom in order to adjust the communication rate of the I2C interface, and switch the Bluetooth functionality of the Raspberry Pi to mini UART.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="dtparam=i2c_arm_baudrate=10000
enable_uart=1
dtoverlay=pi3-miniuart-bt" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #575279">dtparam=i2c_arm_baudrate=10000</span></span>
<span class="line"><span style="color: #575279">enable_uart=1</span></span>
<span class="line"><span style="color: #575279">dtoverlay=pi3-miniuart-bt</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Plaintext</span></div>



<p>Save the file (Ctrl+x) and reboot the device.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo reboot" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">reboot</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>Once rebooted we can then install Python and a few essential pieces of software in order to communicate programmatically with the sensors.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo apt install build-essential git i2c-tools python3-dev python3-setuptools python3-venv python3-requests python3-smbus python3-serial python3-tz" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">apt</span><span style="color: #575279"> </span><span style="color: #EA9D34">install</span><span style="color: #575279"> </span><span style="color: #EA9D34">build-essential</span><span style="color: #575279"> </span><span style="color: #EA9D34">git</span><span style="color: #575279"> </span><span style="color: #EA9D34">i2c-tools</span><span style="color: #575279"> </span><span style="color: #EA9D34">python3-dev</span><span style="color: #575279"> </span><span style="color: #EA9D34">python3-setuptools</span><span style="color: #575279"> </span><span style="color: #EA9D34">python3-venv</span><span style="color: #575279"> </span><span style="color: #EA9D34">python3-requests</span><span style="color: #575279"> </span><span style="color: #EA9D34">python3-smbus</span><span style="color: #575279"> </span><span style="color: #EA9D34">python3-serial</span><span style="color: #575279"> </span><span style="color: #EA9D34">python3-tz</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>I always recommend creating a virtual environment for new projects because it keeps everything a little more segregated and reduces the risks of conflicts and other issues.</p>



<h3 class="wp-block-heading">Environment Setup</h3>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="mkdir weather &amp;&amp; cd weather
python3 -m venv .venv
source .venv/bin/activate" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">mkdir</span><span style="color: #575279"> </span><span style="color: #EA9D34">weather</span><span style="color: #575279"> </span><span style="color: #797593">&amp;&amp;</span><span style="color: #575279"> </span><span style="color: #B4637A; font-style: italic">cd</span><span style="color: #575279"> </span><span style="color: #EA9D34">weather</span></span>
<span class="line"><span style="color: #D7827E">python3</span><span style="color: #575279"> </span><span style="color: #286983">-m</span><span style="color: #575279"> </span><span style="color: #EA9D34">venv</span><span style="color: #575279"> </span><span style="color: #EA9D34">.venv</span></span>
<span class="line"><span style="color: #B4637A; font-style: italic">source</span><span style="color: #575279"> </span><span style="color: #EA9D34">.venv/bin/activate</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>Now let&#8217;s install python libraries for the PMS5003 and BME680 sensors</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="pip install pms5003 adafruit-circuitpython-bme680 adafruit_extended_bus" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">pip</span><span style="color: #575279"> </span><span style="color: #EA9D34">install</span><span style="color: #575279"> </span><span style="color: #EA9D34">pms5003</span><span style="color: #575279"> </span><span style="color: #EA9D34">adafruit-circuitpython-bme680</span><span style="color: #575279"> </span><span style="color: #EA9D34">adafruit_extended_bus</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<h2 class="wp-block-heading">Testing</h2>



<p>Let&#8217;s create a couple of python files now in order to use these libraries to connect and read the data coming from the sensors:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="nano pmSensor.py" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">nano</span><span style="color: #575279"> </span><span style="color: #EA9D34">pmSensor.py</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="from pms5003 import PMS5003

pms5003 = PMS5003(device=&quot;/dev/ttyAMA0&quot;, baudrate=9600, pin_enable=&quot;GPIO22&quot;, pin_reset=&quot;GPIO27&quot;)

data = pms5003.read()
print(data)" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">from</span><span style="color: #575279"> pms5003 </span><span style="color: #286983">import</span><span style="color: #575279"> </span><span style="color: #286983">PMS5003</span></span>
<span class="line"></span>
<span class="line"><span style="color: #575279">pms5003 </span><span style="color: #286983">=</span><span style="color: #575279"> PMS5003</span><span style="color: #797593">(</span><span style="color: #907AA9; font-style: italic">device</span><span style="color: #286983">=</span><span style="color: #EA9D34">&quot;/dev/ttyAMA0&quot;</span><span style="color: #797593">,</span><span style="color: #575279"> </span><span style="color: #907AA9; font-style: italic">baudrate</span><span style="color: #286983">=</span><span style="color: #D7827E">9600</span><span style="color: #797593">,</span><span style="color: #575279"> </span><span style="color: #907AA9; font-style: italic">pin_enable</span><span style="color: #286983">=</span><span style="color: #EA9D34">&quot;GPIO22&quot;</span><span style="color: #797593">,</span><span style="color: #575279"> </span><span style="color: #907AA9; font-style: italic">pin_reset</span><span style="color: #286983">=</span><span style="color: #EA9D34">&quot;GPIO27&quot;</span><span style="color: #797593">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #575279">data </span><span style="color: #286983">=</span><span style="color: #575279"> pms5003</span><span style="color: #797593">.</span><span style="color: #575279">read</span><span style="color: #797593">()</span></span>
<span class="line"><span style="color: #B4637A; font-style: italic">print</span><span style="color: #797593">(</span><span style="color: #575279">data</span><span style="color: #797593">)</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Python</span></div>



<p>Save the file and then run it.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="python3 pmSensor.py" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">python3</span><span style="color: #575279"> </span><span style="color: #EA9D34">pmSensor.py</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>And you should see the following output:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="PM1.0 ug/m3 (ultrafine particles):                             35
PM2.5 ug/m3 (combustion particles, organic compounds, metals): 53
PM10 ug/m3  (dust, pollen, mould spores):                      55
PM1.0 ug/m3 (atmos env):                                       28
PM2.5 ug/m3 (atmos env):                                       43
PM10 ug/m3 (atmos env):                                        51
&gt;0.3um in 0.1L air:                                            5892
&gt;0.5um in 0.1L air:                                            1656
&gt;1.0um in 0.1L air:                                            324
&gt;2.5um in 0.1L air:                                            25
&gt;5.0um in 0.1L air:                                            1
&gt;10um in 0.1L air:                                             0" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #575279">PM1.0 ug/m3 (ultrafine particles):                             35</span></span>
<span class="line"><span style="color: #575279">PM2.5 ug/m3 (combustion particles, organic compounds, metals): 53</span></span>
<span class="line"><span style="color: #575279">PM10 ug/m3  (dust, pollen, mould spores):                      55</span></span>
<span class="line"><span style="color: #575279">PM1.0 ug/m3 (atmos env):                                       28</span></span>
<span class="line"><span style="color: #575279">PM2.5 ug/m3 (atmos env):                                       43</span></span>
<span class="line"><span style="color: #575279">PM10 ug/m3 (atmos env):                                        51</span></span>
<span class="line"><span style="color: #575279">&gt;0.3um in 0.1L air:                                            5892</span></span>
<span class="line"><span style="color: #575279">&gt;0.5um in 0.1L air:                                            1656</span></span>
<span class="line"><span style="color: #575279">&gt;1.0um in 0.1L air:                                            324</span></span>
<span class="line"><span style="color: #575279">&gt;2.5um in 0.1L air:                                            25</span></span>
<span class="line"><span style="color: #575279">&gt;5.0um in 0.1L air:                                            1</span></span>
<span class="line"><span style="color: #575279">&gt;10um in 0.1L air:                                             0</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Plaintext</span></div>



<p>Next, for the BME680 sensor</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="nano bme680.py" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">nano</span><span style="color: #575279"> </span><span style="color: #EA9D34">bme680.py</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="import adafruit_bme680
import time
import board

from adafruit_extended_bus import ExtendedI2C as I2C

i2c = I2C(1)

bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)

# Change this to the pressure at sea level in your location
bme680.sea_level_pressure = 1002.25

temp = &quot;%0.1f&quot; % bme680.temperature
humidity = &quot;%0.1f&quot; % bme680.relative_humidity
pressure = &quot;%0.3f&quot; % bme680.pressure
altitude = &quot;%0.2f&quot; % bme680.altitude
                
data = {
  'Temperature': temp,
  'Pressure': pressure,
  'Humidity': humidity,
  'Altitude': altitude
}

print(data)" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">import</span><span style="color: #575279"> adafruit_bme680</span></span>
<span class="line"><span style="color: #286983">import</span><span style="color: #575279"> time</span></span>
<span class="line"><span style="color: #286983">import</span><span style="color: #575279"> board</span></span>
<span class="line"></span>
<span class="line"><span style="color: #286983">from</span><span style="color: #575279"> adafruit_extended_bus </span><span style="color: #286983">import</span><span style="color: #575279"> ExtendedI2C </span><span style="color: #286983">as</span><span style="color: #575279"> </span><span style="color: #286983">I2C</span></span>
<span class="line"></span>
<span class="line"><span style="color: #575279">i2c </span><span style="color: #286983">=</span><span style="color: #575279"> I2C</span><span style="color: #797593">(</span><span style="color: #D7827E">1</span><span style="color: #797593">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #575279">bme680 </span><span style="color: #286983">=</span><span style="color: #575279"> adafruit_bme680</span><span style="color: #797593">.</span><span style="color: #575279">Adafruit_BME680_I2C</span><span style="color: #797593">(</span><span style="color: #575279">i2c</span><span style="color: #797593">)</span></span>
<span class="line"></span>
<span class="line"><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Change this to the pressure at sea level in your location</span></span>
<span class="line"><span style="color: #575279">bme680</span><span style="color: #797593">.</span><span style="color: #575279">sea_level_pressure </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #D7827E">1002.25</span></span>
<span class="line"></span>
<span class="line"><span style="color: #575279">temp </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;</span><span style="color: #286983">%0.1f</span><span style="color: #EA9D34">&quot;</span><span style="color: #575279"> </span><span style="color: #286983">%</span><span style="color: #575279"> bme680</span><span style="color: #797593">.</span><span style="color: #575279">temperature</span></span>
<span class="line"><span style="color: #575279">humidity </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;</span><span style="color: #286983">%0.1f</span><span style="color: #EA9D34">&quot;</span><span style="color: #575279"> </span><span style="color: #286983">%</span><span style="color: #575279"> bme680</span><span style="color: #797593">.</span><span style="color: #575279">relative_humidity</span></span>
<span class="line"><span style="color: #575279">pressure </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;</span><span style="color: #286983">%0.3f</span><span style="color: #EA9D34">&quot;</span><span style="color: #575279"> </span><span style="color: #286983">%</span><span style="color: #575279"> bme680</span><span style="color: #797593">.</span><span style="color: #575279">pressure</span></span>
<span class="line"><span style="color: #575279">altitude </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;</span><span style="color: #286983">%0.2f</span><span style="color: #EA9D34">&quot;</span><span style="color: #575279"> </span><span style="color: #286983">%</span><span style="color: #575279"> bme680</span><span style="color: #797593">.</span><span style="color: #575279">altitude</span></span>
<span class="line"><span style="color: #575279">                </span></span>
<span class="line"><span style="color: #575279">data </span><span style="color: #286983">=</span><span style="color: #575279"> </span><span style="color: #797593">{</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #EA9D34">&#39;Temperature&#39;</span><span style="color: #797593">:</span><span style="color: #575279"> temp</span><span style="color: #797593">,</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #EA9D34">&#39;Pressure&#39;</span><span style="color: #797593">:</span><span style="color: #575279"> pressure</span><span style="color: #797593">,</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #EA9D34">&#39;Humidity&#39;</span><span style="color: #797593">:</span><span style="color: #575279"> humidity</span><span style="color: #797593">,</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #EA9D34">&#39;Altitude&#39;</span><span style="color: #797593">:</span><span style="color: #575279"> altitude</span></span>
<span class="line"><span style="color: #797593">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #B4637A; font-style: italic">print</span><span style="color: #797593">(</span><span style="color: #575279">data</span><span style="color: #797593">)</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Python</span></div>



<p>Save it and run it:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="python3 bme680.py" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">python3</span><span style="color: #575279"> </span><span style="color: #EA9D34">bme680.py</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>And the output will appear as follows:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="{'Temperature': '34.0', 'Pressure': '681.287', 'Humidity': '100.0', 'Altitude': '19.72'}" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #575279">{&#39;Temperature&#39;: &#39;34.0&#39;, &#39;Pressure&#39;: &#39;681.287&#39;, &#39;Humidity&#39;: &#39;100.0&#39;, &#39;Altitude&#39;: &#39;19.72&#39;}</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Plaintext</span></div>



<p>I have found that I have to run the BME680 sensor script 3-4 times before it gives me consistent (and I assume) accurate readings.</p>



<h2 class="wp-block-heading">AirQualityPi Project</h2>



<p>As discussed earlier, this is part of a bigger project which I&#8217;ve dubbed AirQualityPi. The idea is to read these sensors several times per hour and store the data. This data can then be displayed on a web dashboard in order to view current values as well as weekly, monthly, and yearly trends as data is gathered.</p>



<p>All of this data flow will be handled via an API (both reading and writing) which I&#8217;ll discuss in a later post. You can view the <a href="https://github.com/Kingy/AirQualityPiSensors/" target="_blank" rel="noopener" title="AirQualityPiSensor">AirQualityPiSensor</a> code over on my GitHub, and keep an eye out for my future posts where I&#8217;ll go over the rest of the project.</p><p>The post <a href="https://www.devhour.net/monitoring-air-quality-with-a-raspberry-pi-pms5003-sensor/">Monitoring air quality with a Raspberry Pi & PMS5003 Sensor</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.devhour.net/monitoring-air-quality-with-a-raspberry-pi-pms5003-sensor/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspberry Pi and Motion (Weather App Pt 2) (Revised)</title>
		<link>https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2-revised/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=raspberry-pi-and-motion-weather-app-pt-2-revised</link>
					<comments>https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2-revised/#comments</comments>
		
		<dc:creator><![CDATA[Jamie]]></dc:creator>
		<pubDate>Wed, 23 Jul 2014 12:37:00 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[Motion]]></category>
		<category><![CDATA[raspberry pi camera]]></category>
		<guid isPermaLink="false">https://www.devhour.net/?p=40</guid>

					<description><![CDATA[<p>Having written the original Raspberry Pi and Motion (Weather App Pt 2) and promptly put it on the back burner (read: got lazy and didn’t finish it) I’ve come back to finish it off. Firstly, I’m going to can the webcam in favour of the Raspberry Pi Camera Module. This is mainly due to the fact that a [&#8230;]</p>
<p>The post <a href="https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2-revised/">Raspberry Pi and Motion (Weather App Pt 2) (Revised)</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Having written the original <a href="https://www.devhour.net/raspberry-pi-and-motion-pt-2/">Raspberry Pi and Motion (Weather App Pt 2)</a> and promptly put it on the back burner (read: got lazy and didn’t finish it) I’ve come back to finish it off.</p>



<p>Firstly, I’m going to can the webcam in favour of the <a href="https://www.raspberrypi.org/help/camera-module-setup/" target="_blank" rel="noreferrer noopener">Raspberry Pi Camera Module</a>. This is mainly due to the fact that a lot of webcams either;</p>



<ol class="wp-block-list">
<li>Don’t work due to lack of driver support</li>



<li>Can’t perform at their optimal resolutions again because of shoddy drivers</li>



<li>Require an external USB hub in order to have enough power to work</li>
</ol>



<p>So after jumping on <a href="https://www.amazon.com/Raspberry-5MP-Camera-Board-Module/dp/B00E1GGE40" target="_blank" rel="noreferrer noopener">Amazon</a> and purchasing the module I got to work setting it up on the Raspberry Pi. There isn’t much to it as it just plugs into small slot behind the ethernet port (pull the tabs out, slide the module in, and shut the tabs). Once you’ve got to that point you need to enable the camera. So power on the Pi and once logged in type the following;</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo raspi-config" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">raspi-config</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>Mid-way down the list of options you’ll see the option to Enable the camera. Do so, and then reboot the device. NB: If you can’t see that option then you need to run update/upgrade on the device first.<a href="https://web.archive.org/web/20170714234055/https://www.devhour.net/wp-content/uploads/2014/07/rpisetup.jpg"></a></p>



<figure class="wp-block-image size-full"><img decoding="async" width="499" height="322" src="https://www.devhour.net/wp-content/uploads/2024/03/RaspberryPiTempSensorPt2-Camera.jpeg" alt="Enable Camera in Raspberry Pi Config" class="wp-image-54" srcset="https://www.devhour.net/wp-content/uploads/2024/03/RaspberryPiTempSensorPt2-Camera.jpeg 499w, https://www.devhour.net/wp-content/uploads/2024/03/RaspberryPiTempSensorPt2-Camera-300x194.jpeg 300w" sizes="(max-width: 499px) 100vw, 499px" /><figcaption class="wp-element-caption">Enable Camera in Raspberry Pi Config</figcaption></figure>



<p>In order to test out the camera simply run the following command after logging in;</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="raspistill -o image.jpg" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">raspistill</span><span style="color: #575279"> </span><span style="color: #286983">-o</span><span style="color: #575279"> </span><span style="color: #EA9D34">image.jpg</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>You should see an image of the camera pop up on screen for a few seconds and then you’ll find a lovely file called image.jpg.</p>



<p>Now natively motion doesn’t work nicely with the camera module but some nice folks have created a port called <a href="https://github.com/dozencrows/motion/tree/mmal-test" target="_blank" rel="noreferrer noopener">motion-mmal</a> that does.</p>



<p>To install it we just run the following;</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="wget https://www.dropbox.com/s/0gzxtkxhvwgfocs/motion-mmal.tar.gztar zxvf motion-mmal.tar.gzsudo ./motion -c motion-mmalcam.conf" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">wget</span><span style="color: #575279"> </span><span style="color: #EA9D34">https://www.dropbox.com/s/0gzxtkxhvwgfocs/motion-mmal.tar.gztar</span><span style="color: #575279"> </span><span style="color: #EA9D34">zxvf</span><span style="color: #575279"> </span><span style="color: #EA9D34">motion-mmal.tar.gzsudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">./motion</span><span style="color: #575279"> </span><span style="color: #286983">-c</span><span style="color: #575279"> </span><span style="color: #EA9D34">motion-mmalcam.conf</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>As you can see the new config file is called motion-mmalcam.conf and can (and should be) edited as required. I won’t go through that here as we already covered that in the previous post.</p>



<p>I promise this time that I’m going to continue on with this series and as I said last time I’m going to write a python script that will grab the weather temperature when motion takes a snapshot. From there I’ll be showing you 2 things. The first will be to set up a web page which shows an image + temperature. The second, sending the time/temperature to a 20×4 LCD screen <img src="https://s.w.org/images/core/emoji/15.1.0/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>So stay tuned and as always you can follow me on twitter <a href="https://twitter.com/JAGracie">@JAGracie</a></p><p>The post <a href="https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2-revised/">Raspberry Pi and Motion (Weather App Pt 2) (Revised)</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2-revised/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Raspberry Pi Temperature Sensing Pt 1</title>
		<link>https://www.devhour.net/raspberry-pi-temperature-sensing-pt-1/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=raspberry-pi-temperature-sensing-pt-1</link>
					<comments>https://www.devhour.net/raspberry-pi-temperature-sensing-pt-1/#respond</comments>
		
		<dc:creator><![CDATA[Jamie]]></dc:creator>
		<pubDate>Wed, 30 Apr 2014 12:10:00 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[DS18B20]]></category>
		<category><![CDATA[Temperature Sensor]]></category>
		<guid isPermaLink="false">https://www.devhour.net/?p=15</guid>

					<description><![CDATA[<p>This tutorial is going to teach you how to set up a Raspberry Pi Temperature sensor using GPIO pins and Occidentalis. So like many others before me I decided to pick up a Raspberry Pi to see what all the fuss is about. Now for those stuck under a rock or if you genuinely don’t [&#8230;]</p>
<p>The post <a href="https://www.devhour.net/raspberry-pi-temperature-sensing-pt-1/">Raspberry Pi Temperature Sensing Pt 1</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>This tutorial is going to teach you how to set up a Raspberry Pi Temperature sensor using GPIO pins and Occidentalis.</p>



<p>So like many others before me I decided to pick up a Raspberry Pi to see what all the fuss is about. Now for those stuck under a rock or if you genuinely don’t know what a Raspberry Pi is, it is basically a small computer slightly bigger than a credit card with a cost of less than $50.</p>



<p>With it’s small size, fairly decent specs and the ability to play HD video the options with the Pi  are virtually endless. Add to that the GPIO pins that are attached to the board and it really does open up a whole new world. Already we have seen projects along the lines of <a href="https://www.reddit.com/r/raspberry_pi/comments/y0ehp/video_my_basic_raspberry_pi_home_automation_setup/">home automation</a>, <a href="https://www.raspbmc.com/">media centres</a>, <a href="https://www.youtube.com/watch?v=UjBV6pecjMM">in-car computers</a> and <a href="https://www.raspberrypi.org/archives/2412">arcade gaming</a>.</p>



<p>I haven’t had a lot of time to play around or do much development with it but I’ve decided on making a mini weather application. The plan is that around every hour the application will take the current temperature and an image (using a webcam with Motion) before uploading the results to a website (running via a web server on the Raspberry Pi).</p>



<p>Part 1 is going to be all about setting up the Raspberry Pi temperature sensor and reading the data from it.</p>



<h2 class="wp-block-heading">What you will need</h2>



<ul class="wp-block-list">
<li>Raspberry Pi</li>



<li><a href="https://web.archive.org/web/20160611142626/http://www.adafruit.com/products/914">Adafruit P</a><a href="https://www.adafruit.com/products/914">i</a><a href="https://web.archive.org/web/20160611142626/http://www.adafruit.com/products/914"> Cobbler</a> (optional)</li>



<li><a href="https://www.adafruit.com/products/64">Breadboard</a> (optional)</li>



<li><a href="https://www.ebay.co.uk/itm/DS18b20-Waterproof-digital-probe-thermometer-temperature-sensor-thermal-/130864369025?pt=UK_BOI_Electrical_Components_Supplies_ET&amp;hash=item1e781fcd81">DS18B20 temperature sensor</a></li>



<li>4.7k ohm resistor</li>
</ul>



<h2 class="wp-block-heading">Raspberry Pi Temperature Sensor</h2>



<p>The first step is really setting up the Raspberry Pi itself. This has been done to death in <a href="https://www.google.com/#hl=en&amp;sclient=psy-ab&amp;q=raspberry+pi+setup&amp;oq=raspberry+pi+setup">multiple tutorials</a> so I’m not going to go into the details. I’m currently using the Occidentalis v0.2 distro by Adafruit which by default comes with a lot of the packages you will need.</p>



<p>Once this is all setup and you’re happy then it’s time to move on to wiring up the DS18B20 Raspberry Pi temperature sensor. In the parts list I’ve put the Adafruit Pi Cobbler and breadboard as optional but I highly suggest you get them. It makes life a lot easier and can easily save you from doing damage to the Raspberry Pi itself.</p>



<p>It’s very important to get the wire input correct otherwise you run the risk of killing the sensor before you even get it working. The sensor that I’m using (link in the parts list) uses the following.&nbsp;Red = Power, Yellow = Data, Green = Ground. So applying this layout, on the Pi Cobbler/Raspberry Pi we place the Red wire on the 3.3v pin, the Yellow wire on the GPIO #4 pin and the Green wire on the GND pin. The 4.7k resistor goes between the PWR and Data wires (Red and Yellow).</p>


<div class="wp-block-image is-style-default">
<figure class="aligncenter size-medium"><img decoding="async" width="240" height="300" src="https://www.devhour.net/wp-content/uploads/2014/04/RaspberryPiTempSensorPt1-Wiring-240x300.png" alt="Raspberry Pi Temperature Sensor Wiring Diagram" class="wp-image-50" style="object-fit:cover" srcset="https://www.devhour.net/wp-content/uploads/2014/04/RaspberryPiTempSensorPt1-Wiring-240x300.png 240w, https://www.devhour.net/wp-content/uploads/2014/04/RaspberryPiTempSensorPt1-Wiring.png 753w" sizes="(max-width: 240px) 100vw, 240px" /><figcaption class="wp-element-caption">Raspberry Pi Temperature Sensor Wiring Diagram</figcaption></figure></div>


<p><strong>NB:</strong>&nbsp;There are two things to note. Firstly, if by the end of this tutorial nothing is working then try placing the Red PWR wire on the 5.5v pin instead of 3.3v. The 3.3v didn’t work for me (and &nbsp;hasn’t for many others) so give this a go. Secondly, if you turn the Pi on and the sensor gets extremely hot (enough to burn you when you touch it) then you have the pin layout wrong and need to double check the wire layout.</p>



<p>Now it’s time to fire up the Raspberry Pi and start reading some temperatures. Once it has booted up you need to firstly use the ‘modprobe’ command to load up the GPIO module in order to read the sensors data. So using ssh or desktop type:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo modprobe w1-gpiosudo modprobe w1-therm" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">modprobe</span><span style="color: #575279"> </span><span style="color: #EA9D34">w1-gpiosudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">modprobe</span><span style="color: #575279"> </span><span style="color: #EA9D34">w1-therm</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>Next browse to the system devices folder to find the Raspberry Pi temperature sensor device.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="cd /sys/bus/w1/devicesls" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #B4637A; font-style: italic">cd</span><span style="color: #575279"> </span><span style="color: #EA9D34">/sys/bus/w1/devicesls</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>When you issue the listing command under this directory you should see a folder beginning with 28-00000. This is your temperature sensor device. Go into this directory and read out the temperature by issuing the command:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="cd 28-00000xxxx # change this to your folder name
cat w1-slave" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #B4637A; font-style: italic">cd</span><span style="color: #575279"> </span><span style="color: #D7827E">28</span><span style="color: #EA9D34">-00000xxxx</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> change this to your folder name</span></span>
<span class="line"><span style="color: #D7827E">cat</span><span style="color: #575279"> </span><span style="color: #EA9D34">w1-slave</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>You will see an output similar to this:</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="675" height="424" src="https://www.devhour.net/wp-content/uploads/2024/03/RaspberryPiTempSensorPt1-Output.png" alt="Raspberry Pi Temperature Sensor Output" class="wp-image-52" srcset="https://www.devhour.net/wp-content/uploads/2024/03/RaspberryPiTempSensorPt1-Output.png 675w, https://www.devhour.net/wp-content/uploads/2024/03/RaspberryPiTempSensorPt1-Output-300x188.png 300w" sizes="auto, (max-width: 675px) 100vw, 675px" /><figcaption class="wp-element-caption">Raspberry Pi Temperature Sensor Output</figcaption></figure>



<p>The output will display either YES or NO at the end of the top line. If it is YES, then the temperature is valid and will be at the end of the bottom line. It will show as the temp*1000 so if it looks like a large number just divide it by 1000 to get the correct reading. Eg: 21500/1000 = 21.5C. If it displays NO then re-issue the ‘cat w1-slave’ until you get a correct reading.&nbsp;Putting your fingers over the sensor and issuing the cat command again should show the temperature going up.</p>



<p>Now one annoying part is that each time the Raspberry Pi is restarted you need to re-issue the modprobe commands. A neat little hint I found online will solve this problem. So type this command into a shell terminal and the modprobe commands will be done on startup!</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo sh -c &quot;echo 'w1_gpio\nw1_therm\n' &gt;&gt; /etc/modules&quot;" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">sh</span><span style="color: #575279"> </span><span style="color: #286983">-c</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;echo &#39;w1_gpio\nw1_therm\n&#39; &gt;&gt; /etc/modules&quot;</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>This is all there is to it. In part 3 of this series I’m going to write a python script which will grab the temperature automatically for you as well as some other neat stuff. Next up though will be getting a webcam and motion working to go side by side with the Raspberry Pi temperature sensor.</p>



<p>Until then feel free to leave a comment or any questions (I’ll do my best to answer) and don’t forget to follow me on <a href="https://twitter.com/JAGracie" target="_blank" rel="noreferrer noopener">twitter</a>!</p><p>The post <a href="https://www.devhour.net/raspberry-pi-temperature-sensing-pt-1/">Raspberry Pi Temperature Sensing Pt 1</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.devhour.net/raspberry-pi-temperature-sensing-pt-1/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Raspberry Pi and Motion (Weather App Pt 2)</title>
		<link>https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=raspberry-pi-and-motion-weather-app-pt-2</link>
					<comments>https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2/#respond</comments>
		
		<dc:creator><![CDATA[Jamie]]></dc:creator>
		<pubDate>Mon, 06 May 2013 12:12:00 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Motion]]></category>
		<guid isPermaLink="false">https://www.devhour.net/?p=17</guid>

					<description><![CDATA[<p>Part 2 in this series is going to show you how to setup Raspberry Pi and Motion in order to snap a picture every 10 minutes or so. If you haven’t already read Part 1 in this series to check out how to set up a Raspberry Pi temperature sensor with the DS18B20 sensor. Having setup the [&#8230;]</p>
<p>The post <a href="https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2/">Raspberry Pi and Motion (Weather App Pt 2)</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Part 2 in this series is going to show you how to setup Raspberry Pi and Motion in order to snap a picture every 10 minutes or so.</p>



<p>If you haven’t already read Part 1 in this series to check out how to set up a <a href="https://www.devhour.net/raspberry-pi-temperature-weather-app/">Raspberry Pi temperature sensor</a> with the DS18B20 sensor.</p>



<p>Having setup the temperature sensor and tested that it can read the temperature correctly, I can now move on to setting up our camera to capture an image of the weather every 10 minutes.</p>



<p>Fortunately I did have a spare web cam lying around but you could get away with spending a couple of dollars and getting a fairly cheap web camera that’ll do the trick.</p>



<p>Now to do this I am going to use a pretty cool piece of software called <a href="https://www.lavrsen.dk/foswiki/bin/view/Motion">Motion</a>. Motion is a piece of software which uses video4linux device to detect motion and can be used to take both videos and pictures. It also has a pretty powerful trigger action settings which allows you to run shell commands after/before a certain event in order to perform extra actions (eg Send an email or upload the video/picture). I will make use of these in the next part of this series in order to grab the current temperature after the image has been taken.</p>



<p>One of the cool things people have used Motion for is to make a basic home security system. Have a webcam pointed at the driveway or main entrance to your house and then have motion take a video or picture of anyone who approaches. Upload the video to a remote location and send you an email letting you know you have a visitor. Works quite well and for ~$50 is a cheap solution.</p>



<p>For now though I am going simpler. Tell Motion to take a picture of whatever the web camera is pointing at every 10 minutes and move the picture to our images folder (later used for the website I make). In my case I will be pointing my web cam out the window in order to see the weather.</p>



<h2 class="wp-block-heading">Setup Raspberry Pi and Motion</h2>



<p>Firstly, install and setup motion on the Raspberry Pi.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="# Update and upgrade the Raspberry Pi
sudo apt-get update
sudo apt-get upgrade

# Install motion
sudo apt-get install motion" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Update and upgrade the Raspberry Pi</span></span>
<span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">apt-get</span><span style="color: #575279"> </span><span style="color: #EA9D34">update</span></span>
<span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">apt-get</span><span style="color: #575279"> </span><span style="color: #EA9D34">upgrade</span></span>
<span class="line"></span>
<span class="line"><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Install motion</span></span>
<span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">apt-get</span><span style="color: #575279"> </span><span style="color: #EA9D34">install</span><span style="color: #575279"> </span><span style="color: #EA9D34">motion</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>Then edit the config file.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="# Tell the service to start in daemon mode
sudo nano /etc/default/motion
start_motion_daemon=yes

# Make these changes to the motion config file
sudo nano /etc/motion/motion.conf
daemon on
snapshot_interval 600
output_normal off
ffmpeg_cap_new off
target_dir /home/pi/motion/images" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Tell the service to start in daemon mode</span></span>
<span class="line"><span style="color: #575279">sudo nano /etc/default/motion</span></span>
<span class="line"><span style="color: #286983">start_motion_daemon</span><span style="color: #797593">=</span><span style="color: #575279">yes</span></span>
<span class="line"></span>
<span class="line"><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Make these changes to the motion config file</span></span>
<span class="line"><span style="color: #575279">sudo nano /etc/motion/motion.conf</span></span>
<span class="line"><span style="color: #575279">daemon on</span></span>
<span class="line"><span style="color: #575279">snapshot_interval 600</span></span>
<span class="line"><span style="color: #575279">output_normal off</span></span>
<span class="line"><span style="color: #575279">ffmpeg_cap_new off</span></span>
<span class="line"><span style="color: #575279">target_dir /home/pi/motion/images</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">INI</span></div>



<p>The above changes made to the config are only a handful of the options you will see inside the file. The general idea of the changes I made are to turn off video recording and to tell motion to take a snapshot every 10 minutes and to then save the file to the images directory. Feel free to play around but these settings will get me doing what I need to do.</p>



<h2 class="wp-block-heading">Start Motion on the Raspberry Pi</h2>



<p>You probably want to start motion in debug mode the first time around just to make sure everything is as it should be.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo motion -n" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">motion</span><span style="color: #575279"> </span><span style="color: #286983">-n</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>This will display output to the screen and every 10 minutes you should see snapshots getting saved to the output directory.</p>



<p>Check the directory and download the images to make sure you are getting the desired output and if all is as expected you can now start the motion service.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="sudo service motion start" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #D7827E">sudo</span><span style="color: #575279"> </span><span style="color: #EA9D34">service</span><span style="color: #575279"> </span><span style="color: #EA9D34">motion</span><span style="color: #575279"> </span><span style="color: #EA9D34">start</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">Bash</span></div>



<p>That’s it! Raspberry Pi and Motion is now set up. Pretty easy and straight forward. Like I said though, this is one of the more basic uses of motion and it can be used to do a lot more. Have a play around and let me know what you come up with. I’m always interested!</p>



<p>The next part of this tutorial series I will be showing you how to write a python script which will be executed using the motion action trigger.</p>



<p>So stay tuned and as always you can follow me on twitter <a href="https://twitter.com/JAGracie">@JAGracie</a></p><p>The post <a href="https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2/">Raspberry Pi and Motion (Weather App Pt 2)</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.devhour.net/raspberry-pi-and-motion-weather-app-pt-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
