I2C Tutorial for Renesas S5D9 board: Add an External SHT31 sensor (Part2)

ic2
s5d9

#1

Project Goals

  • Take what is developed from Part 1
  • Add an external SHT31 sensor (new hardware)
  • Change the code to read the current temperature (F) from an external SHT31 sensor instead of an onboard AMS EN210 sensor (software change)
  • Add the code to interface with SHT31 (new software code)

Screen Shots

Board

Renesas S5D9 IoT Fast Prototyping Kit

Software

  1. Renesas E2 Studio Tool version 5.4.0.023
  2. Renesas SSP version 1.30
  3. S5D9 IOT ENABLER pack file

Hardware

(Only new device needed for Part 2)

  1. Temperature and Humidity I2C SHT31 Sensor (Seeed Studio)

(Hardware from Part 1)

  1. I2c IIC Serial 128x64 Oled LCD Module (Amazon Link)
  2. 4 Pin Female Jumper To Grove 4 Pin Conversion Cable (Amazon Link)
  3. The Jlink debugger board (included in S3A7 kit)

Prerequisites

  1. I2C Tutorial for Renesas S5D9 board: Show The Temperature Reading on an OLED Display (Part 1)

Diagram 1: SHT31 Temperature and Humidity Sensor with I2C Interface

Demo Video:

Hardware Setup:

  1. Connect the SHT31 sensor to the same J4 I2C grove header of S5D9 board as the OLED display module.

Software Setup:

  1. No change to configuration. All the configurations done in part 1 are good for part 2.

C code Files [UPDATED]

  1. hal_entry.c/h (Main Program Loop) [Small changes]
  2. i2c.c/h (i2c SSP API calls)
  3. sht31.c/h (subroutines for SHT31 operations) [new]
  4. en210.c/h (subroutines for AMS EN210 operations)
  5. ssd1306_oled.c/h (subroutines for OLED module operations)

Note: ssd1306_oled.c/h only contains the code written by Adafruit to access the driver chip ssd1306 on the display module. The rest of the codes are developed independently.

A number of advantages with this ssd1306_oled.c over Adafruit ssd1306 are:

  • It does not require C++ compiler. It will work with your Synergy C project.

  • It is simpler. It has all the essential subroutines to draw lines and show letters/numbers/symbols on the display. So, Adafruit_gfx.library (Graphic library) is no longer required.

  • Supports A-Z,0-9,=,.

  • It is easy to add your 8x8 pixels font symbols.

#Code Download

Note: You can download all the codes from here (Github)

version 1. (Github_ver1) - 1st release (only T,E,M,P, =, 0-9, and space are supported)

version 2. (Github_ver2) - 2nd release with improvements. 1. A-Z, =, 0-9, period and space are supported. 2. sprintf is supported to simplify the method of writing a message to the display.

(version 1)

Display "TEMP="
for (uint8_t i=0; i<5; i++){
     writefontchar(8*i+(HISTXPOS-1), 0, i+1);
}

(version 2) - A much easier method is used

sprintf(msg,"TEMPERATURE=%d.",(uint8_t)g_temperatureF);
writedisplaybuffer(0, 0, msg, strlen(msg));

#Note: Included is S5D9_I2C_INT_ENV210_OLED_SHT31.7z file (the 7zip archive file for the e2 studio project file for this project) Unzip and import it into your e2 studio. It is ready to build and run if you cannot make your project to work.

Step by Step Procedure:

Step 1: Open your project (Part 1)

Step 2: Open hal_entry.c file. Add the following lines (Diagram 2a and 2b).

Diagram 2a: Add sht31.h include line

Diagram 2b: The additional code (Line 97-107) is added to hal_entry.c file

Step 3: Add sht31.h and sht31.c files.

Step 4: Build project.

Step 5: Run debug to upload the new code.

Step 6: If you put your hand over the SHT31 sensor, the temperature reading should increase.

Congratulation! You have completed the tutorial. Once the I2C configuration is done, you can re-use it for as many new I2C devices you wish to add. In addition, the I2C communication coding in SHT31.c is very similar to that in SSD1306.c. It makes fast prototyping possible.

Challenges!

  1. Add your favorite I2C grove sensor and display the sensor value on the OLED display.
  2. A plot of values over a period of time rather than continuous reading. Take one measurement every hour and plot a new graph at the end of the day.