Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the TPYBoard development board supporting MicroPython to make a self-made PM2.5 detector

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the TPYBoard development board that supports MicroPython to make a self-made PM2.5 tester, the content of the article is of high quality, so the editor shares it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

The persistence of haze weather in autumn and winter makes people pay more attention to air quality. Recently, people's attention to air quality can not get around a word-"PM2.5". The Environmental Air quality Standard (Ambient Air quality Standard) incorporates PM2.5 and ozone (concentration of 8 hours) into routine air quality assessment. It is the first time that China has formulated a monitoring standard for PM2.5. Fine particles are also known as fine particles, fine particles, PM2.5. Fine particles refer to particles in the ambient air whose aerodynamic equivalent diameter is less than or equal to 2.5 microns. PM2.5 has the advantages of small particle size, large area, strong activity, easy to be accompanied by toxic and harmful substances (such as heavy metals, microorganisms, etc.). PM2.5 is a fatal hazard to human health.

So what is PM2.5 (fine particles)?

Because the standards are different in different countries, the weather forecast also reports the air quality. is the forecast air quality the same as the actual air quality? But this problem, want to make a PM2.5 detector, with self-made PM2.5 detector, when the air quality is poor or serious pollution, remind family members, classmates and people around to reduce outdoor activities as much as possible, really reduce the inhalation of fine particles.

The idea of making a PM2.5 tester is good. Can you make a PM2.5 tester within an hour? It takes a long time or even half a year to learn the C language first, then consider hands-on production, let alone make a PM2.5 detector within an hour.

Next, I would like to introduce a way to make a PM2.5 within an hour, that is, to make a PM2.5 tester using your own parser, compiler, virtual machine and class library, that is, a TPYBoard development board with secondary development and environment.

1. The purpose of PM2.5 detector

The TPYBoard development board is used as the control processor, and the low degree of air pollution is detected by the PM2.5 dust sensor GP2Y1010AU0F through the serial port. PM2.5 can distinguish cigarettes and indoor / outdoor dust, and the current air dust concentration (ug/m?) is displayed by the LCD5110 display through the SPI interface. When the dust concentration in the air reaches the set limit, different LED lamps are lit to know the current air quality level.

The system has the advantages of simple circuit, stable operation, high integration, convenient debugging and high testing precision, and has certain practical value. The detector uses Python script language to access and control the fine particle detection sensor at the bottom of the hardware. Every interval, the sensor automatically detects, and the detected air dust concentration data is uploaded to the main control board through the serial port. After the main control board collects the data, the Python script language is also used to display the detection results of PM2.5 to LCD5110.

Refer to the index grade corresponding table of 1:TPYBoardLED lighting status and PM2.5 daily average concentration:

Refer to 2: TPYBoard hardware features:

-

ü STM32F405RG MCU.

ü 168 MHz Cortex-M4 CPU with 32-bit hardware floating point.

1 MiB flash storage, 192 KiB RAM.

ü USB port, support serial port, general storage, HID protocol.

ü SD card slot.

ü MMA76603 axis accelerometer.

4 LEDs, 1 reset button, 1 universal button.

ü 3.3V0.3A on-board LDO, which can be powered from the USB port or external battery.

U real-time clock.

There are 30 general IO ports, of which 28 support 5V input and output.

2 SPI interfaces, 2 CAN interfaces, 2 I 2C interfaces, 5 USART interfaces.

14 12-bit ADC pins.

ü 2 DAC pins.

-

two。 Material preparation

The materials needed to make the PM2.5 detector are as follows:

1.PM2.5 dust sensor, detection of PM2.5 (fine particles) sensor, TXD serial port output.

2.TPYBoard development board 1, mainly used as the main control development board, read sensor data.

One 3.Lcd5110 display screen, which is mainly used to display the detected information.

4. How many DuPont lines.

5. A data cable.

3. Hardware wiring method

3.1 Pins of the sensor

There are six wires on the sensor, from 1 to 6 is GND,VCC,NC,NC,RX,TX. Which we only use three wires, power (GND,VCC) and serial port (TX), the sensor and TPYBorad connection refer to figure 1, specific serial port please refer to the official website document TPYBoard on the use of serial port, Xiaobian used serial port for UART (2) is on: (TX, RX) = (X3, X4) = (PA2, PA3), because only need to transfer data to PTYBoard, so only use RED that is PTYBoard X4 pin.

3.2 LCD5110 pins

Take a look at the meaning of LCD5110 stitches first. (note: LCD5110 stitches are a little different.

The corresponding relationship between the pins of TPYBoard and those of 5110 is shown in figure 2:

TPYBoard? LCD5110??? Memo

-

# any? Pin???? = > RST? Reset pin (0=reset, 1=normal)

# any? Pin???? = > CE? Chip Enable (0=listen for input,? 1=ignore input)

# any? Pin???? = > DC? Data/Command (0=commands, 1=data)

# MOSI? = > DIN? Data flow (Master out, Slave in)

# SCK?= > CLK? SPI clock

# 3V3 or any Pin? = > VCC? 3.3V logic voltage (0=off, 1=on)

# any Pin? = > LIGHT???? Light (0=on, 1=off)

# GND?= > GND

If you still don't understand, just put the pin number on it.

TPYBoard? LCD5110??? Memo

-

Y10? = > RST? Reset pin (0=reset, 1=normal)

Y11? = > CE? Chip Enable (0=listen for input, 1=ignore input)

Y9? = > DC? Data/Command (0=commands, 1=data)

X8? = > DIN? Data flow (Master out, Slave in)

X6? = > CLK? SPI clock

VCC

Y12? = > LIGHT???? Light (0=on, 1=off)

GND

3. 3 integral wiring method of PM2.5 detector

Connect the PM2.5 dust sensor and the 5110 display screen to the PTYBoard as shown in figure 1 and figure 2, and the hardware is connected, as shown in figure 3:

Working principle and data processing of 4.PM2.5 Dust Sensor

4.1the working principle of PM2.5 dust sensor

The working principle of PM2.5 dust sensor is based on the principle of light scattering, particles and molecules will produce light scattering phenomenon, at the same time, also absorb part of the energy of irradiated light. Radish education subject programming tpyboard. Com

When a beam of parallel monochromatic light is incident on the measured particle field, it will be affected by the scattering and absorption around the particle, and the light intensity will be attenuated. In this way, the relative attenuation rate of the incident light passing through the concentration field to be measured can be obtained. The relative decay rate can basically linearly reflect the relative concentration of dust in the field to be tested. The intensity of light is proportional to the intensity of the photoelectric converted electrical signal. The relative attenuation rate can be obtained by measuring the electrical signal, and then the concentration of dust in the field to be tested can be determined. There is a hole in the middle of the sensor that allows air to flow through it. At the two edges of the hole, a laser emission qi is installed on one side and a laser receiver is installed on the other. In this way, the air flows through this small hole, and the particles in the air will block the laser and produce scattering, and the receiver on the other side sends out different signals according to the intensity of the laser received (in fact, it outputs different voltage values). In this way, the more particles in the air, the higher the output voltage, the less the particles, the lower the output voltage.

The internal structure is shown in the internal structure simulation diagram.

4.2 PM2.5 dust sensor data processing

The principle of the sensor is mentioned above, and then let's talk about the signal it sends out and the calculation of the signal it receives.

The output data of this sensor is transmitted through the serial port, and the sensor will send one data per 10ms (usually 3~4ms) through the serial port. The data type is roughly hexadecimal data such as "0X00". Each data will start with "0XAA" and end with "0XFF". A total of 7 data bits, 7 data bits include the start bit, the end bit, the data high bit, the data low bit, the data university check bit, the data low check bit and the check bit (how the check bit is calculated, which will be discussed below). The data format is roughly as follows:

Where the check bit length = the length of Vout (H) + Vout (L) + Vref (H) + Vref (L).

The composition of the data is a total of seven data bits, but only Vout (H) and Vout (L) are the data we really need. We need to calculate the digital data of the serial port output according to these two data, so as to calculate the output voltage through the digital-to-analog conversion formula. Furthermore, the number of particles in the air is calculated by the proportional coefficient. Let's talk about how to calculate it.

The output data of the sensor can be divided into high bit and low bit, in which Vout (H) is high and Vout (L) is low. Because the Vout (H) and Vout (L) passed through the serial port are hexadecimal, the first step is to convert them into decimal (which everyone can do, not to mention). Then the voltage of the serial output value is calculated according to the decimal number of the two output values.

The formula is as follows (where Vout (H) and Vout (L) have been converted to decimal):

Vout= (Vout (H) * 256+Vout (L)) / 102405

In this way, the voltage output from him is calculated, and then according to the proportional coefficient A, the value of particles in the air can be calculated. (the value of An is usually between 800 and 1000, and the specific value should be determined according to the accuracy, accuracy and error of the sensor you buy. I'm using 800 now. )

Sampling Frequency and Program coding of 5.PM2.5 Dust Sensor

Sampling Frequency of 5.1PM2.5 Dust Sensor

The sampling frequency of PM2.5 dust sensor is very high. Generally, 3~4ms sends a hexadecimal sampling data, that is to say, after the sensor is powered on (turn on VCC and GND), it sends hexadecimal sampling data every 3~4ms. Such a high sampling frequency is obviously not necessary as a detector.

TPYBoard receives the dust sensor data through the serial port. Of course, the serial port is defined first by using the serial port. By opening the serial port, you can receive the serial port data, and when the serial port is closed, you can stop receiving the data, which comes from controlling the sampling frequency of the PM2.5 dust sensor.

5.2 Program coding

In our main.py, the serial port is defined first, then the serial port is opened to receive the sampling data, and finally the serial port is closed, and the sampling data and display are processed and cycled in turn.

6. Run the test

After wiring ok, import font.py file and upcd8544.py file (mainly used for 5110 display data), and then run main.py to see the current air quality level and PM2.5 concentration value.

7. source code

Share the source code of the program I wrote to you. If you need it, please refer to it.

# main.pyimport pybimport upcd8544from machine import SPI,Pinfrom pybimport UARTfrom ubinascii import hexlifyfrom ubinascii import * # M0 = Pin ('X1 ratio, Pin.OUT_PP) i=0K=1T=0E=0F=0W=0P=0L=0SHUCHU=0A=800#A ratio coefficient, which is generally used in the north. The air in the south is better, usually 600-800. This is also related to the sensitivity of the sensor you use, and you need to test it yourself. Graph 1024Universe G is a fixed coefficient, which is used to convert the data received by the serial port into the PM standard value. SHI=0# will then assign values that are converted to decimal values. # * * main program * * # pyb.delay (5000) SPI = pyb.SPI (1) # DIN= > X8 Mosi data flow CLK = > X6-SCK#DIN = > SPI (1). MOSI 'X8' data flow (Master out) Slave in) # CLK = > SPI (1). SCK 'X6' SPI clockRST = pyb.Pin (' Y10') CE = pyb.Pin ('Y11') DC = pyb.Pin (' Y9') LIGHT = pyb.Pin ('Y12') while True: U2 = UART (2 2400) pyb.delay (1000) # print ('kaishi') u2.deinit () pyb.delay (10) if (u2.any () > 0): Whum1 _ dataRead=u2.readall () # print ('_ dataRead=' _ dataRead) Run0 while (W > 0): # print ('start of intercept') Tunable _ dataRead [R] if (Troup170): E=R+1 F=R+2 # R=_dataRead [65] # print ('ten digits =', _ dataRead [E]) # print ('bit =' _ dataRead [F]) Word0 R=R+1 packets _ dataRead [E] loaded _ dataRead [F] SHI=P*256+L# converts the hexadecimal data received by the serial port into decimal. SHUCHU=SHI/G*An if (SHUCHU

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report