MakeRadar School - Sense2GoL Programming Tutorial


This Programming Tutorial will walk through the setup and basic programming of the Sense2GoL Development Kit:

  1. Set up the environment by installing the necessary software and preparing the IDE.
  2. Start with a simple program to make an LED blink on the Sense2GoL.
  3. Read raw data from the Sense2GoL.
  4. Sample raw data in time frames.
  5. 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:

  1. Install Segger J-Link
  2. 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:

 digitalWrite(LED1, HIGH)   turns the LED on,   delay(500)   waits half a second before it proceeds.


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: 

  1. Set-up the board
  2. Read the data
  3. Send the data to the PC


3.1 Set-up the board

In the   setup()  method, we have two things to do, before we can read raw data and send it to the PC.

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:

 Serial.begin(BAUDRATE)  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  38400  .

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  pin (  BGT_ON - see here) .
Since the controlled switch for that is low-active, we need to turn  the  BGT_ON  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  VCCIN  (5v power) and  GND (ground) to the respective pins of your board. 
Now connect the analog pins  IF_I_HG  and  IF_Q_HG   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  loop  method. The raw data of the radar chip can be sensed as an amplified analog signal on the   CH_I  and the   CH_Q  pins (see here).

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:

  analogRead(PIN reads the value of raw data from the specified analog pin.    Serial.print(PIN)  and  Serial.println(PIN)  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   bufferI  for the sampled I(t)-data and   bufferQ  for the Q(t)-data. 
To easily change the number of sampled IQ(t)-data points we define a macro  SAMPLES   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  SAMPLING_RATE  . 
Therefore, the two analog input pins are read and it is waited for   SAMPLING_TIME_US  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  loop()  method and print the buffer content and the corresponding mean values to the serial monitor. This is done every 5  seconds. 
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.

Figure 5.1: Sampled IQ(t)-data over time of a departing object (left) and sampled IQ-data over time of an approaching object (right).

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                  
Rising  Edge Departing Approaching
Falling Edge Approaching Departing

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.

5.1 Implementation

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   OUTPUT  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   loop()  method.
You can find the complete scetch in our Listing Section: L2. Implementation: Door opener



Find here the complete code for the corresponding sections!

L1.  Testing time frame sampling

L2.  Implementation: Door  opener