如何用树莓派搭建一个颗粒物传感器
颗粒物 PM2.5 树莓派

> 
> 用树莓派、一个廉价的传感器和一个便宜的屏幕监测空气质量。
> 
> 
> 


![](/data/attachment/album/201906/05/005121bbveeavwgyc1i1gk.jpg)


大约一年前，我写了一篇关于如何使用树莓派和廉价传感器测量[空气质量](/article-9620-1.html)的文章。我们这几年已在学校里和私下使用了这个项目。然而它有一个缺点：由于它基于无线/有线网，因此它不是便携的。如果你的树莓派、你的智能手机和电脑不在同一个网络的话，你甚至都不能访问传感器测量的数据。


为了弥补这一缺陷，我们给树莓派添加了一块小屏幕，这样我们就可以直接从该设备上读取数据。以下是我们如何为我们的移动细颗粒物传感器搭建并配置好屏幕。


### 为树莓派搭建好屏幕


在[亚马逊](https://www.amazon.com/gp/search/ref=as_li_qf_sp_sr_tl?ie=UTF8&tag=openschoolsol-20&keywords=lcd%20raspberry&index=aps&camp=1789&creative=9325&linkCode=ur2&linkId=51d6d7676e10d6c7db203c4a8b3b529a)、阿里巴巴以及其它来源有许多可以买到的树莓派屏幕，从 ePaper 屏幕到可触控 LCD。我们选择了一个便宜的带触控功能且分辨率为 320\*480 像素的[3.5英寸 LCD](https://www.amazon.com/gp/search/ref=as_li_qf_sp_sr_tl?ie=UTF8&tag=openschoolsol-20&keywords=lcd%20raspberry&index=aps&camp=1789&creative=9325&linkCode=ur2&linkId=51d6d7676e10d6c7db203c4a8b3b529a)，可以直接插进树莓派的 GPIO 引脚。3.5 英寸屏幕和树莓派几乎一样大，这一点不错。


当你第一次启动屏幕打开树莓派的时候，会因为缺少驱动屏幕会保持白屏。你得首先为屏幕安装[合适的驱动](https://github.com/goodtft/LCD-show)。通过 SSH 登入并执行以下命令：



```
$ rm -rf LCD-show
$ git clone <https://github.com/goodtft/LCD-show.git>
$ chmod -R 755 LCD-show
$ cd LCD-show/
```

为你的屏幕执行合适的命令以安装驱动。例如这是给我们 MPI3501 型屏幕的命令：



```
$ sudo ./LCD35-show
```

这行命令会安装合适的驱动并重启树莓派。


### 安装 PIXEL 桌面并设置自动启动


以下是我们想要我们项目能够做到的事情：如果树莓派启动，我们想要展现一个有我们空气质量测量数据的网站。


首先，安装树莓派的[PIXEL 桌面环境](/article-8459-1.html)：



```
$ sudo apt install raspberrypi-ui-mods
```

然后安装 Chromium 浏览器以显示网站：



```
$ sudo apt install chromium-browser
```

需要自动登录以使测量数据在启动后直接显示；否则你将只会看到登录界面。然而树莓派用户并没有默认设置好自动登录。你可以用 `raspi-config` 工具设置自动登录：



```
$ sudo raspi-config
```

在菜单中，选择：“3 Boot Options → B1 Desktop / CLI → B4 Desktop Autologin”。


在启动后用 Chromium 打开我们的网站这块少了一步。创建文件夹 `/home/pi/.config/lxsession/LXDE-pi/`：



```
$ mkdir -p /home/pi/config/lxsession/LXDE-pi/
```

然后在该文件夹里创建 `autostart` 文件:



```
$ nano /home/pi/.config/lxsession/LXDE-pi/autostart
```

并粘贴以下代码：



```
#@unclutter
@xset s off
@xset -dpms
@xset s noblank

# Open Chromium in Full Screen Mode
@chromium-browser --incognito --kiosk <http://localhost>
```

如果你想要隐藏鼠标指针，你得安装 `unclutter` 包并移除 `autostart` 文件开头的注释。



```
$ sudo apt install unclutter
```

![移动颗粒物传感器](/data/attachment/album/201906/05/005145ef4gxp4gggupfuiq.jpg "Mobile particulate matter sensor")


我对去年的代码做了些小修改。因此如果你之前搭建过空气质量项目，确保用[原文章](/article-9620-1.html)中的指导为 AQI 网站重新下载脚本和文件。


通过添加触摸屏，你现在拥有了一个便携的颗粒物传感器！我们在学校用它来检查教室里的空气质量或者进行比较测量。使用这种配置，你无需再依赖网络连接或 WLAN。你可以在任何地方使用这个小型测量站——你甚至可以使用移动电源以摆脱电网。




---


这篇文章原来在<ruby> <a href="https://openschoolsolutions.org/mobile-particulate-matter-sensor/">  开源学校解决方案 </a> <rt>  Open Scool Solutions </rt></ruby>上发表，获得许可重新发布。




---


via: <https://opensource.com/article/19/3/mobile-particulate-matter-sensor>


作者：[Stephan Tetzel](https://opensource.com/users/stephan) 选题：[lujun9972](https://github.com/lujun9972) 译者：[tomjlw](https://github.com/tomjlw) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
About a year ago, I wrote about [measuring air quality](https://opensource.com/article/18/3/how-measure-particulate-matter-raspberry-pi) using a Raspberry Pi and a cheap sensor. We've been using this project in our school and privately for a few years now. However, it has one disadvantage: It is not portable because it depends on a WLAN network or a wired network connection to work. You can't even access the sensor's measurements if the Raspberry Pi and the smartphone or computer are not on the same network.


To overcome this limitation, we added a small screen to the Raspberry Pi so we can read the values directly from the device. Here's how we set up and configured a screen for our mobile fine particulate matter sensor.

## Setting up the screen for the Raspberry Pi

There is a wide range of Raspberry Pi displays available from [Amazon](https://www.amazon.com/gp/search/ref=as_li_qf_sp_sr_tl?ie=UTF8&tag=openschoolsol-20&keywords=lcd%20raspberry&index=aps&camp=1789&creative=9325&linkCode=ur2&linkId=51d6d7676e10d6c7db203c4a8b3b529a), AliExpress, and other sources. They range from ePaper screens to LCDs with touch function. We chose an inexpensive [3.5″ LCD](https://amzn.to/2CcvgpC) with touch and a resolution of 320×480 pixels that can be plugged directly into the Raspberry Pi's GPIO pins. It's also nice that a 3.5″ display is about the same size as a Raspberry Pi.

The first time you turn on the screen and start the Raspberry Pi, the screen will remain white because the driver is missing. You have to install [the appropriate drivers](https://github.com/goodtft/LCD-show) for the display first. Log in with SSH and execute the following commands:

```
$ rm -rf LCD-show
$ git clone https://github.com/goodtft/LCD-show.git
$ chmod -R 755 LCD-show
$ cd LCD-show/
```


Execute the appropriate command for your screen to install the drivers. For example, this is the command for our model MPI3501 screen:

`$ sudo ./LCD35-show`


This command installs the appropriate drivers and restarts the Raspberry Pi.

## Installing PIXEL desktop and setting up autostart

Here is what we want our project to do: If the Raspberry Pi boots up, we want to display a small website with our air quality measurements.

First, install the Raspberry Pi's [PIXEL desktop environment](https://opensource.com/article/17/1/try-raspberry-pis-pixel-os-your-pc):

`$ sudo apt install raspberrypi-ui-mods`


Then install the Chromium browser to display the website:

`$ sudo apt install chromium-browser`


Autologin is required for the measured values to be displayed directly after startup; otherwise, you will just see the login screen. However, autologin is not configured for the "pi" user by default. You can configure autologin with the **raspi-config** tool:

`$ sudo raspi-config`


In the menu, select: **3 Boot Options → B1 Desktop / CLI → B4 Desktop Autologin**.

There is a step missing to start Chromium with our website right after boot. Create the folder **/home/pi/.config/lxsession/LXDE-pi/**:

`$ mkdir -p /home/pi/config/lxsession/LXDE-pi/`


Then create the **autostart** file in this folder:

`$ nano /home/pi/.config/lxsession/LXDE-pi/autostart`


and paste the following code:

```
#@unclutter
@xset s off
@xset -dpms
@xset s noblank
# Open Chromium in Full Screen Mode
@chromium-browser --incognito --kiosk http://localhost
```


If you want to hide the mouse pointer, you have to install the package **unclutter** and remove the comment character at the beginning of the **autostart** file:

`$ sudo apt install unclutter`



![Mobile particulate matter sensor Mobile particulate matter sensor](https://opensource.com/sites/default/files/uploads/mobile-aqi-sensor.jpg)

I've made a few small changes to the code in the last year. So, if you set up the air quality project before, make sure to re-download the script and files for the AQI website using the instructions in the [original article](https://opensource.com/article/18/3/how-measure-particulate-matter-raspberry-pi).

By adding the touch screen, you now have a mobile particulate matter sensor! We use it at our school to check the quality of the air in the classrooms or to do comparative measurements. With this setup, you are no longer dependent on a network connection or WLAN. You can use the small measuring station everywhere—you can even use it with a power bank to be independent of the power grid.

*This article originally appeared on Open School Solutions and is republished with permission.*

## 2 Comments