269 views|5 replies

62

Posts

0

Resources
The OP
 

[STM32H7R/S] Review ⑦ Make a Data Logger for NANO EDGE AI STUDIO to collect data [Copy link]

This post was last edited by Hamster who doesn't like carrots on 2024-11-6 21:09

When we use nano edge ai software to train models, we need to provide sample data for training. In nano edge ai, there are two ways to upload sample data: CSV file prepared in advance and real-time acquisition through serial port. These two solutions can be selected according to your actual situation.

CSV: Suitable for scenarios where sample data is already available or it is inconvenient to collect data in real time. Then you need to fill in the data according to the specified file format and then upload it.

Serial port: The advantage of real-time acquisition through the serial port is that it can be collected on site, but it requires the microcontroller to be able to transmit the formatted data in real time through the serial port.

For the serial port method, we can choose to use the ready-made datalogger provided by ST, or we can choose to make our own

1. DataLogger provided by ST

There is a dataLogeer button in the upper left corner of the nano edge ai interface

Click to see what development boards ST provides for you

The number is still quite considerable, with nearly 20 species

We can select any development board and choose the sensor and configuration parameters to collect data.

When generated you will get a compressed package

This bin can be used directly after burning. Because I don't have the corresponding development board, I can't give you a trial

If you want to get the source code, ST also provides it. You can get the source code in the following place

2. Make your own dataLogger

As mentioned above, I don’t have a corresponding development board, and this time we are evaluating the H7R/S development board, so I will use the H7R/S development board to make a dataLogger.

Before writing code, we need to understand what function dataLogger implements, or what format of data it needs to send. The software data description interface is as follows

In the interface, ST has actually simply described the data content he needs, which is very vivid. We need to collect many rounds of data, corresponding to the lines in the interface. Then in each round of data collection, data needs to be sampled at a certain frequency, and each round of sampling can collect up to 256 times.

For example, I am collecting accelerometer data here, and all three-axis data are collected, collecting M rounds, sampling N+1 times each round, then the final result is

line1 (first round of sampling): ACC_X_0 ACC_Y_0 ACC_Z_0 ACC_X_1 ACC_Y_1 ACC_Z_1 ...... ACC_X_N ACC_Y_N ACC_Z_N

. . . . . .

lineM (Mth round of sampling): . . . . . .

If you have other data, assuming that there is only one data per sampling, assuming that it is the acceleration of one axis, then each round of data is as follows

lineX: ACC_X_0 ACC_X_1... ACC_X_N

This is what is finally presented in the software. So what is the format of the data uploaded on our development board? What protocol is there? And how to distinguish which characters are this data and which characters are that data? How to distinguish each round of data? This part is not shown in detail on this page.

The following are the results of my exploration. There is no formal protocol for data transmission, only some simple data formats, and printing is sent in the form of text: [data][separator][data][separator]. . . . . [data][/r/n][data][separator]…

The number of data for each sampling is set when the nano dege ai project is configured, and the software knows it. Then each data is distinguished by a separator. There are many choices for separators, such as commas, spaces, etc. The details are explained later. Each round of data is distinguished by line feeds and carriage returns (/r/n are required, otherwise the recognition will be abnormal)

Now that I have sorted out my thoughts, I will start to modify the code. My code follows the project of transplanting the X-NUCLEO-IKS4A1 MEMS sensor from the last [STM32H7R/S] evaluation.

First we need to define some variables

#define ACC_SAMPLE_MAX 64
#define AXIS  3
static int acc_sample_buffer[AXIS * ACC_SAMPLE_MAX] = {0};

We will store the sampled data in this buffer and then print it out uniformly

Next, modify while1. Since we only use one sensor on the development board, the previous for loop can be discarded and directly changed to the following

  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
#if 1
    Accelero_Sensor_Handler(0);
    HAL_Delay(100);
#endif

  }
  /* USER CODE END 3 */

Directly call the ACC sensor processing function, with the input parameter 0, because there is only one sensor, and the first sensor's serial number in the array is 0. The delay function is to leave enough time for printing (I don't know why, after I switched back to this branch, the printf that was originally called suddenly didn't work, which was very strange. I could only use the HAL_UART_Transmit function, but it needs a delay, otherwise the data cannot be printed out)

Then we need to modify the Accelero_Sensor_Handler function. The original demo will print out a lot of messy data, but now it is not necessary. We need to complete the data collection in the for loop, and then print the data in the format mentioned before. The modified function is as follows

static void Accelero_Sensor_Handler(uint32_t Instance)
{

  IKS4A1_MOTION_SENSOR_Axes_t acceleration;
  uint16_t i = 0;

  for (i = 0; i < ACC_SAMPLE_MAX;)
  {
    if (0 == IKS4A1_MOTION_SENSOR_GetAxes(Instance, MOTION_ACCELERO, &acceleration))
    {
      acc_sample_buffer[AXIS * i] = (int)acceleration.x;
      acc_sample_buffer[(AXIS * i) + 1] = (int)acceleration.y;
      acc_sample_buffer[(AXIS * i) + 2] = (int)acceleration.z;

      i++;
    }
  }

  unsigned char data[50] = {0};
  uint8_t len = 0;
  for(i = 0; i < ACC_SAMPLE_MAX - 1; i++)
  {
    sprintf(data, "%d,%d,%d,", acc_sample_buffer[i], acc_sample_buffer[i+1], acc_sample_buffer[i+2]);
    len = strlen(data);
    HAL_UART_Transmit(&huart4, data, len, 0xFFFF);
  }
  sprintf(data, "%d,%d,%d", acc_sample_buffer[i], acc_sample_buffer[i+1], acc_sample_buffer[i+2]);
  len = strlen(data);
  HAL_UART_Transmit(&huart4, data, len, 0xFFFF);



  unsigned char data2[] = {"\r\n"};
  len = strlen(data2);
  HAL_UART_Transmit(&huart4, data2, len, 0xFFFF);

}

Then, in order to increase the serial port printing rate, I also changed the baud rate from the default 115200 to 921600 (I changed the code directly, and no longer modified it in cubemx. First, the code of this branch will not regenerate the project in the future, and regenerating it requires changing ld, which is too troublesome)

This is basically it. The code is a bit messy and it took too long to debug. Please forgive me, but the basic functions are OK.

After running, the SSCOM log is as follows:

3. Test function

Next, we will test the function in nano edge ai. The steps and instructions for creating a project in nano edge ai will be described in subsequent articles. Today, we will jump directly to the data collection step.

First you need to select upload data and use the serial port to upload data

When we select the serial port mode, the following interface will pop up

You need to select the serial port and baud rate of the development board

Then we can configure the maximum number of rounds of sampling data. If you do not select it, it will continue to collect data until you press stop. Otherwise, it will automatically stop when the maximum value is reached.

Finally, click start to start sampling. We can see the number of sampling rounds and the data obtained from each sampling in real time.

After the sampling is completed, click continue to parse the data, and then you can get the results of the data analysis, as shown in the following interface

On the left side of this interface, we can choose which delimiter to use. The first one is comma, which is also what I use. There is no need to change it. On the right side is the result of the analysis.

line_index is the number of sampling rounds.

nb_columns is the number of data, for example, the 3-axis data written in my code * sampling 64 times = 192 data

If the data is normal, it will be white. If the analysis is obviously abnormal, it will be red (if only one or two data are wrong, it may be a serial transmission error. If there are many, I suggest you take a good look at the original data to see if it meets the requirements. I used /n between each round at the beginning, and it was abnormal. The first 5 data were all marked red, and the rest were white, but the white data was obviously wrong).

We can select delete to delete abnormal data. We also need to look at the white data, because there may be some sampled data that is obviously abnormal, which requires manual filtering.

After checking the data, you can click import to load the data.

We will discuss how to further use this data in subsequent articles. Today, the production and use of this datalogger is successfully completed.

This post is from stm32/stm8

Latest reply

Here I modified the source code of datalogger. Because it involves multiple sensors, I deleted all other parts and only left the single-axis data of the accelerometer. I guess there was something wrong with the data format when I modified it. The sampling window only shows the first few segments of data, and the subsequent data is invisible. I will go back and check the specific sampling speed at that time.   Details Published on 2024-11-7 14:29
 

126

Posts

1

Resources
2
 

Excuse me, does this use the three-axis data? I used one-axis acceleration but the software collected incorrect data

This post is from stm32/stm8

Comments

My device is 3-axis, and in the first step of nano edge ai, I also selected the accelerometer, 3-axis. Can you check if you configured it with 1 axis instead of 1 axis in the first step? Can you also post a screenshot of the data received by SSCOM and the incorrect data displayed by nano edge ai? Let's communicate  Details Published on 2024-11-7 09:54
 
Personal signature

没用比没有强

 

62

Posts

0

Resources
3
 
Electronic rotten man published on 2024-11-7 09:22 Excuse me, does this use the data of three axes? I used one axis acceleration but the software collected data incorrectly

Mine is a three-axis one, and in the first step of nano edge ai I also chose an accelerometer with three axes.

Did you check if you configured the 1st axis incorrectly in the first step? Can you also post a screenshot of the data received by SSCOM and the incorrect data displayed by nano edge ai? Let's communicate

This post is from stm32/stm8
 
 

126

Posts

1

Resources
4
 

The first step is to configure one axis. I made a motor monitor and used it as a vibration sensor, so I don’t need too many.

Screenshots at the time:

It feels like the data is not sent and received normally. Only a little bit is received and then thrown into data processing.

This post is from stm32/stm8

Comments

There must be something wrong with this analysis result. He even put an exclamation mark here. First, you need to determine how many rounds of sampling you have in total, and how many times are you sampling in each round? He analyzed it here and found that there are 138 rounds of sampling, 3 times of sampling in each round, and 3 times of sampling in each week of each round. This means that there should be no problem with this configuration of one axis.  Details Published on 2024-11-7 14:04
 
Personal signature

没用比没有强

 
 

62

Posts

0

Resources
5
 
Electronic rotten man published on 2024-11-7 13:06 The first step is to configure one axis. I made a motor monitoring, which is used as a vibration sensor, so I don’t need too many screenshots at that time: It feels like data collection...

There must be something wrong with this analysis result, he even put an exclamation mark here.

First of all, you need to determine how many rounds of sampling you have done in total, and how many times you sampled in each round?

He analyzed that there are 138 rounds of sampling, 3 samplings per round, and 3 samplings per week per round. This shows that there should be no problem with this configuration of one axis.

I think 3 samplings per round is too few (it depends on the code whether you have written only 3 samplings per round). Another possibility is that there is a problem with the data format, which leads to incorrect parsing.

This post is from stm32/stm8

Comments

Here I used the source code of datalogger to modify it. Because it involves multiple sensors, I deleted all other parts; only one axis of the accelerometer data was left. I guess there was a problem with the data format when I modified it. The sampled window only has the first few segments of data, and the rest of the data is not available.  Details Published on 2024-11-7 14:29
 
 
 

126

Posts

1

Resources
6
 
Hamster who doesn't like carrots posted on 2024-11-7 14:04 There must be something wrong with this analysis result. He even put an exclamation mark here. First of all, you have to make sure how many rounds of sampling you have in total, and how many times in each round? ...

Here I modified the source code of datalogger. Because it involves multiple sensors, I deleted all other parts and only left the single-axis data of the accelerometer.

I guess there was something wrong with the data format when I modified it. The sampling window only shows the first few segments of data, and the subsequent data is invisible. I will go back and check the specific sampling speed at that time.

This post is from stm32/stm8
 
Personal signature

没用比没有强

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list