In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to use TPYBoard development board to make PM2.5 tester, many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
The following is mainly to share how to use less cost, a short time. Make a more accurate pm2.5 detector by yourself.
So what is PM2.5 (fine particles)? (nonsense paragraph)
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'll introduce a way to make a PM2.5 in an hour.
1. The principle of PM2.5 detector
Using the TPYBoard development board as the control processor, the low level of air pollution is detected by the PM2.5 dust sensor GP2Y1010AU0F through the serial port. PM2.5 can distinguish between cigarettes and indoor / outdoor dust, and the current air dust concentration is displayed by the LCD5110 display through the SPI interface (ug/m ³). When the dust concentration in the air reaches the set limit, different LED lamps are lit to know the current air quality level.
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:
Number of PM2.5 values
Average daily concentration (ug/m ³)
Air quality grade
LED lamp statu
050
0-35
Excellent
The green light is on
50 years 100
35-75
Good
The green light is on
100,150
75-115
Mild pollution
The blue light is bright
150, 200.
115-150
Moderate pollution
The yellow light is on
20000300
150-250
Heavy pollution
The red light is on
> 300
> 250
Serious pollution
Red light + yellow light
Refer to 2: TPYBoard hardware features:
-
ü STM32F405RG MCU.
ü 168 MHz Cortex-M4 CPU with 32-bit hardware floatingpoint.
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 the 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.
Figure 1
LCD5110's pins.
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
Figure 2
The whole 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:
Figure 3
Working principle and data processing of PM2.5 Dust Sensor 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.
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 transmitter is installed on one side and a laser receiver 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.
Internal structure simulation diagram
Data processing of PM2.5 Dust Sensor
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 of PM2.5 Dust Sensor and Program coding sampling Frequency of PM2.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.
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.
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.
The link below is a demo video of me using smoke for your reference.
Http://v.youku.com/v_show/id_XMTY5NjM5NDYwMA==.html
source code
Share the source code of the program I wrote to you. If you need it, please refer to it.
# main.py
Import pyb
Import upcd8544
From machine import SPI,Pin
From pyb import UART
From ubinascii import hexlify
From ubinascii import *
# M0 = Pin ('X1neighbors, Pin.OUT_PP)
ITunes 0
Knights 1
Thellos 0
Ethereal 0
Franz 0
White0
Pluto 0
L=0SHUCHU=0
A ratio factor of 800 to 1000 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 murmurMOSI _ CLK = > X6-SCK
# DIN = > SPI (1). MOSI 'X8' data flow (Master out, Slave in)
# CLK = > SPI (1). SCK 'X6' SPI clock
RST = 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):
White1
_ dataRead=u2.readall ()
# print ('_ dataRead=',_dataRead)
Ritual 0
While (W > 0):
# print ('intercept start')
Tipped _ dataRead [R]
If (Troubles 170):
E=R+1
F=R+2
# R=_dataRead [65]
# print ('ten digits =', _ dataRead [E])
# print ('bit =', _ dataRead [F])
White0
R=R+1
Published _ dataRead [E]
Loaded _ dataRead [F]
SHI=P*256+L# converts the hexadecimal data received by the serial port into decimal.
SHUCHU=SHI/G*A
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.