教程:用覆盆子Pi安装DAQ测量加速度计

How to Measure an Accelerometer Using a Raspberry Pi-Mounted DAQ

IEPE(集成电子压电)传感器用于测量加速度,压力或力。这些类型的压电传感器包含内置独立转换电子器件,用于将信号从压电传感器转换为低阻抗电压信号。

该项目将展示如何使用MCC 172 DAQ HAT– coupled with a Raspberry Pi – to measure the signals received from this type of sensor. The sensor used is for vibration and can be mounted in different places to monitor the condition of different pieces of equipment.

需要硬件和软件

该项目使用MCC 172 IEPE测量DAQ HAT和Raspberry PI来读取输出IEPE传感器。该项目的传感器使用是805加速度计500G IEPE T05-3(data sheet)。面包板和电线用于连接到帽通道,如下所示。

On the software side the following are needed:

设置必要的软件

To use the MCC 172 DAQ HAT with the Raspberry Pi, the first thing to do is install the libraries provided by the manufacturer.
以下是步骤:

  1. 如果使用图形界面并更新包列表,请打开终端窗口:
    1. sudo apt更新
  2. Optional: Update your installed packages and reboot:
    1. sudo apt全升级
    2. sudo重启
  3. 如果未安装安装git:
    1. sudo apt安装git
  4. Download the package offered by the manufacturer to your user folder with git:
    1. cd ~
    2. git clone https://github.com/mccdaq/daqhats.git.
  5. 安装库。安装程序将询问您是否要安装Python 2和Python 3支持。
    1. CD〜/ daqhats
    2. sudo ./install.sh

要执行固件更新或阅读有关MCC 172的更多信息,请访问MCC DAQ HAT库文档

Setting Up the Hardware

For this project, we will use an IEPE sensor. The 805-0500 from TE connectivity is a 3-pin IEPE low-cost accelerometer well suited for embedded applications that use a TO-5 header. This model of sensor has a dynamic range of 500g and wide bandwidth up to 12kHz. This sensor can be mounted using adhesive to the structure to be monitored. In this project, the sensor will be mounted using the 3 pins on a breadboard, connecting the pins to the channels from the MCC 172 for ease of use. In the manufacture datasheet, it is specifying the pin function. Pin 1 is output of the sensor, for reference the sensor packaging has a notch (as shown in the image below), the ground pin is the opposite one.

Figure 1: Sensor connection ports
Figure 2: Sensors +OUT Pin

The next step is to connect the output and ground to the channel 0 input from the MCC 172. There are several types of connectors for IEPE sensors on the market, but for this sensor we will use the screw connector to securely connect the wires leading to the sensor. The code for this project is written in such a way that channel 2 is also used, if necessary, for a second sensor.

Figure 3: Connecting to the MCC 172

Program Flow

After mounting the components and installation of libraries, the two files attached below must be saved in the same folder. “daqhats_utils.py” is taken from the examples folder, it is in the “daqhats” folder which is installed after performing the steps for installing the libraries using git. “main.py” is the main file for this project.

  • 下载main.py.HERE
  • Download daqhats_utils.pyHERE(确保它与main.py的相同文件夹)

图书馆进口

To perform the measurement, we need some functions offered in the libraries in the git repository and daqhats_utils. We import the entire mcc118 class and some help functions“OptionFlags”用于设置用于扫描帽子上的通道提供的值的模式,并识别我们使用“hatids”和“haterror”函数的ID和错误。

阅读和显示数据

total_samples_read = 0.

read_request_size = read_all_available.

dt_string = date_time.strftime(“%d /%b /%y /%h:%m:%s”)#转换值存储在date_tame到字符串中

打印('\ n \ n',dt_string,file =打开('log.txt','a'))
print(‘\nSamples Read Scan Count Channel 0 Channel 1’, file=open(‘log.txt’, ‘a’))

超时= 5.0

while True:

read_result = hat.a_in_scan_read(read_request_size,超时)

# Check for an overrun error
如果read_result.hardware_overrun:
print(‘\n\nHardware overrun\n’)
休息
elif read_result.buffer_overrun:
打印('\ n \ nbuffer overrun \ n')
休息

samples_read_per_channel = int(len(read_result.data)/ num_channels)
total_samples_read + = samples_read_per_channel

# Display the last sample for each channel,in a maximum number of 12 digits.
打印('\ r {:12}'。格式(samples_read_per_channel),
‘ {:12} ‘.format(total_samples_read), end=”)
打印('\ r {:12}'。格式(samples_read_per_channel),
‘ {:12} ‘.format(total_samples_read), end=”, file=open(‘log.txt’, ‘a’))
#\ r用于写入现有行

#显示每个通道的RMS电压。

if samples_read_per_channel > 0:
对于IN范围(num_channels):
value = calc_rms(read_result.data,i,num_channels,
samples_read_per_channel)
#在逗号后显示10位数字和5位数字的值
打印('{:10.5f}'。格式(值),'vrms',end =“)
#在日志文件上保存在逗号后的值10位数和5位数
打印('{:10.5f}'。格式(value),'vrms',end =“,file =打开('log.txt',‘a’))

stdout.flush()

sleep(0.1)

print(‘\n’)

The readings are executed in a loop that continues until the user stops the scan or an overrun error is detected. All the available samples are read (up to the size of the read_buffer). Since the read_request_size is set to -1 (READ_ALL_AVAILABLE), the function “hat.a_in_scan_read” returns immediately what samples are available at the moment and the timeout parameter is ignored. The function “hat.a_in_scan_read” returns multiple elements: running, hardware overrun, buffer overrun, triggered, and timeout with all is a bool type and data that is a list of float. The data return is the one we will use next to display the information read from the buffer.

samples_read_per_channel = int(len(read_result.data)/ num_channels)

total_samples_read + = samples_read_per_channel

“samples_read_per_channel” is used to show the number in the data list acquired it was made and displayed. “total_samples_read” stores the total number of samples. These numbers are displayed in 12-digit format.

If there are samples in the buffer, then the program will start displaying. For each channel its result is saved to a certain value in the list, the position for each value is a multiple of the number of channels used. To display we use an index that saves for each reading the position of each sample on each channel.

f samples_read_per_channel> 0:

对于IN范围(num_channels):

value = calc_rms(read_result.data,i,num_channels,

samples_read_per_channel)

#在逗号后显示10位数字和5位数字的值

打印('{:10.5f}'。格式(值),'vrms',end =“)

#在日志文件上保存在逗号后的值10位数和5位数

打印('{:10.5f}'。格式(value),'vrms',end =“,file =打开('log.txt',

For each value displayed in the terminal, a copy of each displayed value is saved in the log file. For this reason, after each data value is displayed, we have another print line that ends with “file=open(‘log.txt’, ‘a’))” is the function for working in Python with files, this function takes two parameters:文件名and模式。在此模式下“a”一个文件是打开的,以便附加,如果文件不存在,则文件文件名will be created.

值显示格式

def calc_rms(data, channel, num_channels, num_samples_per_channel):“”” Calculate RMS value from a block of samples. “””

价值= 0.0

索引=通道

for _i in range(num_samples_per_channel):

value += (data[index]* data[index]) / num_samples_per_channel

index += num_channels

return sqrt(value)

In the terminal, the buffer value is displayed as Vrms (root-mean-square voltage). The RMS value is the square root of the average value of the square function of the instantaneous values. The output of an IEPE sensor is a sine an offset between 8 and 12 V. A way to compare these values read by the MCC 172 is to calculate the RMS value. This value is easier to interpret than reading the value sent directly by the DAQ. The calc_rms function is called before the values are displayed in the terminal.

对于IN范围(num_channels):

value = calc_rms(read_result.data,i,num_channels,

samples_read_per_channel)

启动脚本

要启动Python脚本,请在文件夹中打开一个终端,其中包含以下命令的两个文件。

  1. python main.py

之后,在终端中,将出现MCC 172所在的地址。回答问题,以使IEPE与Y为YES和N为NO。之后,终端应该显示:如何设置帽子(连续扫描),IEPE电源状态,使用中的通道,最后将其设置为工作的扫描速率。按ENTER键后,程序将开始扫描。使用第一次运行,程序将创建日志文件。第一行将包含扫描启动和保存时的日期和时间。然后在日志文件中,它保存在不同的行上,终端中显示的数据。当再次执行程序时,数据将在先前写的最后一行开始的同一日志文件中保存在相同的日志文件中。

图4:终端显示
图5:日志文件

的解释显示is as follows:

  • Samples Read is the number of samples displayed and resets back to 0 after the buffer fills.
  • Scan Count is the total numbers of the samples read, it does not reset when the buffer is full and continues to count.
  • 通道0和通道1是该频道读取的值。

Conclusion

This project is an example of how the MCC 172 DAQ HAT and can be used with an IEPE-based accelerometer to monitor sudden movements or vibrations. With the help of other IEPE sensors, force and pressure can also be monitored. The code does not need any modification to be able to use another type of IEPE sensor.

0
是第一个投票。

Leave a Reply

您的电子邮件地址不会被公开。