MakeRadar School - Sense2GoL Programming Tutorial
This Programming Tutorial will walk through the setup and basic programming of the Sense2GoL Development Kit:
- Set up the environment by installing the necessary software and preparing the IDE.
- Start with a simple program to make an LED blink on the Sense2GoL.
- Read raw data from the Sense2GoL.
- Sample raw data in time frames.
- Implement first applications:
- Door Opener
1. Set up the enviroment
There are several ways to get your development environment set up, depending on your favorite IDE. We’ve provided you with instructions for the most common IDEs.
There are only two steps to get you ready to code:
- Install Segger J-Link
- Prepare your IDE
1.1 Install Segger J-Link
In order to use and program the Infineon XMC microcontrollers on the Sense2GoL DevKit, SEGGER J-Link must be installed on your PC. Please follow this link and install the 'J-Link Software and Documentation Pack' for your operating system.
1.2 Prepare your IDE
In order to program your Sense2GoL DevKit we suggest on out of the two IDEs:
- Arduino IDE
- PlatformIO (recommended)
For more complex programming with the creation and inclusion of own libraries this IDE is preferable because of its structure.
For the basics of Sense2GoL programming the Arduino IDE is absolutely sufficient.
1.2.1 Arduino IDE
If not done yet, download and install the ArduinoIDE from here.
After that, you have to add the Infineon microcontroller boards to the ArduinoIDE.
This is done by opening the ArduinoIDE and go to File > Preferences.
In the opened 'Preferences' window paste the follwing URL into the 'Additional Boards Manager URLs' input field.
To install the boards, please navigate to 'Tools > Board > Boards Manager...' and search for XMC. You will find options to install the board files for the microcontrollers. Click 'Install' to add the boards to your Arduino IDE.
Finally, after successful installation the 'XMC1300 Sense2GoL' has to be selected from the boards list in 'Tools > Board'.
1.2.2 PlatformIO (recommended)
Download and install platformIO from here.
Open platformIO, create a new project and choose 'XMC1300 Sense2GoL (Infineon)' board in the project wizard.
The generated 'platform.ini' file should look like this:
Now you can start coding, building, uploading and monitoring right away. Make yourself familiar with it! (Help can be found here.)
2.2 Let the LED blink
Next, we have to turn LED1 on and off again, repeatedly.
We can do that in the loop() method:
turns the LED on,
2.3 Watch it blink
Upload your code to the Sense2GoL and watch your LED blink.
Congrats! You just managed to talk to your board.
3. Read raw data
While a blinking LED is cool, it’s not at all useful. Let’s continue and read some raw data from the Sense2GoL to get to the exciting things.
Three steps are necessary for this:
- Set-up the board
- Read the data
- Send the data to the PC
3.1 Set-up the board
3.1.1 Opening the serial port
First, we need to initialize a serial port connection, that allows us to communicate between the XMC and the PC.
This is done by:
opens a serial connection and sets the baud-rate for transmission via that connection. This baud-rate must match on the board side and on the PC side. In our example the Sense2GoL baud-rate is .
3.1.2 Turning on the Radar Chip
Second, in order to use the on-board radar chip BGT24LTR11, we have to power it up first via the BGT_ON - see here) .
Since the controlled switch for that is low-active, we need to turn the pin off to enpower the BGT.
This is done by:
NOTE: Operation with external board
The Sense2GoL can also be operated with an external board for data acquisition and signal processing.
For more background information about the operation with an external board see Sense2GoL Device Page.
Please note, if you use the Sense2GoL with an external board, the steps mentioned above are slightly different.
After you have uploaded the code above to the on-board XMC in order to power up the BGT, you have to connect the (5v power) and (ground) to the respective pins of your board.
Now connect the analog pins and to some analog inputs of your own board and you are ready to go.
3.2 Read data
Next, we want to read the raw data in the here).method. The raw data of the radar chip can be sensed as an amplified analog signal on the and the pins (see
What we have to do now is simply read those pins and send their values via the serial port connection to the PC, so it appears on the serial console on our computer.
This looks as follows:
reads the value of raw data from the specified analog pin. and send the read raw data to the serial connection.
The whole code looks like this:
3.3 Receiving data
If you compiled and uploaded the code to the Sense2GoL board, it will read the raw data and send it to the serial connection. On your computer, you can see it arriving by opening a serial monitor (such as that from the ArduinoIDE or PlatfromIO).
The arriving data will look like this:
You should see the values changing when you’re moving the board or some objects in front of the antenna.
Congrats! You just managed to read the radar raw data from your radar sensor.
4. Time frame sampling
We now step deeper into the word of C/C++ programming!
If you are not familiar with pointers, functions or concepts of the Arduino Language, take a closer look in the Arduino Language Reference!
For further analysis, i.e. implementation of applications, it is necessary to consider the sampled IQ-data in a cirtain time frame. Therefore, multiple data points are sampled with a fixed samling rate (also called sampling frequency) and stored into buffers.
The buffered IQ-data can then be analyzed.
4.1 Creating IQ-data buffers
In order to store the IQ-data values from the two analog input pins, two integer arrays have to be declared. In this case we call them
To easily change the number of sampled IQ(t)-data points we define a macro that defines the buffer size and also determines the number of measured data points.
4.2 Sample multiple data points
Now that we have the two buffers for I- and Q-data each, these signals IQ-data can be acquired.
To do this, the two input signals are sampled with a fixed .
Therefore, the two analog input pins are read and it is waited for microseconds and read again. This is repeated until the buffers are full.
Thus, we declare a function which accepts the pointers of the two buffers and realizes the function just described.
This results in the following function:
Now that we have two buffers filled with data we can specify some support functions for these buffers that are usefull in the further processing steps.
First, we define a function, that returns the mean value of a buffer content.
Second, for debug reasons, we realize a printing function that displays the content of a buffer.
4.3 Mean value calculation
A very useful funtion is the calculation of the mean value of a filled buffer. The mean value can be used to set up a sensivity threshold or for a pre-processing step for the fourier transform.
Therefore, we declare a function that takes the pointer and length of the buffer we want to analyze and returns the corresponding mean value.
4.4 Print buffer content
For debug reasons, it is very useful to have a function that displays the entire buffer content. By printing the buffer in .csv (comma separated value)-file format, the transmitted values can be easily visualzied in data evaluation programs (Python scripts, Matlab scripts, Excel). So we implement a function that takes the pointer and length to a buffer and prints it to the serial monitor with each value separated by a simicolon.
4.5 Testing time frame sampling
Now that all functions and buffers have been implemented, it is time to test them. To do this, we read 128 samples in our
You can find the complete scetch in our Listing Section: L1. Testing time frame sampling
5. Implement: Door opener
The door opener is a classic application of radar sensors. The goal is to detect departing or approaching people or objects to automatically open or close a door.
This can be done in multiple ways. The easiest one is simply analyzing the IQ(t)-signals over time.
Thus, we only have to analyze the simple raw data time signals in our signal processing algorithm.
5.1 Signal Processing
As explained in our #MakeRadar School Radar Theory lesson the direction of motion can be detected by determining the leading signal in phase. In case of a direction of motion towards the radar the I(t)-signal will lead the Q(t)-signal, but away from the radar the Q(t)-signal leads the I(t)-signal.
It has now to be determined which signal is the leading one. As can be seen from Figure 5.1, the Q(t)-signal is clearly leading the I(t)-signal in phase when departing from the radar sensor and vice versa.
Thus, the determination has to be implemented within our signal processing code.
Leading/trailing signal indicator
One way to do so, is to consider the edges of the Q(t)-signal (Figure 5.1 (blue)) at the turning points of the I(t)-signal (Figure 5.1 (red)). Depending on the direction of the edges the leading, respectively the trailing signal is indicated.
|Q-singal edge \ I-signal turning point||Minimum||Maximum|
Depending of the duration of the IQ(t)-signal frame, the edges at multiple turning points can be observed. By incrementing/decrementing an indicator for the different turning points, the average direction over the time frame can be considered.
In order to ignore small movements in front of the radar we can only consider the turning points outside a sensivity range around the mean value of the IQ(t)-signal (Figure 5.1 (black)). Thus, only higher magnitudes of the I(t)-signals are considered.
Now that we have discussed the the idea behind the signal processing we can start to implement the door opener.
With the preliminarily work for raw data acquisition we have only to implement a further function, that determines the direction of motion in the bufferd IQ(t)-data.
In a further step we have to implement our door functiononality in our method.
Let's start with the detection of direction!
The return value of our function should be the direction of motion, whereas '1' indicates an approaching motion and '-1' a departing one. No motion is indicated by '0'. Basically for the determination, the two buffers of the IQ(t)-signals has to be analyzed and thus handeld to the function.
Togther with the steps already explained in the Signal Processing Section following function is obtained:
Let's apply it to the door!
Since we only implement a 'virtual' door opener, we do only print the door reaction in our serial monitor.
An approaching person or object means the door should open and vice versa. So we implement this in our method.
You can find the complete scetch in our Listing Section: L2. Implementation: Door opener