TINY MACHINE LEARNING LESSON 4

TOPICS INDEX

Warnings

With regard to the safety aspects, since the projects are based on a very low voltage power supply supplied by the USB port of the PC or by support batteries or power supplies with a maximum of 9V output, there are no particular risks of an electrical nature. It is however necessary to specify that any short circuits caused during the exercise phase could produce damage to the PC, to the furnishings and in extreme cases even to burns, for this reason every time a circuit is assembled, or changes are made on it, it will be necessary to do so in the absence of power and at the end of the exercise it will be necessary to provide for the disconnection of the circuit by removing both the USB cable connecting to the PC and any batteries from the appropriate compartments or  external power connectors.  In addition, always for safety reasons, it is strongly recommended to carry out projects on insulating and heat-resistant carpets that can be purchased in any electronics store or even on specialized websites.

At the end of the exercises it is advisable to wash your hands, as the electronic components could have processing residues that could cause damage if ingested or if in contact with eyes, mouth, skin, etc. Although the individual projects have been tested and safe, those who decide to follow what is reported in this document, assume full responsibility for what could happen in the execution of the exercises provided for in the same. For younger children and / or the first experiences in the field of Electronics, it is advisable to perform the exercises with the help and in the presence of an adult.

Roberto Francavilla

Inertia and the IMU Sensor - LSM9DS1

To better understand the function of the LSM9DS1  Sensor on the  Arduino Nano 33 BLE Sense board, it is appropriate to give some basic notions of Physics.

Let’s start with the definition of inertia; in Physics,  “inertia” is defined as the tendency of a body to maintain its state of stillness or uniform motion.

Let’s see better what “state of stillness” means  for a body;  the state of stillness is when all the forces acting on the body are balanced, whereby the resulting force is nothing. In this case the body remains stationary even if different forces act on it. An example is a ball placed in the circle of the entrance of the field. Only the weight force P acts on it  , which is balanced by the reaction force R of the football field.

The ball will remain motionless as long as someone does not give it a force that is transferred to the ball with an acceleration.

The same applies to a body that “moves with uniform motion”, simplifying the model appropriately, suppose we have a locomotive that travels on straight tracks:

The weight force of the locomotive P is balanced by the reaction of the rails R, the Friction Force Fa of the air and balanced by the thrust (or pull) force Fs of the locomotive engine. The system is thus balanced and the locomotive travels at a constant speed, so it moves in uniform motion.

The question is: what if in one of the examples seen above an additional force is applied to those present? The answer is simple, the system unbalances and the body undergoes an acceleration, so the ball will move and the locomotive will undergo an acceleration.

Acceleration in Physics is defined as the change in speed over time and is measured, unlike the speed that is measured in “m/s” (meters per second),  in “m/s2” (meters per second picture).

The IMU sensor (“IMU” is an acronym that means Inertial Measurement Unit  ) of the company ST, whose model name is called LSM9DS1 [for the datasheet click here]  is a sensor capable of measuring these accelerations. The accelerations that the ST sensor can measure are not only along the Cartesian axes, but are also gyroscopic, or angular accelerations around the same Cartesian axes and also manages to measure magnetic fields along the same Cartesian axes.

Let’s see exactly how much the LSM9DS1 sensor measures:

Measurement of acceleration along the three Cartesian axes – Accelerometer; the sensor returns a value in “g”, or in “acceleration of gravity”. Knowing that 1 g = 9.8 m/s2 it is possible to convert the value from “g” into values referring to the International System i.e. m/s2

Measurement of the angular velocity on the three Cartesian axes – Gyroscope; the sensor returns the value in “dps”, or “degrees per second”, that is, in “gradi/s”. Again, knowing that 180° = 3.14 rad, it is possible to convert the value from “gradi/s” to “rad/s” (radians per second).

Measurement of the magnetic induction field along the three Cartesian axes – Magnetometer; The sensor returns a value in “G” (gauss), that is, it measures the density of the magnetic flux. Knowing that 1 gauss = 1×10−4 T where “T” stands for “Tesla” which is the unit of measurement of the magnetic induction field (B) in the International System, you can easily make the conversion.

This sensor is also called a 9 DOF (DOF stands for Degree Of Freedom – that is Grado of Libertà), in fact if you add up the possible measurements, you can easily guess why the name:

  • 3 degrees of freedom (movements along the x, y and z axes) for the accelerometer
  • 3 degrees of freedom (rotations on the x, y and z axes) for the gyroscope
  • 3 degrees of freedom (magnetic fields along the x, y and z axes) for the magnetometer.

from which 3+3+3 =9 degrees of freedom.

Let’s see, in practice, the operation of this sensor.

For all the projects that follow we only need the Nano BLE Sense card, a PC and the USB connection cable.

PAI-007: Measure acceleration along Cartesian axes with LSM9DS1

The sketch to be used for this project is the one shown below, it was obtained directly from the sample sketch in the library (apart from some small changes made by me):

Once the sketch has been loaded, as described above and the port to which the board is connected has been changed, open the  Serial Plotter and the readings made in the form of graphs will be shown…  it is easy to understand the variation along the three axes represented with three different colors.

However, the video of the project shows everything in detail.

Analysis of Project AI-007 - Measure x, y, and z acceleration with LSM9DS1

For this sensor you need to use the Arduino_LSM9DS1.h Library, and you need to call it with the classic syntax:

#include

As you can see from the sketch, you must first define the three variables that will host the values returned by the sensor:

float x, y, z;

the readings from the sensor are made using the function:

IMU.readAcceleration(x, y, z);

The three return values are float and represent the acceleration along the three axes expressed in g.  So if you want to get the values expressed in m/s2, you have to divide the value obtained by 9.8.

PAI-008: Measure angular velocity with LSM9DS1

Also for this project we will use, modifying it appropriately, the sketch made available by the example of the library.

The sketch to use for this project is:

Once the sketch has been loaded and the port to which the Nano BLE Sense is connected has been changed, open the  Serial Plotter and you will be shown  the sensor readings in graphic form  .

However, the video of the project shows everything in detail.

Analysis of Project AI-008 - Measure Angular Velocity with LSM9DS1

As you can see from the sketch, also in this case the use of the <Arduino_LSM9DS1.h  Library > greatly simplifies the sketch.  In fact, once the library is invoked with “include”, just define the three variables that will host the values returned by the sensor:

float x, y, z;

the readings from the sensor are made using the function:

IMU.readGyroscope(x, y, z);

The three values returned are float and represent the angular velocity along the three axes expressed in dps, that is, degrees per second, or rather degrees/sec.  If you want to get the values expressed in rad/s, you have to multiply the value of the sensor by 3.14 and divide it by 180.

PAI-009: Magnetic Field Measurement on Cartesian Axes with LSM9DS1

The LSM9DS1 sensor  is also capable of measuring the Magnetic Field (B) along the three Cartesian axes. This allows us to identify the magnetic North Pole and then also give us indications in which direction the accelerations and rotations detected with the accelerometer and  gyroscope functions of the same sensor are.

To show the functionality also in this case the sketch present in the examples of the library was used.

Once the sketch is loaded and the communication port between the PC and the board has been changed, passing from the writing to the reading port, it is possible to open the  serial plotter that shows us the read values in the form of a graph. In the video project I used a magnet to better show  the variation of the letti values  on the axes.

Analysis of the AI-009 Project – 3D Magnetic Field Measurement with LSM9DS1

Also in this case, the library helps us a lot in immediately receiving the values expressed in G that is in gauss.

Define the three variables that will host the values returned by the sensor:

float x, y, z;

the readings from the sensor are made using the function:

IMU.readMagneticField(x, y, z);

To have the Tesla (unit of measurement in the S.I. of the Magnetic Induction Field B) it is necessary to multiply by 10-4.

If you found the lesson interesting, make a donation you will help me realize many others.