The Avnet RASynBoard already includes two TDK sensors on the core board; the TDK ICM-42671-P (6-axis IMU), and the TDK T5838 (digital MEMS microphone). While these two sensors will support many different ML use cases, adding additional sensors extends the number of use cases that can be addressed.
This document captures the steps to add the Renesas US082-HS3001EVZ temperature and humidity sensor to the Avnet RASynBoard Out of Box application. We're going to use the Renesas Flexible Software Package (FSP) to complete the tasks required to add this sensor to the project. The FSP is a powerful feature that you'll see in action.
This content does not show how to pass the add-on sensor data to the NDP120 for inferencing. Look for follow on content that will cover that topic.
Buy links for the hardware:
In order to use this PMOD I2C sensor with the Avnet OOB application we need to . . .
- Clone the project
- Open the project in the Renesas e^2 Studio IDE
- Connect the sensor to the RASynBoard
- Disable the PMOD UART software initialization calls in the project
- Add a new thread to read the sensor
- Disable the PMOD debug UART hardware signals (we'll re-use these signals for the I2C interface)
- Add the I2C interface
- Add the new sensor drivers
- Write 10 lines to code to initialize and read the sensor
- Run the application and verify that the sensor is working
As you'll see the FSP makes this an easy task!
First we'll clone the Avnet Out-of-Box application. I prefer to clone git repos that way I get my source control all setup from the start. This makes tracking any software changes a breeze.
If you need help getting these steps done, please reference the RASynBoard Getting Started Guide. Once you have built and run the unmodified OOB application come back to this guide.
Since the RASynBoard has a PMOD connector, we can simply plug in the HS300X sensor to the board. Use the graphic below to connect your HS300X sensor to your RASynBoard.
Since we're going to use the PMOD connector to connect the HS300X device we need to disable application code that assumes that interface is setup for UART Debug.
- Open
src/ndp_thread_entry.c
- Comment out the
console_init()
call
- Open
src/fat_load.c
- Change
print_console_type = CONSOLE_USB_CDC
- Select the Stacks tab
- Click the New Thread link
- Select the New Thread in the Threads window
- Select the Properties tab
- Scroll down to the Thread section
- Update the Thread Symbol to
sensor_thread
- Update the Thread Name to
Sensor Thread
- Set the Thread Stack size (bytes) to
2048
The new thread is added to the project, but the (rm_comms_i2c) block is red indicating an issue with the configuration. You can always hover your mouse over the red error text to see what the issue is with a hint on how to resolve the issue.
- Select the Sensor Thread in the Threads list
- In the Sensor Thread Properties tab under Common-->General update the following items . . .
Use Mutexes --> Enabled
Use Recursive Mutexes --> Enabled
The standard OOB application exposes Debug UART signals on the PMOD, but we need to reconfigure these pins to I2C signals. The I2C sensor will use these signals from the PMOD connector.
- In the IDE open the
configuration.xml
file, this opens the FSP Configuration
- Select the Pins tab
- Select Peripherals --> Connectivity:SCI --> SCI4
- Select the pull down control in the Operation Mode --> Value column
- Select Disabled
Your SCI4 configuration should look like this . . .
- Select the Pins tab
- Select Peripherals -> Connectivity:IIC -> IIC1
- Change the Operation Mode to
Enabled
- Select the Stacks tab
- With the Sensor Thread selected
- Click on the Add I2C Communications Peripheral block
- A New option appears
- Select New
- Select I2C Master (r_iic_master)
- Select the g_i2c_master0 I2C Master (r_ii2_master) block
- In the Properties tab change the Channel to
1
to select the I2C interface exposed on the PMOD
We'll use the Renesas Flexible Software Package tool to generate all the driver code to read our new sensor.
- Make sure that the Sensor Thread is selected
- Select Stacks --> New Stack --> Sensor --> HS300X Temperature/Humidity Sensor (rm_hs300x)
Now it's time for the Flexible Software Package (FSP) Magic
- In the upper right corner click on the Generate Project Content link
- If prompted to save the changes click yes or Proceed as appropriate
- The FSP adds the
hs300x
drivers and newSensor Thread
to your project!
Note that the project now has the hs300x drivers included under the ra/fsp/src/rm_hs300x
directory
If you expand the src
directory you'll see a new file sensor_thread_entry.c
has been added to the project, and furthermore calls were added to call our new thread on startup. So far we have not written any code but we already have an execution path enabled to read our sensor. Pretty cool! Note that the sensor_thread_entry.c
file is pretty sparse!
Usually at this point we would need to dig into documentation to learn how to initialize the I2C interface and read the device datasheet to understand how to interact with the I2C device. Well the FSP has done all that work for us!
- Expand the
Developer Assistance
folder - Expand the
Sensor Thread
folder - Add a few blank lines in
sensor_thread_entry.c
below the#include "sensor_thread.h"
line
We can add all the initialization code for our device by dragging code from the Developer Assistance tree directly into our source file!
- Using your mouse, drag the following items into the sensor_thread_entry.c file
After dragging all the identified items to my sensor_thread_entry.c file it was about 270 lines long (your line numbers will be different based on white space)
- Locate the two lines shown below and set the values to
(1)
/* TODO: Enable if you want to open HS300X */
#define G_HS300X_SENSOR0_NON_BLOCKING (1)
/* TODO: Enable if you want to use a callback */
#define G_HS300X_SENSOR0_CALLBACK_ENABLE (1)
So just like that we have all the driver code done!
- Add the standard I/O
#include <stdio.h>
at the top of thesensor_thread_entry.c
file
- Copy and paste the code below overwriting the existing empty
sensor_thread_entry()
function
void sensor_thread_entry(void *pvParameters)
{
FSP_PARAMETER_NOT_USED (pvParameters);
rm_hs300x_data_t ht_data;
float g_temp = 0.0f;
float g_hum = 0.0f;
g_comms_i2c_bus0_quick_setup();
g_comms_i2c_device0_quick_setup();
g_hs300x_sensor0_quick_setup();
/* TODO: add your own code here */
while (1)
{
g_hs300x_sensor0_quick_getting_humidity_and_temperature(&ht_data);
g_temp = (float)ht_data.temperature.integer_part + (float)ht_data.temperature.decimal_part / 100.0f;
g_hum = (float)ht_data.humidity.integer_part + (float)ht_data.humidity.decimal_part / 100.0f;
// Output the sensor readings. Note we do not include support for printing
// floats by default.
printf("Temp: %d.%dC, Hum: %d.%d%%\n", ht_data.temperature.integer_part,
ht_data.temperature.decimal_part,
ht_data.humidity.integer_part,
ht_data.humidity.decimal_part);
vTaskDelay (1000);
}
}
- Build the project by clicking on the Hammer Icon
- Run the project in the debugger by clicking on the green bug icon
If you have issues starting the debugger, refer back to the RASynBoard Getting Started Guide
- Once the debugger is running it will be halted at the call to
SystemInit()
- Press the F8 key to continue
- Next the debugger stops at the first line in
int main(void)
- Press the F8 key to continue
Since we highjacked the Debug UART signals for the I2C signals, we need to redirect the application debug to the USB-C connector on the core board (the smaller of the two RASynBoard boards). We can do this by editing the config.ini file on the microSD card.
- With the debugger still running . . .
- Connect a second USB-C cable to the USB-C connector on the core board
- Open a file explorer window and find the USB drive associated with your RASynBoard
- Open the config.ini file in the root directory
- Change
[Debug Print] Port=2
to select the USB-C connector on the core board for debug output
- Stop debugging the application by clicking on the stop button (red square)
- Restart the application by clicking on the green bug
- Open the serial port associated with the USB-C cable on the core board
- Set the port to 115200, 8,N, 1
You should see debug every second when the sensor data is read
This document included all the details needed to add the Renesas HS300X temperature and humidity sensor to the Avnet RASynBoard Out-of-Box application. You got a brief introduction to the Renesas Flexible Software Package and saw how easy it is to add one of the supported sensors to a RA project.
This project is included on the GitHub page under a branch called AddTempHumiditySensor
To pull this branch . . .
git clone https://github.com/Avnet/RASynBoard-Out-of-Box-Demo.git
git checkout AddTempHumiditySensor
If you have any questions, issues or comments on this content please open a new issue on the GitHub page!