International Journal of Advanced Network, Monitoring and Controls Volume 03, No.03, 2018 DOI: 10.21307/ijanmc-2019-008 70 Readings of Portable UV Spectrum Analyzer Data Based on Raspberry Pi Xu Shuping School of Computer Science and Engineering Xi’an Technological University Xi’an, 710021, China e-mail:xusp686@163.com Huang Mengyao, Xu Pei School of Computer Science and Engineering Xi’an Technological University Xi’an, 710021, China Abstract—Most of the spectrometer has the advantages of large volume, inconvenient carrying, slow data reading, long development cycle and high cost. In view of this situation, this paper presents a raspberry based portable spectrum analyzer. The general structure, working principle and data reading principle of the portable ultraviolet spectrum analyzer system based on raspberry faction are introduced in detail. And the raspberry sent a brief introduction, and finally introduced the raspberry pie to the development of the environment configuration, and the use of Python-Qt prepared control software for data read. The final test shows that the system interface is simple and friendly, stable operation, you can quickly read the data from the spectrometer, to meet the actual requirements. Keywords-Spectrometer; Raspberry Pi; Working Principle; Data Reading I. INTRODUCTION The micro-spectrometer has advantages of modular structure and flexible construction, so inpractice, only a spectrometer is needed, and the software can detect different samples in realtime [5]. At the same time, the micro-spectrometer has advantages of small size, easy to carry, compact internal structure, wide wavelength range, fast detection speed and low price. It has wide application development space in the field of industrial online monitoring and portable detection [8]. At present, the portable spectrometer in domestic and foreign market has two main methods: electrochemical analysis and infrared spectrometry[2]. The electrochemical analysis method has the advantages of simple structure and easy operation. It mainly depends on the gas sensor, and a gas sensor can only detect a corresponding gas, and the gas sensor also has a life limit, the use of a period of time, the sensitivity of the gas will be reduced, the need to replace gas sensors, and gas sensors are expensive, increasing the cost of use for the user. The main principle of the gas sensor is the use of gas oxidation or reduction reaction, the current, but if both the presence of oxidizing gas and reducing gas, the measurement results will be inaccurate [7]. Infrared spectroscopy overcomes the shortcomings of electrochemical analysis, but it can only measure the approximate concentration of NOx, and it cannot accurately measure the specific concentration of NO and NO2, and the infrared spectral analysis method is more complicated than the environment humidity, temperature, etc [6]. Based on the above problems, this paper presents a portable UV spectrometer developed using Maya2000Pro UV spectrometer and raspberry pi, according to the UV light wavelength 190nm-290nm, the gas has good absorption of ultraviolet light, and the measurement is absorbed by the gas, after the UV light, which can read through the spectrometer wavelength and photon number. The ultraviolet spectral analysis has the advantages of high reliability, strong anti-interference, and a variety of gases can be measured at the same time, accurate measurement and so on. The portable spectrometer has the advantages of fast data reading speed, low cost, convenient on-line debugging, stable operation and simple operation, and achieves practical requirements. mailto:xusp686@163.com International Journal of Advanced Network, Monitoring and Controls Volume 03, No.03, 2018 71 II. SYSTEM ARCHITECTURE The portable UV spectrometer’s system architecture as shown in Fig.1, and system consists of three modules: data acquisition module, data processing module and man-machine interaction module. The data acquisition module is composed of sampling probe, flue gas sampling pump, ultraviolet light source and micro spectrum analyzer, and the main purpose is to complete the collection of gas, analyze the spectral data before and after the ultraviolet light source and micro-spectrometer, and transform the spectral data into digital signal to transmit to the data processing module. In fact, in the whole system, the micro-spectrometer is a very important sensor component, and the spectrometer is mainly composed of optical components, photoelectric conversion module (CCD), memory. The optical components are mainly for optical fiber incoming optical signal processing, photoelectric conversion module (CCD) after the optical processing of ultraviolet light into electrical signals, memory used to store electrical signals [3]. At the core of the data center is the Raspberry Pi Development Board, then the task is to calculate the specific concentration of gases in the mixed gas by using the relevant algorithm. The man-machine interaction module is composed of a keyboard and an LCD screen, which is designed to visualize the concentration of gas and other related settings on line monitoring. Figure 1. The overall architecture of the portable spectrometer The key component of the portable UV spectrum analyzer control and data processing is the Raspberry Pi Development Board. It is a micro-computer motherboard based on ARM (shown in Fig.2), and the board contains an arm cortex A53 microprocessor, then the main frequency is 1.2GHz. It provides a 10m/100m Ethernet socket and four USB connectors, uses a normal SD card as a hard drive, supports C, C++, python and other development languages. The above parts are integrated in a motherboard, with the basic functions of ordinary computers, compared with the traditional embedded development platform such as ARM7, ARM9, Raspberry Pi in the development efficiency, operation speed, market price and so on have obvious advantages. Figure 2. Raspberry Pi 3B Development Board III. DATA ACQUISITION AND READING PRINCIPLE OF SPECTROMETER A. Principle of data acquisition The data acquisition of portable UV spectrometer is a process of collecting frames. When the spectrometer has collected a frame of data, will collect the spectral data into a queue, waiting for the Raspberry Pi sent instructions to read, and the Raspberry Pi reading spectral data is the process of USB or serial communication. The data read from the spectrometer is derived from the photoelectric conversion (CCD) module. The photoelectric conversion module used in the Maya 2000 pro series spectrometer is a thin photoelectric conversion (CCD) array on the back of the science level. International Journal of Advanced Network, Monitoring and Controls Volume 03, No.03, 2018 72 Figure 3. Data reading sequence diagram of spectrometer The data reading sequence of UV spectrometer is shown in Figure 3. The spectrometer first receives the external triggering signal (high level, 100ns), at the same time, starts triggering the delay signal (low level), resets the CCD signal (low level signal), integration time signal (high level), and the data reads the signal (low level), Idle time signal (low level), after receiving the external trigger signal again, then a data acquisition process is over, and the collected data is stored in memory. B. Principle of data reading Figure 4. Schematic diagram of data reading of spectrometer International Journal of Advanced Network, Monitoring and Controls Volume 03, No.03, 2018 73 One of the most important components of the UV spectrometer is the high-speed single-chip microcomputer. High-speed single-chip computer has a USB port (square port, USB2.0, mini B-type 4-Pin) and serial port two interface (serial port for the 30-PIN Ocean Spectrometer special interface) [4]. The data reading process and principle of UV spectrometer are as follows: First, the optical components of the ultraviolet light processing, ultraviolet light through the slit to the collimating mirror, after collimation, the grating is assembled onto the CCD after the grating is divided, and the photons with different wavelengths will hit the different CCD pixels after the light is divided, and then the CCD element converts the ultraviolet signal into the electrical signal. This completes the spectrometer and the detection function. The signal information obtained from the data will be stored in the memory, then, the raspberry pi is connected with the spectrometer through a USB port, and the raspberry and spectrometer communicate with each other through the USB interface. Finally, the raspberry sent to the spectrometer internal high-speed microcontroller to send instructions, and high-speed SCM will be based on instructions, from the memory to obtain relevant information, and return the information to the raspberry pi. IV. RASPBERRY PIE DEVELOPMENT ENVIRONMENT CONFIGURATION AND SOFTWARE PROGRAMMING A. Python-seabreeze Package Working principle Figure 5. How Python reads the Data development package works The Python-seabreeze package is a two-time development package developed by the Python language on the spectrometer and is the easiest way to access the Maya2000pro-type Ultraviolet spectrum analyzer in Python language. It communicates with the spectrometer using the Seabreeze Library provided by Ocean Optics. Any command sent by the raspberry pie to the ultraviolet spectrometer will use and rely on the Seabreeze library. Python-seabreeze is available as a prebuilt package on windows, Linux, macOS platforms in Python 2.7.x, 3.5.x, 3.6.x, and more. The package supports communication through the Cseabreeze backend with the Maya2000pro Series Ultraviolet spectrometer. In Figure 5, the Libseabreeze is a C + + language library ported from the Seabreeze 2.0 API. The back end is packaged for the Seabreeze Library and uses the Ocean Optics Open Source Seabreeze 2.0 API (using the "SeaBreezeAPI.h") interface. Almost all commands, such as the Format command for communication with the spectrometer, are completed in the C/S library. As shown in Figure 5, the Python language reads the data of the ultraviolet spectrum spectrometer through the Python programming interface provided by Python-seabreeze, and invokes Cseabreeze to read data from the ultraviolet spectrometer through the Libseabreeze library. B. Raspberry PiDevelopment environment configuration (Raspberry Pi Development Board configuration environment must be networked) International Journal of Advanced Network, Monitoring and Controls Volume 03, No.03, 2018 74 1) Install the Python environment on Linux The typical Linux system has a Python environment and is already configured. If not, you will install it by yourself. Python 2.7 is used in this article. 2) Install Python-seabreeze Package Method One: In the Linux Terminal Command Window input command (raspberry pie must be networked, Python-seabreeze installation process is longer, please wait patiently): Conda install-c Poehlmann Python-seabreeze, The raspberry pie will then download the Python-seabreeze and install the configuration automatically. Method Two: Download the Python-seabreeze installation package from the Internet, then copy the installation package to the installation directory, execute the python setup.py command in the command box, and install the configuration automatically. After completion of 3.1.1 and 3.1.2, the installation environment is configured. Because of the use of raspberry pie, so here is the recommended installation Berryconda3-2.0.0-linux-armv7l,berryconda3 itself is a Python development package, and contains a large number of scientific calculation package, easy to install Third-party expansion pack (can use Conda for rapid upgrade), support Cross-platform operation, easy program migration, improve development efficiency, and this will also automatically install the modules and dependencies required for the Cseabreeze backend, saving a lot of time. C. How Python reads data works Figure 6. Data Reading flowchart When the raspberry pie is reading the spectrometer data, it first reads the relevant information of the spectrometer equipment, and if it reads the equipment information of the spectrometer, initializes the spectrometer equipment, sets the integration time and so on; If you do not read the spectrometer device information, you will restart and read the spectrometer device information, cycle, until the device information is read. Second, after the spectrometer equipment initialization completes, the software starts to read the spectral data, and the basic data which reads from the spectrometer is the light wavelength and the photon number. This completes the spectrometer equipment data reads the work. D. Raspberry Pie Data Read part of the code as follows #Introduce related packages and device definitions importseabreeze. spectrometers as sb#Introduction of Python-seabreeze Two development kits devices=sb.list_devices() #Define spectrometer equipment spec=sb. Spectrometer(devices[0]) #Device information printspec.serial_number #Print output spectrometer factory serial number International Journal of Advanced Network, Monitoring and Controls Volume 03, No.03, 2018 75 printspec.model #Print output spectrometer model printspec.pixels #Print output spectrometer number of pixels that can be read at a time #Spectrometer Data acquisition spec.integration_time_micros(10000) #Set the spectrometer integration time x=spec.wavelengths() print x #Print spectrometer wavelength data y=spec.intensities() #Print spectrometer photon Number data #Drawing images using the readout wavelength and photon number importmatplotlib.pyplot as plt plt.plot(x,y,color="green",linewidth=2) plt.xlabel("wavelengths") plt.ylabel("integration") plt.savefig("test2.png",dpi=120) plt.show() The drawing results are shown in the following illustration: Figure 7. Wavelength of dark spectrum and photon number Figure 8. Wavelength of light spectrum and number of photons Figures 7 and 8 are images drawn from the data (photon number and wavelength) that are read from the ultraviolet spectrometer. Fig. 7 is an image of the dark spectral wavelength and the number of photons, and fig. 8 is the wavelength of the light spectrum and the number of photons (the horizontal axis is the wavelength and the longitudinal axes are photon numbers). Dark spectrum, which means that without an external light source, and the spectral line caused by dark current in the CCD of Ultraviolet spectrometer, when the ultraviolet spectrum is actually carried out, the number of photons measured by the detected gas needs to be reduced by the number of dark photons in order to get the actual photon number of the detected gas. It is shown from Fig.7 that the number of dark spectral photons is about 2,800, and the number of photons is related to the ambient temperature. E. Software Simulation The application is programmed with the Python Qt GUI. After writing, then the software is simulated and tested on the raspberry pie to verify that the software function meets the design standard, and the software simulation results are shown in Figure 9. Finally, the raspberry pie and spectrometer were debugged online (Fig.10). International Journal of Advanced Network, Monitoring and Controls Volume 03, No.03, 2018 76 Figure 9. Software Run interface Figure 10. Hardware and software online debugging V. CONCLUSIONS This paper mainly introduces the working principle of micro Ultraviolet spectrometer, data reading and so on, using the developed software after a long time test test shows: the theoretical analysis is correct, and the software has been written to achieve the raspberry pie from the micro-ultraviolet spectrometer read data, and work stable, fast, friendly interface, anti-interference ability, easy to operate and master. The system takes the raspberry pie as the core, realizes the data reading through two times development package, and carries on the software development through the python. The system has the advantages of short development cycle and stable operation, and achieves the practical goal. Next, based on this, the gas iterative algorithm is studied, and the actual concentration of various gases is calculated by using an iterative algorithm for the photon number read by the raspberry pie from the ultraviolet spectrometer. VI. ACKNOWLEDGMENT The authors wish to thank the cooperators. This research is partially funded by the Project funds in shanxi province department of education (15JF019) and the Project funds in shanxi province department of science industrial projects(2015GY067). REFERENCES [1] Xu Shuping, Lichao. Portable smoke analyzer based on arm [J]. Computer measurement and control. 2011.19 (7): 1788-1790 [2] Lei Tianxue. Status of portable flue gas analyzer [J]. Environmental monitoring management and Technology, 1998, (4): 19. [3] Shi Baosong, Sun Shouhong, Zhang Wei. Application of CCD in Portable Spectral analyzer [J]. Electronic measurement Technology, 2010 (11): 84-86 [4] Juwu ,WuYihui. Micro-miniaturization of spectrometer [J].Journal of Instrumentation, 2003. 22 (4): 131-133 [5] Yu Zhiqiang, Wenzhi Yu, XieYingke, Zhou Suyi. The control system of multi-parameter water quality tester based on raspberry pie [J]. Instrumentation technology and Sensors, 2015 (06): 20-23. [6] Han Xiao, Wenzhi Yu, XieYingke, Wei Kanglin, Zhou Xiaofeng. Software design of control and signal processing system for multi-parameter water quality tester [J]. Instrumentation technology and Sensors, 2014 (08): 20-22 [7] Lichao. Design of a portable Smoke analyzer controller based on ARM [D]. Xian: Xi ' an University of Technology, 2012 [8] Zhang Yi. Design of portable multifunctional flue gas analyzer [D]. Xian: Xi ' an University of Technology, 2012.