Get Started with the SensorTile.box (Extract)

Page 1

H0W2

Get Started with the SensorTile.box STmicroelectronics’ wireless IoT & wearable sensor development kit

Dogan Ibrahim

This book is an introduction to the SensorTile.box and includes the following: > Brief specifications of the SensorTile.box; description of how to install the STE BLE Sensor app on an iOS or Android compatible smartphone required to communicate with the box. > Operation of the SensorTile.box in Basic mode is described in detail by going through all of the pre-loaded demo apps, explaining how to run these apps through a smartphone. > An introduction to the Expert mode with many example apps developed and explained in detail enabling users to develop their own apps in this mode. Again, the STE BLE Sensor app is used on the smartphone to communicate with the SensorTile.box and to run the developed apps. > The book then describes in detail how to upload the sensor data to the cloud. This is an important topic since it allows the sensor measurements to be accessed from anywhere with an Internet connection, at any time. > Finally, Pro mode is described in detail where more experienced people can use the SensorTile.box to develop, debug, and test their own apps using the STM32 open development environment (STM32 ODE). The Chapter explains how to upload the developed firmware to the SensorTile.box using several methods. Additionally, the installation and use of the Unicleo-GUI package is described with reference to the SensorTile.box. This PC software package enables all of the SensorTile.box sensor measurements to be displayed or plotted in real time on the PC.

About the Author Prof Dr Dogan Ibrahim has BSc degree in electronic engineering, an MSc degree in automatic control engineering, and a PhD degree in digital signal processing. Dogan has worked in many industrial organizations before he returned to academic life. Prof Ibrahim is the author of over 60 technical books and over 200 technical articles on microcontrollers, microprocessors, and related fields. He is a Chartered electrical engineer and a Fellow of the Institution of Engineering Technology.

Get Started with the SensorTile.box

The SensorTile.box can be operated in three modes: Basic mode, Expert mode, and Pro mode. Basic mode is the easiest way of using the box since it is pre-loaded with demo apps and all the user has to do is choose the required apps and display or plot the measured data on a smartphone using an app called STE BLE Sensor. In Expert mode users can develop simple apps using a graphical wizard provided with the STE BLE Sensor. Pro mode is the most complex mode allowing users to develop programs and upload them to the SensorTile.box.

H0W2

‘SensorTile.box’ is a portable multi-sensor circuit board housed in a plastic box and developed by STMicroelectronics. It is equipped with a high-performance 32-bit ARM Cortex-M4 processor with DSP and FPU, and various sensor modules, such as accelerometer, gyroscope, temperature sensor, humidity sensor, atmospheric pressure sensor, microphone, and so on. SensorTile.box is ready to use with wireless IoT and Bluetooth connectivity that can easily be used with an iOS or Android compatible smart phone, regardless of the level of expertise of the users. SensorTile.box is shipped with a long-life battery and all the user has to do is connect the battery to the circuit to start using the box.

Volume 1

Dogan Ibrahim

Elektor International, Media BV www.elektor.com

1

knows how



H0W 2 Get Started with the SensorTile.box â—? Dogan Ibrahim


This is an Elektor Publication. Elektor is the media brand of

Elektor International Media B.V. PO Box 11 NL-6114-ZG Susteren, The Netherlands Phone: +31 46 4389444

All rights reserved. No part of this book may be reproduced in any material form, including

photocopying, or storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this publication, without the written permission of the copyright holder except in accordance with the provisions of the Copyright Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licencing Agency Ltd., 90 Tottenham Court Road, London, England W1P 9HE. Applications for the copyright holder's permission to reproduce any part of the publication should be addressed to the publishers.

British Library Cataloguing in Publication Data

A catalogue record for this book is available from the British Library ISBN 978-1-907920-97-4 EBOOK 978-3-89576-380-9 EPUB 978-3-89576-381-6 © Copyright 2020: Elektor International Media b.v. Prepress Production: D-Vision, Julian van den Berg First published in the United Kingdom 2020

Elektor is part of EIM, the world's leading source of essential technical information and electronics products for pro engineers, electronics designers, and the companies seeking to engage them. Each day, our international team develops and delivers high-quality content - via a variety of media channels (including magazines, video, digital media, and social media) in several languages - relating to electronics design and DIY electronics. www.elektormagazine.com

LEARN DESIGN SHARE


Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Chapter 1 • Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Chapter 2 • The SensorTile.box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2 The SensorTile.box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2.1 The System clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.2.2 Pushbuttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.2.3 The STM32L4R9ZIJ6 microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.2.4 Digital temperature sensor (STTS751) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.2.5 6-axis inertial measurement unit (LSM6DSOX) . . . . . . . . . . . . . . . . . . . . . . 19 2.2.6 3-axis accelerometer (LIS2DW12 and LIS3DHH) . . . . . . . . . . . . . . . . . . . . . 19 2.2.7 3-axis magnetometer (LIS2MDL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.2.8 Altimeter/pressure sensor (LPS22HH) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.2.9 Microphone/audio sensor (MP23ABS1) . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.2.10 Humidity sensor (HTS221) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.2.11 Bluetooth connectivity (SPBTLE-1S) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.2.12 STBC02AJR Li-Ion linear battery charger . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.2.13 STBB3JR 2MHz DC-DC converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.3 Using the SensorTile.box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Chapter 3 • The Entry level mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.2 The STE BLE Sensor app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3.2.1 Logging the data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2.2 Plotting the data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.2.3 Bluetooth signal level and battery status . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.3 Example apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.3.1 Compass and Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.3.2 Data Recorder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.3.3 Pedometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 3.3.4 Baby Crying Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 3.3.5 Human Activity Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

●5


H0W 2 Get Started with the Sensor Tile Box 3.3.6 In-Vehicle Baby Alarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 3.3.7 Sensor Fusion – Quaternion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 3.3.8 Vibration monitor — training . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 3.3.9 Vibration Monitor - Compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 3.3.10 The ‘About’ display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3.3.11 The Sensors display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 3.3.12 Displaying more information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 3.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Chapter 4 • The Expert level mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.2 Creating a new app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.3 APP 1 - Temperature display app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.4 APP 2 – Turn the LED ON if the temperature is above a predefined value . . . . . . . 54 4.5 APP 3 – Audio sound level meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 4.6 APP 4 - Turn the LED ON if the magnetic field is above a predefined value . . . . . . . 59 4.7 APP 5 – Magnetic people-counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 4.8 APP 6 – Frequency spectrum of a square wave . . . . . . . . . . . . . . . . . . . . . . . . . . 65 4.9 APP 7 – Temperature and humidity inside a fridge . . . . . . . . . . . . . . . . . . . . . . . 66 4.10 APP 8 – Acceleration of our car . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 4.11 APP 9 – Bandwidth of shaking hand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 4.12 APP 10 – Pedometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.13 APP 11 – Inclinometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 4.14 APP 12 – Time and date stamped log of temperature and humidity . . . . . . . . . . . 79 4.15 APP 13 – Sensor fusion quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 4.16 APP 14 – Free-fall detection and blinking the LED . . . . . . . . . . . . . . . . . . . . . . . 85 4.17 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Chapter 5 • Connecting to the Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.2 The IBM Watson IoT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.2.1 Sending sensor data to the IBM Watson IoT – Quickstart . . . . . . . . . . . . . . . 88 5.2.2 Sending sensor data to IBM Watson IoT . . . . . . . . . . . . . . . . . . . . . . . . . . 92 5.3 Generic MQTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

●6


Contents 5.3.1 How MQTT works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 5.3.2 The Mosquitto Broker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.3.3 Displaying the ambient temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 5.3.5 Displaying the ambient temperature, humidity, and pressure as gauges . . . 102 5.4 Sending sensor data to the Azure IoT – ST Web Dashboard . . . . . . . . . . . . . . . . 105 5.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Chapter 6 • The Pro level mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 6.2 Using SensorTile.box in Pro mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 6.3 Uploading firmware to SensorTile.box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 6.3.1 Installing the STM32CubeProg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 6.3.2 Installing the STM32 ST-LINK Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 6.4 The Unicleo-GUI software package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 6.4.1 Installing the Unicleo-GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 6.5 Uploading the firmware DataLogExtended.bin using the DFU . . . . . . . . . . . . . . . 111 6.6 Restoring the original firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 6.7 Uploading firmware using the STM32 ST-LINK Utility . . . . . . . . . . . . . . . . . . . . 118 6.8 SensorTile.box program development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.9 Installing the STM32CubeIDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.10 SensorTile.box block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 6.11 The STM32L4R9ZIJ6 microcontroller clock module . . . . . . . . . . . . . . . . . . . . . 122 6.12 Project – Flashing the green user LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.12.1 The Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.13 Using the demo application programs supplied with the Pro mode pack . . . . . . . 136 6.14 Project – Reading the temperature sensor data and activating the user LED . . . 138 6.14.1 The LPS22HH pressure/temperature sensor . . . . . . . . . . . . . . . . . . . . . . 139 6.14.2 The program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 6.15 Project – Serial interface to a PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 6.16 Project – Displaying the temperature on PC screen and activating the user LED . . 166 6.17 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Chapter 7 • The future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

●7


H0W 2 Get Started with the Sensor Tile Box Appendix A • Available inputs and functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Appendix B • Available expressions and functions . . . . . . . . . . . . . . . . . . . . . . . . 180 Appendix C • Primary and secondary functions . . . . . . . . . . . . . . . . . . . . . . . . . . 181 Appendix D • Available functions and outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Appendix E • Inputs and settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Declaration and Acknowledgement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

●8


Preface

Preface Sensors are quintessential devices used extensively in nearly all microcontroller-based applications. In many applications the designer chooses the sensors to be used as external devices and connects them to the target processor. Although most sensors can directly be connected to a processor, some sensors require special interface circuitry before they can be connected to a processor. For example, the connection of an analogue sensor to a digital processor requires an ADC converter. Similarly, it is important that the output voltage of a sensor is compatible with the processor inputs. Some sensors provide +5Â V outputs which is not compatible with many present-day processors which operate at around +3.3Â V. Another problem with using external sensors is that the operation of some sensors are so complex that special libraries are required to use them correctly. Such libraries may not freely available and the designer may have to develop the required libraries for the target processor. SensorTile.box is a small multi-sensor circuit board housed in a plastic box and developed by STMicroelectronics. The circuit board is equipped with a high performance 32-bit ARM Cortex-M4 processor, and various sensor modules, such as accelerometer, gyroscope, temperature sensor, humidity sensor, atmospheric pressure sensor, microphone, and so on. SensorTile.box is a ready to use box with wireless IoT and Bluetooth connectivity that can easily be used with an iOS or Android compatible smart phone, regardless of the level of technical expertise of the users. SensorTile.box is shipped with a long-life battery and all the user has to do is connect the battery to the circuit and start using the box. SensorTile.box can be operated in three modes: Basic mode, Expert mode, and Pro mode. Basic mode is the easiest way of using the box since it is pre-loaded with demo apps and all the user has to do is choose the required apps and display or plot the measured data on a smart phone using an app called STE BLE Sensor on the smart phone. In Expert mode users can develop simple apps using a graphical wizard provided as part of STE BLE Sensor. Pro mode is the most complex mode which allows users to develop programs and upload them to the SensorTile.box. This book is an introduction to the SensorTile.box and describes how to use it in all three modes. The book starts with giving the brief specifications of the box, and then describes how to install the smartphone app required to communicate with the box. The operation of the SensorTile.box in Basic mode is described in detail by going through all of the pre-loaded demo apps, explaining how to run the apps through a smartphone using the STE BLE Sensor app. Then, an introduction is made to the Expert mode and many example apps have been developed and explained in detail so that users can develop their own applications in this mode. Again, the STE BLE Sensor app is used on the smart phone to communicate with the SensorTile.box and to run the developed apps.

â—?9


H0W 2 Get Started with the Sensor Tile Box

The book then describes in detail how to upload the sensor data to the cloud. This is an important topic since it allows the sensor measurements to be accessed from anywhere with an Internet connection, at any time. Finally, the Pro mode is described in detail where more experienced users can use the SensorTile.box to develop, debug, and test their own apps using the STM32 open development environment (STM32 ODE). The installation and use of the Unicleo-GUI graphical package has been described with reference to the SensorTile.box. This software package enables the users to easily access all the sensors on the SensorTile.box and display or plot the sensor readings in real time. I hope the readers find the book helpful and enjoy reading it, and at the same time develop some interesting apps on the SensorTile.box. Prof Dr Dogan Ibrahim London, July 2020

â—? 10


Chapter 1 • Introduction

Chapter 1 • Introduction In order for a microcontroller to perform a useful task it needs to communicate with the outside, (i.e. the real world). This communication can be in the form of reading an input signal from a switch, keyboard, mouse, touch screen, sensor, or some other type of input device or several inputs. The signals input to the microcontroller are processed and one or more outputs are generated. These outputs can be in the form of lights, displays, plotters, sound generating devices, and many more. Sensors and transducers are very important devices used extensively in nearly all microcontroller based applications. The word transducer is the collective term used for both sensors and actuators. A sensor is an electronic device which generates an electrical signal usually linearly proportional to what it measures. For example, a temperature sensor generates electrical signals proportional to the measured temperature. Thus, by measuring the value of the electrical signal we can find out the temperature at the time of measurement. An actuator is usually a mechanical device which moves under the effect of an electrical signal, such as a relay, a motor and so on. Most sensors in real life are analogue, where analogue output voltages are generated which are proportional to the measured variables. For example, the LM35DZ type analogue temperature sensor outputs voltages given by the equation V = 10 mV/ºC. In this case, if the measured temperature is 10ºC then the output voltage of the sensor will be 100 mV and so on. Analog sensors cannot directly be connected to digital processors. Analogue-to-digital converter (ADC) modules are used to convert an analogue signal into digital form so that it can be connected to a digital processor. The data width of the ADC determines its resolution and accuracy. In the past, most ADC used to be 8-bits wide, but nowadays ADCs are available with much higher data widths (e.g. 10, 12, 16 etc.), providing accurate readings of analogue voltages. Digital sensors have the advantage that they can be directly connected to digital processors. For example, DS18B20 is a digital temperature sensor chip which can be directly connected to the input ports of a digital processor. The availability of digital sensors is rather limited as most sensors provide analogue outputs. Using external sensors in digital processors can complicate the designs for both hardware and software reasons. The need for an additional external component such as an ADC makes the circuit more complex, although most modern digital processors nowadays have built-in ADCs. Another problem with using an external component is that the voltage levels of the component may not be compatible with the input/output voltage requirements of the digital processor and this may require additional circuitry, such as voltage step-up or step-down circuits. The operation of some sensors are so complex that it may be necessary to use special library modules if they are available, or to develop them if such libraries are not readily available. This task creates additional complexity to the design.

● 11


H0W 2 Get Started with the Sensor Tile Box

SensorTile.box is a small multi-sensor circuit board housed in a plastic box and developed by STMicroelectronics. The circuit board is equipped with a high performance 32-bit ARM Cortex-M4 processor and various sensor modules, such as an accelerometer, gyroscope, temperature sensor, humidity sensor, atmospheric pressure sensor and microphone. SensorTile.box is a ready to use box with wireless IoT and Bluetooth connectivity that can easily be used with an iOS or Android compatible smartphone, regardless of the level of expertise of the user. The advantage of using the SensorTile.box is that all its sensors have been connected to the processor chip on the board, additionally, there is no need to develop any special library modules to access these sensors. SensorTile.box is shipped with a long-life battery and all the user has to do is connect the battery to the circuit and start using the box. For example, the SensorTile.box can be placed inside a fridge in order to measure and log the temperature and the humidity inside the fridge. This task does not require any hardware changes or any programming. The user can simply press a few buttons on a smartphone and then place the box inside the fridge to collect the data. The collected data can later be analysed and plotted as required using tools such as Microsoft Excel, the popular spreadsheet application. SensorTile.box can be operated in three modes: Basic mode, Expert mode, and Pro mode. Basic mode is the easiest way of using the box since it is pre-loaded with demo apps and all the user has to do is choose the required apps and display or plot the measured data on a smartphone using an app called ‘STE BLE Sensor’. In Expert mode, users can develop simple apps using a graphical wizard provided as part of STE BLE Sensor. Pro mode is the most complex mode which allows users to develop programs and upload them to the SensorTile.box. This book is an introduction to the SensorTile.box and describes how to use it in all three modes. Chapter 2 begins with the brief specifications of the box and then describes how to install the smartphone app required to communicate with the box. The operation of the SensorTile.box in Basic mode is described in detail in Chapter 3 by analysing the pre-loaded demo apps, explaining how to run the apps through a smartphone using the STE BLE Sensor app. Following which, an introduction is made to Expert mode in Chapter 4 and many example apps have been developed and explained in detail so that users can develop their own applications in this mode. Again, the STE BLE Sensor app is used on the smartphone to communicate with the SensorTile.box and to run the developed apps. Chapter 5 delves into cloud programming and describes in detail how to upload sensor data to the cloud. This is an important topic since it allows the sensor measurements to be accessed from anywhere with Internet connectivity at any time.

● 12


Chapter 1 • Introduction

Finally, the Pro mode is described in detail in Chapter 6 where more experienced users can use the SensorTile.box to develop, debug, and test their own apps using the STM32 open development environment (STM32 ODE). Appendices are given at the end of the book in the form of references to help users who wish to develop apps in Expert mode. Using these references should help users choosing sensors correctly for their apps.

● 13


H0W 2 Get Started with the Sensor Tile Box

Chapter 2 • The SensorTile.box 2.1 Overview The SensorTile.box is a ready to use wireless IoT and wearable sensor evaluation and development kit manufactured by STMicroelectronics. The actual product code of the kit is STEVAL-MKSBOX1V1. The SensorTile.box was first demonstrated at the IoT World Conference in Santa Clara, California, on May 13, 2019. An early version of the SensorTile. box was used by Luca Colli as he climbed Everest where the device was used to measure his movements and store information about his performance. The latest version of the device is relatively small, flexible, low power, highly accurate, easy to use and configure, and it can be used in a wide range of sensing, tracking, and monitoring applications. In this Chapter we will be looking at the features of this development box and describe briefly how it can be used. 2.2 The SensorTile.box As shown in Figure 2.1, The SensorTile.box is shipped in a plastic container, consisting of the actual processor housed in a small robust blue plastic container, a plastic container lid, a small programming board, a ribbon cable, and a folded leaflet that shows the basic features of the processor.

Figure 2.1: The SensorTile.box The SensorTile.box is a Plug & Play module that is connected to a smartphone through Bluetooth Low Energy technology, allowing users to observe and calculate the data detected by the sensors, including step counting, trajectory, speed and the distance travelled, or environmental monitoring, such as altitude, humidity, temperature and pressure. The SensorTile.box comes with a lithium rechargeable battery which is not connected to the circuit board for safety reasons during transportation. You should open the processor box by unscrewing the two screws located on the top of the processor box, and then connect the 2-pin battery cable to the battery connector located at the rear side of the circuit board. The processor box should then be closed.

● 14


Chapter 2 • The SensorTile.box

A micro-B USB connector is placed at the side of the processor box (see Figure 2.2) that can be used to charge the battery and at the same time to communicate with the processor board.

Figure 2.2: Micro USB connector on the processor box There are 3 LEDs on the box: • A BLUE LED (on I/O port PB15) flashes once every 10 seconds when a valid Bluetooth connection is available. • A RED LED indicates the battery condition and flashes while the battery is charging. • A GREEN LED (on I/O port PF2) turns ON by specific user functions or when SensorTile.box firmware is being updated. The SensorTile.box processor is equipped with low power and high precision MEMS sensors. The processor board has the following features (see Figure 2.3): • STM32L4R9ZIJ6 ultra-low-power, 120 MHz ARM Cortex-M4 microcontroller with DSP and FPU and 2048 KB flash memory • LQFP144 package • 16 MHz crystal oscillator, 32 kHz crystal oscillator for RTC • 3 x SPI bus, 3 x I2C bus • microSD slot • 3 pushbuttons (BOOT, PWR, USER) • Digital temperature sensor (STTS751) • 6-axis inertial measurement unit (LSM6DSOX) • 3-axis accelerometer (LIS2DW12 and LIS3DHH) • 3-axis magnetometer (LIS2MDL) • Altimeter/pressure sensor (LPS22HH) • Microphone/audio sensor (MP23ABS1) • Humidity sensor (HTS221) • Bluetooth connectivity (SPBTLE-1S) • HCP602535ZC 500mAh, 3.7 V Li-Ion chargeable battery

● 15


H0W 2 Get Started with the Sensor Tile Box

• STBC02AJR Li-Ion linear battery charger • STBB3JR 2 MHz DC-DC converter • FTSH107 connector for SWD debugging and UART Tx/Rx Programming and debugging interface (for professional development) • 57 mm x 38 mm x20 mm IP54 plastic container

Figure 2.3: Block diagram of the SensorTile.box processor, © STMicroelectronics. Used with permission Brief details of the components that make up the SensorTile.box are given in the next subsections. 2.2.1 The System clock SensorTile.box System Clock can be driven by an internal or external oscillator, as well as a main PLL clock. By default, the System clock is driven by the PLL clock at 80 MHz, driven by the 16 MHz external crystal oscillator. The system clock can be boosted to 120 MHz. 2.2.2 Pushbuttons The three pushbuttons (see Figure 2.4) have the following functions: BOOT: This button is used to let the SensorTile.box enter the DFU programming and debugging mode. PWR: This button is used to Power on/off the board when battery is connected USER: This is a general-purpose user button

● 16


Chapter 2 • The SensorTile.box

Figure 2.4: Pushbuttons on the SensorTile.box processor board Figure 2.5 shows the sensors on the processor board.

Figure 2.5: Sensors on the processor board

â—? 17


H0W 2 Get Started with the Sensor Tile Box

2.2.3 The STM32L4R9ZIJ6 microcontroller This 32-bit powerful ARM processor is at the heart of the SensorTile.box which has the following basic features: • 32-bit Cortex-M4 with FPU, adaptive real-time accelerator allowing 0-wait state execution, MPU and DSP instructions • 2 MB flash memory • 1.71 to 3.6 V operating range • Up to 120 MHz operating frequency • 125 nA standby mode power consumption • 43 μA/MHz run mode power consumption • 1.25 DMIPS/MHz (Drystone 2.1) • 4 to 48 MHz crystal oscillator • RTC with calendar and alarm • 24 capacitive sensing channels • Graphics interface • 16 timers • 136 input/output ports • 12-bit ADC • 2x 12-bit DAC • 2x operational amplifiers • 2x comparators • 20x communication interfaces (2x serial audio, 4x I2C, 6x UART, 3x SPI, CAN) • 14-channel DMA controller • 8-14 bit camera interface (black & white and colour)

2.2.4 Digital temperature sensor (STTS751) The STTS751 (STMicroelectronics) is a 6-pin ultra-low current digital temperature sensor chip that communicates over the 2-wire SMBus, measuring the temperature very accurately between 9 and 12 bits, with the default of 10 bits. At 9 bits the step size is 0.5 ºC, and at 12 bits it is 00625 ºC, while at the default resolution it is 0.25 ºC with a conversion time of 21 milliseconds. The device can be programmed to indicate an interrupt driven alarm condition if the measured temperature exceeds a user programmed value. The slave address of the STTS751 is user configurable where up to 8 such devices can be connected to the SMBus. The basic features of the STTS751 are: • Operating voltage 2.25 V to 3.6 V • Operating temperature -40 ºC to +125 ºC • Up to 12-bit resolution with 0.0625 ºC/LSB • ±0.5 ºC accuracy • 3 μA standby current • 20 μA supply current (for 1 conversion/sec) • 21 ms conversion time (at 10-bit resolution))

● 18


Chapter 2 • The SensorTile.box

2.2.5 6-axis inertial measurement unit (LSM6DSOX) The LSM6DSOX (STMicroelectronics) is a low-power (0.55 mA) inertial module that features a 3D digital accelerometer and a 3D digital gyroscope in a package. The device has a full-scale acceleration range of ±2/±4/±8/±16 g and an angular rate range of ±125/±250 /±500/±1000/±2000 dps. The basic features of the LSM6DSOX are: • Operating voltage 1.71 V to 3.6 V • 9 Kbyte FIFO • Very small footprint (2.5 mm x 3 mm x 0.83 mm) • 0.55 mA current consumption • ±2/±4/±8/±16 g full scale • ±125/±250/±500/±1000/±2000 dps full scale • SPI / I2C & MIPI I3CSM serial interface compatible • Motion detection, tilt detection, pedometer, step detector and step counter • Embedded temperature sensor • Interrupts for free-fall, wakeup, 6D/4D orientation • Machine learning core 2.2.6 3-axis accelerometer (LIS2DW12 and LIS3DHH) The LIS3DHH (STMicroelectronics) is an ultra-high resolution 3-axis linear accelerometer with a full scale of ±2.5 g. The measured acceleration is available through a standard SPIwire digital interface. The basic features of the LIS3DHH are: • 16-bit data output • 3-axis ±2.5 g full-scale • SPI interface • Embedded 12-bit temperature sensor • Embedded 32 level FIFO • High stability over temperature (< 0.4 mg/°C) and time • Operating temperature -40 °C to +85 °C The LIS2DW12 (STMicroelectronics) ultra-low power MEMS digital motion sensor chip is a high performance 3-axis linear accelerometer chip. The LIS2DW12 has user-selectable full scales of ±2g/±4g/±8g/±16 g and is capable of measuring accelerations with output data rates from 1.6 Hz to 1600 Hz. The device has an integrated 32-level FIFO buffer allowing the user to store local data. The LIS2DW12 has internal electronics to detect free-fall, wakeup, single and double tap, activity/inactivity, motion detection, portrait/landscape detection, and 6D/4D orientation.

● 19


H0W 2 Get Started with the Sensor Tile Box

The basic features of the LIS2DW12 are: • Operating voltage 1.62 V to 3.6 V • Ultra-low power consumption (< 1 μA in active mode, 50 nA in power-down mode) • ±2 g/±4 g/±8 g/±16 g full scale • I2C/SPI digital interface to the host processor • 16-bit data output • Embedded temperature sensor • 32-level FIFO • Single data conversion (on demand) 2.2.7 3-axis magnetometer (LIS2MDL) The LIS2MDL (STMicroelectronics) is an ultra-low power 3-axis digital output magnetometer that can be used to detect magnetic fields. The device features ±50gauss magnetic field dynamic range with three magnetic field channels. The output can be configured to generate an interrupt when magnetic field is detected. The output data is 16-bits and interface to the device is through the I2C serial bus. The basic features of the LIS2MDL are: • Operating voltage 1.71 V to 3.6 V • Current consumption 200 μA in high-resolution mode, 50 μA in low-power mode • ±50 gauss magnetic dynamic range • 15 mgauss to 500 mgauss self-test range • Operating temperature –40 °C to +85 °C 2.2.8 Altimeter/pressure sensor (LPS22HH) The LPS22HH (STMicroelectronics) is a low-power MEMS absolute pressure sensor chip that can be used as a digital output barometer. The device communicates with the host processor through I2C, MIPI I3CSM, or an SPI interface. Data can be read from the device through an interrupt service routine. The basic features of the LPS22HH are: • Operating voltage 1.7 V to 3.6 V • 260 hPa to 1260 hPa absolute pressure range • 0.5 hPa absolute pressure accuracy with embedded temperature compensation • Current consumption < 4 μA • 24-bit pressure data output • Interrupt functions: Data-Ready, FIFO flags, pressure thresholds 2.2.9 Microphone/audio sensor (MP23ABS1) The MP23ABS1 (STMicroelectronics) is a low-power, MEMS capacitive microphone and an IC interface which can be used to detect audio waves. The sensitivity of the device is 38 dBV±1 dB with minimum 64 dB signal-to-noise ratio.

● 20


Chapter 2 • The SensorTile.box

The basic features of the MP23ABS1 are: • Operating voltage 1.52 V to 3.6 V • Omnidirectional • Flat audio frequency response • High signal-to-noise ratio (64 dB) • Temperature range -40 ºC to +85 ºC 2.2.10 Humidity sensor (HTS221) The HTS221 (STMicroelectronics) is a low-power digital relative humidity and temperature sensor chip. The device is based on a polymer dielectric planar capacitor structure, having the operating temperature -40 °C to +120 °C. The basic features of the HTS221 are: • Operating voltage: 1.7 V to 3.6 V • 2 μA low-power consumption • 1 to 100% relative humidity range • Humidity accuracy: ±4.5% rH (20% to 80% rH) • Temperature accuracy: ± 0.5 °C (15 °C to +40°C) • 16-bit humidity and temperature output data • I2C and SPI interface • Factory calibrated 2.2.11 Bluetooth connectivity (SPBTLE-1S) The SPBTLE-1S (STMicroelectronics) is a low-power, low-energy Bluetooth v4.2 compliant module (BLE) used to provide Bluetooth connectivity to the SensorTile.box. The basic features of the SPBTLE-1S are: • Operating voltage: 1.7 V to 3.6 V • Cortex-M0 32-bit processor based • Supports both master and slave modes • 1 x UART, 1 x I2C, 1 x SPI, 14 x GPIO, 2 x multifunction timer, 10-bit ADC, watchdog and RTC, DMA controller, and SWD debug interface • AES security • Pre-programmed UART bootloader • Extended operating temperature (-40 ºC to +85 ºC) 2.2.12 STBC02AJR Li-Ion linear battery charger The STBC02AJR (STMicroelectronics) is a linear Li-Ion battery charger, providing 150 mA, 2 SPDT load switches, a smart reset/watchdog block and a protection circuit to prevent the battery from electrical damage. The device features a charger enable input to stop the charging process anytime. It is powered off automatically if a battery is not connected to the device. An external thermistor can be used to detect a battery under/over temperature condition.

● 21


H0W 2 Get Started with the Sensor Tile Box

The basic features of the STBC02AJR are: • Fast charging (up to 450 mA) • Adjustable voltage (up to 4.45 V) • Auto recharge function • Protection circuit against overcharge, over-discharge and battery overcurrent • Charge/fault status output • Low battery leakage in over-discharge and shutdown modes • Two 3 Ω SPDT load switches 2.2.13 STBB3JR 2MHz DC-DC converter The STBB3JR (STMicroelectronics) is a fixed voltage DC-DC converter that provides output voltages from 1.2V to 5.5V. The input voltage range is 1.8 V to 5.5 V, although higher voltages can be applied. The converter is based on N-channel and P-channel MOSFET switches. The basic features of the STBB3JR are: • Minimum input voltage range: 1.8 V to 5.5 V • Output voltage range (adjustable): 1.2 V to 5.5 V • Output current: 2A (with Vin = 3.6 to 5.5 V) • Output current: 800 mA (with Vin = 2 V) • High efficiency (94%) • 2 MHz switching frequency • Load disconnect during shutdown • Less than 50 μA quiescent current (<1 μA shutdown current) 2.3 Using the SensorTile.box The SensorTile.box has 3 working modes: Entry level mode, Expert level mode, and Pro level mode. The Entry level mode enables the user to discover the SensorTile.box functionalities by providing a number of pre-developed examples that can run quickly and easily by the users on their Android or iOS mobile devices. These examples do not require any programming skills. The Expert level mode enables the users to build their own relatively simple programs using a graphical wizard. Some programming background is required to use the box in this mode, although the use of C programming code is not required. The expert mode is a great educational tool for students as it allows them to view programs before using the more complicated Pro mode. The Pro level mode is the most complicated mode. Here, the user opens the processor box and connects the processor to STM32 programmers. This enables the users to configure the processor for their own applications and develop projects by writing programming code. A good programming background is required to use the box in this mode.

● 22


Chapter 2 • The SensorTile.box

2.4 Summary In this Chapter we have briefly looked at the basic features of the SenorTile.box. In the next Chapter we will be learning how to use the box in Entry level mode to run the pre-developed applications. The video apps in the following STMicroelectronics web site gives very useful information on using the SensorTile.box in all three modes, © STMicroelectronics. Used with permission:

https://www.st.com/en/evaluation-tools/steval-mksbox1v1.html

● 23


Index

Index Symbols 3-axis accelerometer 3-axis magnetometer

19 20

DFU Discrete Fourier Transform

108 72

E A About 48 Acceleration 69 accelerometer sensor 85 Altimeter/pressure sensor 20 App loaded successfully 32, 58 autoscale 28 Azure IoT 105

B Baby Crying Detector 39 Bandwidth 71 battery charger 21 BLEFOTA_BL.bin 116 block diagram 121 BLUE LED 15 Bluetooth connectivity 21 BOOT 15, 16 Bootloader 108 Broker 93, 95

C Calibration 33 clock module 122 Cloud Logging 88, 91, 92 Compass and Level 31 CONNECT TO A DEVICE 24 CREATE A NEW APP 31 CTRL_REG1 141 Custom Apps 58, 63

Enable Autoscale Erasing & Programming EXPERT VIEW

28 113 51, 54

F FFT 65 FIFO_CTRL 141 Finite State Machine 110 Free-fall 85 Frequency spectrum 65 Function node 101

G gauge node 101 gear icon 52 Generic MQTT 93 GPIO_Output 126 GREEN LED 15

H Hard-iron compensation HTS221 Human Activity Recognition Humidity sensor

82 21 40 21

I IBM Watson 88 ifconfig 98 Inclinometer 75 inertial measurement unit 19 In-Vehicle Baby Alarm 42

D DataLogExtended Data Recorder DC-DC converter Debug Deploy Device ID Device Name DFT

108, 113 35 22 99 99 106 106 72

L Link V2/V3 107 LIS2MDL 20 LIS3DHH 19 Logging the data 26 LPS22HH 20, 139 LSM6DSOX 19

â—? 185


H0W 2 Get Started with the Sensor Tile Box

M magnetic field 59 MEMS 84 MEMS sensors 15 micro-B USB connector 15 Microphone 20, 57 Mosquitto Broker 95 Motion MEMS 115 MP23ABS1 20

N NEW APP Node-RED

51 98

O Orientation 33 original firmware 116 Overwrite board 32

P Pedometer 37, 74 people-counter 62 pitch 76 PLAY 32 PLL clock 16 Plot Data 58, 84 Plot Settings 28 Plotting the data 27 Plug & Play module 14 Publisher 93 Pushbuttons 16 PWR 15, 16

Seconds to plot 28 Sensor fusion 81 Serial interface 153 SPBTLE-1S 21 square wave 65 START LOGGING 26 Start Programming 113 STATUS 142 STBB3JR 22 STBC02AJR 21 STE BLE Sensor app 24 STM32CubeIDE 120 STM32CubeProg 109 STM32L4R9ZIJ6 15 STM32 ST-LINK Utility 118 STOP LOGGING 26 Stream to Bluetooth 52, 65 STTS751 18 Subscriber 93 System clock 16

T temperature sensor threshold Time and date Topics

18 60 79 94

U UART 157 Unicleo-GUI 110 USER 15, 16

V Q quanter 84 Quaternion 43 Quickstart 88

Vibration monitor 46 Vibrometer 82 VIEW CLOUD DATA 89

W R rechargeable battery RED LED roll Rssi & Battery

14 15 76 29

S SAVE CONFIG

● 186

Wildcards wireless IoT

94 14

X X-CUBE-MEMS1 110

Y 52

Yaw

76


H0W2

Get Started with the SensorTile.box STmicroelectronics’ wireless IoT & wearable sensor development kit

Dogan Ibrahim

This book is an introduction to the SensorTile.box and includes the following: > Brief specifications of the SensorTile.box; description of how to install the STE BLE Sensor app on an iOS or Android compatible smartphone required to communicate with the box. > Operation of the SensorTile.box in Basic mode is described in detail by going through all of the pre-loaded demo apps, explaining how to run these apps through a smartphone. > An introduction to the Expert mode with many example apps developed and explained in detail enabling users to develop their own apps in this mode. Again, the STE BLE Sensor app is used on the smartphone to communicate with the SensorTile.box and to run the developed apps. > The book then describes in detail how to upload the sensor data to the cloud. This is an important topic since it allows the sensor measurements to be accessed from anywhere with an Internet connection, at any time. > Finally, Pro mode is described in detail where more experienced people can use the SensorTile.box to develop, debug, and test their own apps using the STM32 open development environment (STM32 ODE). The Chapter explains how to upload the developed firmware to the SensorTile.box using several methods. Additionally, the installation and use of the Unicleo-GUI package is described with reference to the SensorTile.box. This PC software package enables all of the SensorTile.box sensor measurements to be displayed or plotted in real time on the PC.

About the Author Prof Dr Dogan Ibrahim has BSc degree in electronic engineering, an MSc degree in automatic control engineering, and a PhD degree in digital signal processing. Dogan has worked in many industrial organizations before he returned to academic life. Prof Ibrahim is the author of over 60 technical books and over 200 technical articles on microcontrollers, microprocessors, and related fields. He is a Chartered electrical engineer and a Fellow of the Institution of Engineering Technology.

Get Started with the SensorTile.box

The SensorTile.box can be operated in three modes: Basic mode, Expert mode, and Pro mode. Basic mode is the easiest way of using the box since it is pre-loaded with demo apps and all the user has to do is choose the required apps and display or plot the measured data on a smartphone using an app called STE BLE Sensor. In Expert mode users can develop simple apps using a graphical wizard provided with the STE BLE Sensor. Pro mode is the most complex mode allowing users to develop programs and upload them to the SensorTile.box.

H0W2

‘SensorTile.box’ is a portable multi-sensor circuit board housed in a plastic box and developed by STMicroelectronics. It is equipped with a high-performance 32-bit ARM Cortex-M4 processor with DSP and FPU, and various sensor modules, such as accelerometer, gyroscope, temperature sensor, humidity sensor, atmospheric pressure sensor, microphone, and so on. SensorTile.box is ready to use with wireless IoT and Bluetooth connectivity that can easily be used with an iOS or Android compatible smart phone, regardless of the level of expertise of the users. SensorTile.box is shipped with a long-life battery and all the user has to do is connect the battery to the circuit to start using the box.

Volume 1

Dogan Ibrahim

Elektor International, Media BV www.elektor.com

1

knows how


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.