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
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog VenTTracker #04 -  Playing with the IMU
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: javagoza
  • Date Created: 28 Mar 2021 8:23 PM Date Created
  • Views 2224 views
  • Likes 5 likes
  • Comments 0 comments
  • oled
  • venttracker
  • TFT LCD
  • ssd1306
  • game
  • st7735s
  • arduino nano 33 iot
  • covid19
  • design_for_a_cause_2021
  • lsm6ds3
Related
Recommended

VenTTracker #04 -  Playing with the IMU

javagoza
javagoza
28 Mar 2021

In this blog we study the behavior of the IMU (Inertial Measurement Unit) built into the Arduino Nano 33 IoT board. For the project we intend to see the possibility of using the IMU to estimate velocity, magnitude and direction, and to estimate the position of an object on which the IMU travels. To encourage the students we have proposed the creation of a simple game that, on the one hand, needs to calculate the estimates of velocity and position, understand the effect of friction and the sampling frequency and, on the other hand, analyze what type of screen we can use for our CO2 monitor and alternatives to visualize data that allow us to debug applications in a disconnected way.

It has been a week of a lot of coding and we have learned to use the libraries that will allow us to read the data from the IMU and present the data on OLED displays and TFT LCD displays. In a future blog we will describe the code of the game and the repository to download it.

 

image

  Design for A Cause 2021 the VenTTracker project

  01 - Intro and motivation. | 02 - Analyzing Window Types (I) | 03 - Analyzing Window Types (II) | 04 - Playing with the IMU | 05-Sliding Window Mock-up | 06 -  Window Sensor Prototype | 07 - Adjusting the window sensor | 08 - Trying to make a measuring device with the accelerometer | 09 - Checking and updating WiFiNINA Firmware | 10 - Ventilation Monitor on Arduino IoT Cloud | 11 - Wireless Environmental Monitor on Arduino Nano 33 IoT | 12 - Window Anomaly Detection. Edge Impulse & Arduino Nano 33 IoT | 14 - Environmental Monitor Revisited - Version 2 | 13 - Project wrap-up and Lessons learned

 

Tracking System for Classroom Ventilation Routines

A STEM project for classrooms

 

the VenTTracker project - Blog #04 - Playing with the IMU

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

The Game

To get familiar with the LSM6DS6 IMU included in the Arduino NANO 33 IoT development board, we are going to implement a small maze game managed with the IMU.

The object of the game is to drive the ball through the randomly generated maze to eat all the balls. It is a game with time, if the player manages to eat all the cookies in time then he scores and goes to the next challenge where a new random maze is generated. If he does not manage to eat all the balls in time, he loses all the accumulated score and is offered to start over. The game requires coordination between the player's eyes and hands.

The device has no buttons and only communicates with the human with the accelerometer. The game uses the three-axis accelerometer for motion input.

As the game is a 2D-game and it is only interested in acceleration changes in X and Y axis to move the ball through the maze. The playfield offers resistance to the ball in the form of friction that slows it down.

 

The hardware 1.8 "SPI TFT LCD

  • Arduino NANO 33 IoT board
  • 1.8 "SPI TFT LCD Screen Module, 9 pins interface. The LCD drive ic is ST7735S. It's a 128 X 160 (resolution).

 

image

 

 

{gallery} The Maze Game

image

Maze Game Screenshot 01: Maze Game Screenshot 01

image

Maze Game Screenshot 02: Maze Game Screenshot 02

image

Maze Game Screenshot 03: Game Over

 

 

 

How to play

  • Tilt Forward – accelerates the big ball to the back of the playfield.
  • Tilt Backward – accelerates the big ball to the front of the playfield.
  • Tilt Right – accelerates the big ball to the left of the playfield.
  • Tilt Left – accelerates the big ball to the right of the playfield.

 

 

Alternative hardware 0.91 inch OLED I2C Display 128 x 32 Pixels

  • Arduino NANO 33 IoT board
  • 0.91 inch OLED I2C Display 128 x 32 Pixels.This is a small display, only about 1" diagonal

 

image

 

Trying the game with 0.91 inch OLED I2C Display 128 x 32 Pixels

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

The board and the LSM6DS3 IMU

image

 

  • The board's main processor is a low power ArmRegistered CortexRegistered-M0 32-bit SAMD21.
  • The WiFi and BluetoothRegistered connectivity is performed with a module from u-blox, the NINA-W10, a low power chipset operating in the 2.4GHz range.
  • On top of those, secure communication is ensured through the MicrochipRegistered ECC608 crypto chip.
  • And a 6 axis IMU, LSM6DS3

 

 

Product website: https://store.arduino.cc/arduino-nano-33-iot-with-headers

 

 

{gallery} The board and the LSM6DS3 IMU

image

ARDUINO NANO 33 IOT - TOP VIEW DRAWING: LSM6DS3 is situated near the reset button

image

ARDUINO NANO 33 IOT - TOP VIEW: LSM6DS3 is situated near the reset button

image

ARDUINO NANO 33 IOT - BOTTOM VIEW: ARDUINO NANO 33 IOT - BOTTOM VIEW

image

ARDUINO NANO 33 IOT  LSM6DS3 CLOSE UP: ARDUINO NANO 33 IOT  LSM6DS3 CLOSE UP

image

Arduino NANO 33 IoT - LSM6DS3 - Close Up 2: Arduino NANO 33 IoT - LSM6DS3 - Close Up 2

image

Arduino NANO 33 IoT - LSM6DS3 - Close Up 2: Arduino NANO 33 IoT - LSM6DS3 - Close Up 2

 

 

Orientation of the sensor on the board

 

imageimage

 

 

 

LSM6DS3TRLSM6DS3TR in the Arduino NANO 33 IoT

 

Accelerometer

An acceleration sensor measures the acceleration applied to the device, including the force of gravity. The accelerometer returns acceleration force data for the three coordinate axes.

Motion sensors are useful for monitoring device movement, such as tilt, shake, rotation, or swing. The movement is usually a reflection of direct user input (for example, a user steering a car in a game or a user controlling a ball in a game), but it can also be a reflection of the physical environment in which the device is sitting.

Motion sensors by themselves are not typically used to monitor device position but we are going to try image

The linear acceleration sensor always has an offset, which we need to remove. The simplest way to do this is to build a calibration step into our application. During calibration we can ask the user to set the device on a table, and then read the offsets for all three axes. We can then subtract that offset from the acceleration sensor's direct readings to get the actual linear acceleration.

 

LSM6DS3TRLSM6DS3TR

The LSM6DS3 is a system-in-package featuring a 3D digital accelerometer and a 3D digital gyroscope performing at 1.25 mA (up to 1.6 kHz ODR) in high-performance mode and enabling always-on low-power features.The LSM6DS3 has a full-scale acceleration range of ±2/±4/±8/±16 g and an angular rate range of ±125/±250/±500/±1000/±2000 dps.

  • Power consumption: 0.9 mA in combo normal mode and 1.25 mA in combo high-performance mode up to 1.6 kHz.
  • “Always-on” experience with low power consumption for both accelerometer and gyroscope
  • Smart FIFO up to 8 kbyte based on features set
  • Hard, soft ironing for external magnetic sensor corrections
  • Analog supply voltage: 1.71 V to 3.6 V
  • Independent IOs supply (1.62 V)
  • Embedded temperature sensor
  • Size: 2.5 mm x 3 mm x 0.83 mm

The LSM6DS3 is a system-in-package featuring a 3D digital accelerometer and a 3D digital gyroscope performing at 1.25 mA (up to 1.6 kHz ODR) in high-performance mode and enabling always-on low-power features.The LSM6DS3 has a full-scale acceleration range of ±2/±4/±8/±16 g and an angular rate range of ±125/±250/±500/±1000/±2000 dps.

 

 

INT1 and INT2 are not wired. In the diagram of the board we see that neither the INT1 nor the INT2 pin are connected, so we will not be able to use interruptions to wake up our device and we will have to continually poll it.

The IMU is a LSM6DS3, it is a 3-axis accelerometer and 3-axis gyroscope; it is connected to the microcontroller through I2C on the NANO board.

The LSM6DS3 on the Arduino Nano 33 IoT can be use easily through the I2C bus on the slave address 0x6A.

 

Arduino NANO 33 IoT Pinouts

For the Arduino Nano 33 IoT, the pins assignments are described in:

https://github.com/arduino/ArduinoCore-samd/blob/master/variants/nano_33_iot/variant.cpp

https://github.com/arduino/ArduinoCore-samd/blob/master/variants/nano_33_iot/variant.h

 

 

imageimage

image

 

 

{gallery} LSM6DS3 Datasheet

image

IMU DATASHEET:

image

IMU DATASHEET:

image

IMU DATASHEET:

 

 

Software Libraries for the LSM6DS3 IMU

 

We are going to analyze two libraries for the IMU LSM6DS3,

  1. the official Arduino library
  2. Sparkfun library

 

The official Arduino library is a very simple library that will allow us to maintain some compatibility with other IMUs placed on other Arduino boards.

The Sparkfun library allows finer control of IMU programming and access to all IMU registers.

 

LSM6DS3 Arduino Library

The library takes care of the sensor initialisation and sets its values as follows:

 

  • Accelerometer range is set at -4 |+4 g with -/+0.122 mg resolution
  • Gyroscope range is set at -2000 | +2000 dps with +/-70 mdps resolution
  • Output data rate is fixed at 104 Hz

 

The LSM6DS3 is a system-in-package featuring a 3D digital accelerometer and a 3D digital gyroscope.

  • Install the LSM6DS3 Arduino Library with the Library Manager available in the Arduino Software (IDE) .
  • Tools / Manage Libraries

image

 

  • For more info on the library go to https://www.arduino.cc/en/Reference/Arduino_LSM6DS3
  • Lets try an example and check also serial port communication through the USB port

image

  • Select the SimpleGyroscope sample

image

  • Upload and open the Serial Monitor: Tools/Serial Monitor Ctrl-***-M

 

imageimage

 

 

Reading data in no movement condition

image

AX AY AZ

0.040410000 0.018800000 1.008420000

0.041020000 0.019650000 1.007320000

0.041380000 0.020750000 1.008420000

0.041990000 0.019650000 1.006840000

0.041630000 0.020750000 1.007810000

 

AZ is approximately 1 g as expected

AX and AY are near to 0.

 

Functions of the API used in the game

 

accelerationAvailable() : Query if new acceleration IMU data is available.

Syntax: IMU.accelerationAvailable()

Parameters: None

Returns: 0 if no new acceleration IMU data is available, 1 if new acceleration IMU data is available.

 

readAcceleration() : Query the IMU accelerometer and return the acceleration in g

Syntax: IMU.readAcceleration(x,y,z)

Parameters: x,y,z - the float variables where the acceleration values will be stored

Returns: 1 on success, 0 on failure

 

begin() : Initialize the IMU.

Syntax : IMU.begin()

Parameters: None

Returns : 1 on success, 0 on failure

 

end(): De-initialize the IMU.

Syntax: IMU.end()

Parameters: None

Returns: Nothing

 

accelerationSampleRate(): Return the accelerometer sample rate

Syntax: IMU.accelerationSampleRate()

Parameters: None

Returns: The Accelerometer sensor sample rate Hz

 

 

The Sparkfun LSM6DS3 library

To install the official library in the Arduino IDE, go in the menu Tools -> Manage Libraries... In the library manager, search for LSM6DS3 and install the SparkFun LSM6DS3 Breakout by SparkFun Electronics.

We have to change the I2C address to 0x6A (by default, the SparkFun module address is 0x6B). LSM6DS3 myIMU(I2C_MODE, 0x6A);

https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library

 

The Sparkfun library allows finer control of IMU programming and access to all IMU registers. We will use it in tests to see how we can take advantage of ML techniques in our project.

 

Selecting Displays

image

 

Our objective is to have a graphical user interface for:

  • The environmental monitor
  • Debugging when unplugged.

 

For the environmental monitor we need a display capable of showing data such as the image

image

And for debugging, we need a screen that is small and that allows us to update the data quickly.

 

0.91 inch OLED I2C Display 128 x 32 Pixels for debugging

 

The game uses a 0.91 inch OLED I2C Display 128 x 32 Pixels.This is a small display, only about 1" diagonal. It is made of 128x32 individual white OLED pixels, each one is turned on or off by the controller chip. No backlight is required. This reduces the power required to run the OLED.

 

The module we’re using here has only four pins and communicates with the Arduino using I2C communication protocol. This model has no RESET pin.

We just need to connect to the Arduino Nano: SDA (A4); SCL (A5);To control the OLED display you need the adafruit_SSD1306.h and the adafruit_GFX.h

 

 

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

 

 

 

{gallery} 0.91 inch OLED I2C Display 128 x 32 Pixels.

image

0.91 inch OLED I2C Display 128 x 32 Pixels: 0.91 inch OLED I2C Display 128 x 32 Pixels Top View

image

0.91 inch OLED I2C Display 128 x 32 Pixels:0.91 inch OLED I2C Display 128 x 32 Pixels Bottom view

image

0.91 inch OLED I2C Display 128 x 32 Pixels:Breadboard

 

 

Power consumption

Power consumption with displayPower consumption without display
imageimage

 

 

1.8 TFT SPI 128x160 v1.1 for environmental monitor

 

Feature

  • It is a 1.8 "SPI TFT LCD Screen Module, 9pins interface. Not just a LCD break but include SD card (2GB),

  • The LCD drive ic is ST7735S. It's a 128 X 160 (resolution). The LCD has a wide viewing angle, the contrast is also very suitable.

  • The display interface is serial, it just needs 5 wires (CS, RS, SCL, SDA, RST) for controlling.

  • SDcard use hardware SPI interface (CS / MOSI / MISO / SCK), Not solder pins.

 

Pinout

  • LED 3.3V IO and Power Supply pin

  • LED UTFT Support

  • SCL Serial clock input

  • SDA/SDI Serial data input

  • DC:Data/Command selection

  • RST:Reset Low level active

  • CS:Chip Selection,Low level active

  • GND:Ground

  • VDD33:3.3V Power Supply pin

 

ST7735S 132RGB x 162 dot 262K Color with Frame Memory Single-Chip TFT Controller/Driver

The ST7735S is a single-chip controller/driver for 262K-color, graphic type TFT-LCD. It consists of 396 source line and 162 gate line driving circuits.

This chip is capable of connecting directly to an external microprocessor, and accepts Serial Peripheral Interface (SPI), 8-bit/9-bit/16-bit/18-bit parallel interface.

Display data can be stored in the on-chip display data RAM of 132 x 162 x 18 bits

 

#include <SPI.h>

#include <Adafruit_GFX.h>

#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 160 // OLED display height, in pixels

#define TFT_CS        10

#define TFT_RST        -1 // Or set to -1 and connect to Arduino RESET pin

#define TFT_DC         8

Adafruit_ST7735 display(TFT_CS, TFT_DC, TFT_RST);

 

 

 

{gallery} 1.8 TFT SPI 128x160

image

1.8 TFT SPI 128x160 : Top view

image

1.8 TFT SPI 128x160 : Bottom view

image

1.8 TFT SPI 128x160 : Dimensions

image

1.8 TFT SPI 128x160 : Breadboard

image

1.8 TFT SPI 128x160 : Connected to the Arduino Nano 33 IoT

 

 

Summary and conclusions

The ST7735 TFT uses SPI to communicate. It is very slow for a graphics game.

We can't use double buffer technique. For an ST7735 (128 x 160 x 16 bit color) would require  the transmission of 327,680 bits.

It has been very difficult to remove the flicker but we have learned to update the screen by small regions by creating and loading small bitmaps.

 

VenTTracker Blogs
VenTTracker #01 - Intro and motivation.
VenTTracker #02 - Analyzing window types.
VenTTracker #03 - Analyzing window types II
VenTTracker #04 - Playing with the IMU
VenTTracker #05 - Sliding Window Mock-up
VenTTracker #06 - Window Sensor Prototype
VenTTracker #07 - Adjusting the window sensor
VenTTracker #08 - Trying to make a measuring device with the accelerometer
VenTTracker #09 - Checking and updating WiFiNINA Firmware
VenTTracker #10 - Ventilation Monitor on Arduino IoT Cloud
VenTTracker #11 - Wireless Environmental Monitor on Arduino Nano 33 IoT
VenTTracker #12 - Window Anomaly Detection. Edge Impulse & Arduino Nano 33 IoT
VenTTracker #14 (aka #11 bis) - Environmental Monitor Revisited - Version 2
VenTTracker #13 - Project wrap-up and Lessons learned

 

<< Previous VenTTracker BlogNext VenTTracker Blog  >>
VenTTracker #03 -  Analyzing window types IIVenTTracker #05 -  Sliding Window Mock-up
  • 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