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

s5d9
oled
temperature

#1

Project Goals

  • Develop the basic C code from scratch for the S5D9 board
  • Read the current temperature (F) from onboard AMS EN210 sensor (I2C interface)
  • Display the current temperature (F) on OLED display (I2C interface)
  • Display the temperature graphically over time on OLED display
  • No RTOS or ThreadX is needed for this tutorial since application response timing is not critical. Having no RTOS makes the code much easier to understand and develop.

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

  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. E2 Studio Installation. For this tutorial, use E2 Studio version 5.4.0.023 and SSP version1.30. (Learn IoT Community Link)
  2. Blinky Example with E2 Studio and Jlink Flash (Learn IoT Community Link)
  3. C language coding skill

Demo Video

Hardware Setup:

  1. Connect the OLED display to the J4 I2C grove header of S5D9 board.

  2. Connect the J-link debugger board to the J2 header of S5D9 board and USB port of your PC. This board is for uploading your code into the board. It is also used for e2 studio to debug your code.

  3. Connect J9 to another USB port of your PC.

Software Setup

  1. E2 Studio Project Setup

    1.1 Synergy C Project

    1.2 SSP 1.30

    1.3 S5D9 IOT ENABLER board

  2. E2 Studio Thread Configuration

    2.1 Set up the configuration for I2C master drivers for two I2C bus (internal I2C bus for the onboard AMS EN210 temperature sensor and external I2C bus for the OLED display module.

    Internal I2C bus (P5_12/P5_11) is connected to EN210 sensor chip.

External I2C bus (P1_1/P1_0) is connected to J4 which we attach the OLED display module.

2.2 Set up the configuration for 32 bit timer for generating delay.

Note: No interrupt is enabled or RTOC is used.

C code Files [UPDATED]

  1. hal_entry.c/h (Main Program Loop)
  2. i2c.c/h (i2c SSP API calls)
  3. en210.c/h (subroutines for AMS EN210 operations)
  4. 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.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 E2 Studio and create a new C synergy project file.

Step 2: Enter the project name. Then click Next.

Step 3: Select 1.3.0 for the SSP version and S5D9_IOT_ENABLER for the board. Then click Next.

Step 4: Select BSP for the project template selection. Then click Next.

Step 5: Click Yes.

Step 6: This summary window will appear. Check the project information for correctness.

Step 6a: Select the Pins tab. Select IIC2 under Connnectivity:I2C selection. Check whether IIC2 channel is enabled for P5_11/P5_12 pins for the sensor chip.

It is usually default enabled. (P5_11/P5_12 pins use channel 2. Need this information to configure the I2C master driver later.)

Step 6b: Select IIC1 under Connnectivity:I2C selection. Choose Enabled for the operation mode. Choose _B only for the pin group selection.

This IIC1 channel is enabled for P1_1/P1_0 pins for the OLED display module. It needs to be enabled by the user. (P1_1/P1_0 pins use channel 1. Need this information to configure the I2C master driver later.)

Step 7: Select the Thread tab. Click HAL/Common Thread. Add I2C MasterDriver on r_riic.

Note: We need to do it two times because one driver is for the internal I2C bus (EN210 sensor chip) and another driver for the external I2C bus (the OLED display module).

Step 8: Select the Properties tab. Update the name field, channel field, and rate field, callback field and priority level.

This driver is chosen to communicate to the sensor chip which connects to the internal I2C bus (P5_11/P5_12). So, “g_int_i2c_bus” is chosen for the name field.

There are two critical fields. They must be configured correctly.

Channel field is 2 because the sensor chip is connected to I2C channel 2 bus (P5_11/P5_12).

Callback field is NULL. Because API calls are enough to takes care of I2C transaction in this example, callback is not needed. So, it is NULL.

Step 9: Add another I2C MasterDriver on r_riic. This driver is for the external I2C bus (the OLED display module).

Step 10: Select the Properties tab. Update the name field, channel field, and rate field, callback field and priority level.

This driver is chosen to communicate to the OLED display module which connects to the external I2C bus (P1_1/P1_0). So, “g_ext_i2c_bus” is chosen for the name field.

Again there are two critical fields. They must be configured correctly.

Channel field is 1 because the sensor chip is connected to I2C channel 2 bus (P1_1/P1_0).

Callback field is NULL. Because API calls are enough to takes care of I2C transaction in this example, callback is not needed. So, it is NULL.

Step 11: One more thing to add is a global timer. It is used to generate delay in seconds for OLED display to freeze an image long enough to see.

Add timer driver on r_gpt.

Step 12: Select the Properties tab. Update the name field and period value field.

Step 13: Click Generate Project Content (Green arrow). Check for any problems. It should be clean. hal_entry.c is generated.

Step 14: Build Project. There should be no errors.

Step 15: Copy all the C files to the src directory.

Step 16: Build Project. There will be some warnings, but they can be ignored because it is only related to integer type conversion.

Step 17: Right click on the project name to bring up the pop up menu. Select Debug As and then select Debug Configuration. This step is to upload the new code into S5D9 board.

Step 18: On the dialog box, first select “S5D9_I2C_INT_ENV210_OLED Debug”. Then click Debug button.

Step 19: Click Yes.

Step 20: Click Resume Icon (a right green arrow) or Press F8.

Step 21: Click Resume Icon or Press F8 again. This time your main c code (hal_entry()) will be running.

Step 22: You will see “running” in the lower left corner. You should see Adafruit logo on OLED display and then the temperature reading.

Congratulations! You just completed this tutorial. As you can see, you can create multiple I2C bus drivers if the I2C devices are connected to separate I2C bus. The drivers allows you to move data between I2C slave devices easily.

Challenges!

  1. Display humidity value instead of temperature value from ENS210.
  2. Create lowercase letter fonts.
  3. Add simplified Chinese or Japanese fonts.

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

Hi all,

I will have an improved code for you today. The updated code will greatly simplify how to put a message on the OLED display. I will let you know when it is ready. It will be in my github under a different project name ("…ver2"). So, you can compare the new code with the old one.

Best regards,
Michael


#3

Fantastic work! I just read through all of your code/instructions, and I’m looking forward to trying it. You just saved me hours and hours of work adding new sensors to the board. Thanks!


#4

Thank you so much for your kind words!!!

Michael


#6

Hi Dan,

I like that you included the project file for your tutorials. So, I did the same thing for my tutorials. In case if someone cannot follow my step by step procedures. They can import, build and run the project to see the result. It is in the github repository now.

Best,
Michael


#7

Hi Dan,

I got confused. Ha ha. You only included the Medium One diagnostics-intelligence-s5d9 project file. Then I need to follow your procedures to complete the rest.

I am going to leave my final project file in my github. I think that it will make it a lot easier for you and others to debug when things don’t work or my procedures are not clear enough.

Best,
Michael


#8

I like the idea. Thanks for posting the project. I’ll start doing the same for large projects.

Dan