S3A7 with Sensirion Grove sensor

 

This tutorial will show you how to easily attach a Sensirion Grove sensor on the S3A7 Fast Prototyping Kit and visualize the sampled data in Renesas IoT Sandbox environment.

As a starting point, you will take an existing Smart Chef project, and add a new sensor to it. Once configured and attached to the S3A7 board, the Sensirion Grove sensor will sample the temperature and humidity, and then the sampled data will be visualized in Real Time Event Log and Real Time Gauge widgets of Renesas IoT Sandbox.

Note:

This is known to work with this version of software:

  • e2 studio version 5.4.0.018
  • SSP version 1.2.0

Here is what you need to get started:

Prerequisites:

 

Step 1: Download and import the project into e2 studio

From the git repository, download the ‘IoT Fast Prototyping Kit Smart Chef Demo – Application Project’ project (link in “what you need to get started”). You can either clone the repository or download an archive of the sources. Re-name the project folder to “SmartChef”.

In the project root folder, you will find the BSP PACK file for the S3A7 Fast Prototyping board, named “Renesas.S3_IOT_BOARD.1.2.0.pack”. Copy this file to the e2Studio Packs directory (usually located at C:\Renesas\e2_studio\internal\projectgen\arm\Packs).

Next, open e2 studio and import the existing project. Go to File -> Import -> Existing Projects into Workspace, then click ‘Next’

“Select root directory” where you downloaded the project; if you downloaded the project into the current workspace folder, you must uncheck “Copy projects into workspace” (since it is already in the workspace). Click “Finish“.

Note: The project in this tutorial uses SSP version 1.2

Step 2: Add new device & driver to the project in e2studio

In e2 studio, you will add the new device and its driver to the current S3A7 smart chef project. Then, you will need to build the updated project, and reflash your S3A7 board kit with the new image.

Add new I2C device

Open the file “configuration.xml”. Make sure you are in the ‘Synergy Configuration’ perspective.

Click on the ‘Threads’ tab, then select “Sensor Thread” under the Threads section.  Then, in Sensor Thread Stacks add the new I2C device.

Add shared bus

Add r_riic driver

Delete DTC drivers

Configure r_riic driver

Configure the new driver with the following settings:

  • Name: sensirion
  • Channel: 2
  • Slave Address: 0x44

Generate Project Content

 

Register Sensirion i2c device with cloud driver

Switch to C/C++ perspective:

In sensor_thread_entry.c, add (in green color) the following lines to register the new device:

    err = g_sf_i2c_device3.p_api->open(g_sf_i2c_device3.p_ctrl, g_sf_i2c_device3.p_cfg);
    APP_ERR_TRAP(err);
    m1_initialize_i2c(&g_sf_i2c_device3);
    err = g_sf_i2c_device4.p_api->open(g_sf_i2c_device4.p_ctrl, g_sf_i2c_device4.p_cfg);
    APP_ERR_TRAP(err);
    m1_initialize_i2c(&g_sf_i2c_device4);
#endif
#endif

Add SSP_SUPPRESS_ISR_sensirion preprocessor macro

The macro “SSP_SUPPRESS_ISR_sensirion” must be defined in order to compile. See the SSP 1.2 Release Notes for more details.

Rebuild project and reprogram board

Right click on the project, then select ‘Build Project’. This will generate the new image for the S3A7 kit.

 

At this point, make sure your board has power by plugging Micro USB to J1. Now, you need to update the board’s image with the previously generated build.

To flash the board, connect the J-Link debugger to your Windows or Mac computer and connect the debugger to the S3A7 Fast Prototyping board.  Right click on project, then select:

Debug As -> Renesas GDB Hardware Debugging 

If you get asked, select J-Link ARM hardware, then R7FS3A77C device.

 

Step 3: Disconnect AMS sensor module and replace it with Sensirion Grove module

On your S3A7 kit, if still attached, remove the Renesas AMS sensor module. In the same place, attach the Sensirion Grove module. Reset the board.

Note: The following picture shows Sensirion Grove module attached to port J18. The board is powered by micro USB, and there is a JTAG J-Link programmer connected at port J20.

 

Step 4: Activate kit in Renesas IoT Sandbox

Click here to activate the kit and complete the registration process to create a Renesas IoT Sandbox account.  

Note: This kit doesn’t come up with any preloaded workflows; however, it does contain some pre-defined tags that will be used later in this tutorial.

Once activation is completed, you will receive an email with your account credentials needed to provision the kit and access the cloud portal.   If you already have a Renesas IoT Sandbox account, you will not receive an email with your account credentials, you will login with your existing account

This email will include your:

  • Renesas IoT Sandbox web login
  • API Key
  • Device username and password

Now, log in to your Renesas IoT Sandbox. You are ready to create new workflows to detect the sensor data.

 

Step 5: Connect the S3A7 kit to the Cloud

Reset the board and reprovision it (touch the screen within 10 seconds after reset occurred) with the information from activation kit email.  If you forgot how to provision the board, refer to step 3 from the Smart Chef tutorial.

 

Step 6: Sample Temperature & Humidity Data with Sensirion sensor

In this step, we will create a workflow that samples temperature and humidity sensor data on the screen. Make sure the Sensirion Grove sensor is attached to the board. Note, in this step, the data is still encoded and we will decode it in subsequent step.

Create a new workflow and name it “Sensirion Sampling”.

Drag the rawconnected” tag and rawtouched” tag into the workflow.

 

 

Drag a Base Python module into the workflow.

Double click on Base Python.  Increase the number of inputs for the Base Python to two, connect both tags to the module such that “connected” goes to in1 and “touched” goes to in2.

This workflow will trigger when one of these 2 things happen:

  • Connect event is received
  • Touched event is received

Make sure the rawconnected” and “touched” tags have enabled trigger as shown below:

Replace the script with the following code in the python module:

# this import the cloud driver for the sensirion sensor
import cloud_driver_sensirion

# configure sensor repeatability to 'low', other values can be 'medium' or 'high'
repeatability = 'low'

# configure clock stretching to be true
clock_stretching = True

# request temperature and humidity from board
cloud_driver_sensirion.request_sensirion_temperature_and_humidity(3, repeatability, clock_stretching, 'temp_and_humidity', 's3a7')

 

Then click “Save and Activate” to finish setting up the workflow.

 

Step 7: Process Temperature & Humidity Data with Sensirion sensor

In this step, we will take the raw temperature and humidity data that our previous workflow produced and process it to display it on the board.

Create a new workflow and name it “Sensirion Processing”. Drag the rawtemp_and_humidity” tag into the workflow. Drag a Base Python module into the workflow. Drag the output tag “Processed Stream – Single” into the workflow; then connect all modules.

Replace the script with the following code in the python module:

 

import cloud_driver_sensirion

raw = IONode.get_input('in1')['event_data']['value']

# decodes the temperature and humidity
t,h = cloud_driver_sensirion.process_sensirion_temperature_and_humidity(raw)

IONode.set_output('out1', {"temperature": t, "humidity":h})

 

Then click “Save” to finish setting up the workflow.

 

Finally, in output tag “Processed Stream – Single”, set the tag name to “temperature”.

Then click “Save and Activate” to finish setting up the workflow.

 

Your S3A7 kit is will now sample the temperature and humidity via the Sensirion sensor when you touch the S3A7 display.  Go ahead and touch the S3A7 display.

In order to see the temperature and humidity values, you can view the real time events log file or real time gauge.

Congratulations!

You just attached a Sensirion Grove module to your S3A7 IoT prototyping kit.

Now you can detect temperature and humidity from the Sensirion sensor and visualize the data in the Renesas IoT Sandbox environment.

 

WHAT’S NEXT?

Congrats, You have just completed setting up the Smart Chef IoT Kit with a new sensor! The rest is up to your imagination!