element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Low Power IoT Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Low Power IoT Design Challenge
  • More
  • Cancel
Low Power IoT Design Challenge
Blog Wearable Gesture Control - #3 Integrating LCD & Accelerometer
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: zst123
  • Date Created: 7 Oct 2021 10:30 AM Date Created
  • Views 763 views
  • Likes 1 like
  • Comments 0 comments
Related
Recommended

Wearable Gesture Control - #3 Integrating LCD & Accelerometer

zst123
zst123
7 Oct 2021

Table of Contents

Wearable Gesture Control - #1 Introduction

Wearable Gesture Control - #2 Install & Setup Template Application

Wearable Gesture Control - #3 Integrating LCD & Accelerometer

Wearable Gesture Control - #4 Collecting data for Edge Impulse

Wearable Gesture Control - #5 Deploying Edge Impulse model & Fixing Makefile issues

Wearable Gesture Control - #6 BLE communication with an app

Wearable Gesture Control - #7 Low Power Profiling

 

See all my posts here

Introduction

 

In this blog I shall use the CY8CKIT-028-TFT display shield. I will add the code to talk to the LCD display and the accelerometer. The display is mainly to show me useful debugging information. The accelerometer will serve to provide gesture movement dataset in real-time.

image

 

There are many good example programs done by Infineon (Official information found on Infineon Github). I have adapted much of the code from them:

  • https://github.com/Infineon/CY8CKIT-028-TFT
  • https://github.com/Infineon/display-tft-st7789v#quick-start
  • https://github.com/Infineon/sensor-motion-bmi160

 

 

Interfacing with LCD Library

 

Right click on the project inside Project Explorer > ModusToolbox > Library Manager

image

 

Here we will be enabling the low-level library for the display, and a high-level emwin middleware which is a powerful library for creating GUI.
Turn on these libraries:

  • Board Utils > CY8CKIT-028-TFT
  • PSoC 6 Middleware > emwin

 

image

 

At the bottom, we can also see the changes that are about to be made. In this case, the tool automatically a few extra libraries for us. This is because the shield, in addition to the TFT LCD screen, also incorporates a motion sensor, ambient light sensor and PDM microphone.

image

Once I'm done with my choices, choose Update at the bottom right. ModusToolbox will process our changes. Click Close once it is successful

 

In the Makefile, this to COMPONENTS. It is to indicate we are using a Non-TouchScreen.

 

COMPONENTS+=EMWIN_NOSNTS

 

At the top of my main file, I also added a hello world code.

 

#include "cy_tft.h" // Library for CY8CKIT-028-TFT

#include "GUI.h" // Library for emWin

 

 

/* Init the display */

    cy_tft_io_init();

    GUI_Init();

    GUI_SetFont(GUI_FONT_32B_1);

    GUI_DispString("Hello World");

 

image

 

To make it look more professional, I created a bitmap in Paint.

Bitmap
image

 

And I generated a bitmap using the emWin generator.

image

 

Up until this point, please see my Github diffs. It shows what changes I have made to the code

  • https://github.com/zst123/Element14_Low-Power-IoT/commit/daa4aae3e98ac36a1795fbf4968c3ef433164a48

 

Interfacing with the Motion Sensor

 

As previously, we have added the library for the display shield (Board Utils > CY8CKIT-028-TFT), it has also included the BMI160 library for the motion sensor which is on the same shield.

 

In the main.c file, include the library.

 

#include "mtb_bmi160.h" // Library for Motion Sensor

 

As for the motion sensor, as it is a lot more complicated, I created a new RTOS task to initialise it. Importantly, the BMI160 library depends on some system delays, thus initialising must be done in an RTOS thread after the scheduler has started.

 

I first initialise the I2C hardware pins, and then initialise the sensor library

 

    /* Initialize i2c for motion sensor */

    result = cyhal_i2c_init(&i2c, CY8CKIT_028_TFT_PIN_IMU_I2C_SDA, CY8CKIT_028_TFT_PIN_IMU_I2C_SCL, NULL);

 

    /* Initialize motion sensor */

    mtb_bmi160_t motion_sensor;

    result = mtb_bmi160_init_i2c(&motion_sensor, &i2c, MTB_BMI160_DEFAULT_ADDRESS);

 

In a continuous loop, I can get the data at a fixed timing. (In this case every 100ms)

 

        mtb_bmi160_read(&motion_sensor, &data);

        vTaskDelay(100);

 

        // Get the readings from the `data` struct:
        //   data.accel.x, data.accel.y, data.accel.z, 

        //   data.gyro.x, data.gyro.y, data.gyro.z

 

For the full code, please see my Github commit for the changes:

  • https://github.com/zst123/Element14_Low-Power-IoT/commit/2c9700d0e0990d1859fc3da32bcbd2c4f3357312

 

Solving a conflict with Motion Sensor I2C

 

Unfortunately, there is a conflict with the I2C communication which randomly causes the processor to go into a halt (or crash) after reading the sensor data.

 

After investigation, it appears that the CapSense tuning functions use the EzI2C HAL initialization library (https://www.cypress.com/documentation/component-datasheets/ezi2c-slave) which conflicts with the standard CyHAL I2C functions.
(ie. both libraries should be used independently and cannot be used at the same time)

 

As a workaround, I decided to just comment out the tuning functions. I'm not sure what exactly the effects of tuning are, but CapSense seems to work fine without tuning too.

 

The changes are documented in this commit:

  • https://github.com/zst123/Element14_Low-Power-IoT/commit/d9594c18ea7251e85fc82d954c11cacaf591dc24

 

After doing those changes, the sensor works reliably!

 

image

 

In the next blog...

 

I will integrate the accelerometer to an data forwarder for Edge Impulse. I plan to use Edge Impulse to do inference of accelerometer data to detect gestures using TinyML to characterise the data for gesture control.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube