tiny machine learning LESSON 2

TOPICS INDEX

Warnings

Regarding 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 backup 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 could cause damage to the PC, to the furnishings and in extreme cases even to burns, for this reason every time a circuit is assembled, or modifications are made on it, it will be necessary to do it in power failure and at the end of the exercise it will be necessary to disconnect the circuit by removing both the USB cable for connection to the PC and any batteries from the appropriate compartments or external power connectors. Furthermore, again for safety reasons, it is strongly recommended to carry out the projects on insulating and heat resistant mats 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 swallowed 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 it. For younger children and / or for their 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

Let's practice with our new Nano BLE Sense board

Before venturing into the world of artificial intelligence, let’s see what the Arduino Nano 33 BLE Sense board is capable of.

To do this, let’s learn how to use the card from the examples made available by the Libraries we have installed.

For all the following projects we only need the Nano BLE Sense board, a PC and the connecting USB cable.

The purpose of the exercises that will follow is to discover in detail the use of the Libraries and therefore the operation of the sensors on the Arduino Nano 33 BLE Sense board. It should be noted that the board itself already has most of the sensors useful for robotic design, so discovering them in detail, seeing how they work, understanding their limits, favors us in the use of the board itself.

APDS 9960 - Digital Proximity Sensor, RGB Light and Gestures

[Technical information extracted and summarized from datasheet AVAGO Technologies]

The operation of the digital Proximity, RGB Light and Gestures sensor commercially known as APDS 9960 is very simple.

As you can see from the photo above, the sensor is composed of an Infrared Light (IR) emitting unit and four very sensitive receiving photodiodes, arranged in a cross:

The emitting unit emits infrared light which is then reflected by the 4 photodiodes.

Proximity detection

For proximity detection the sensor works in this way: the IR emitter LED emits infrared light, which, reflected by the body that is near the sensor, is captured by the photodiodes which also calculate the distance. Obviously, the sensor makes measurements in different ways, so the result it returns is a value that also takes into account any disturbances introduced by the sensor itself.

Proximity is expressed through a numerical value which decreases, starting from a value of 255, when nothing is detected, to 0, when essentially the sensor is almost in contact with the body.

Gesture detection

The emitter LED emits infrared light, the four cross-positioned photodiodes intercept the reflected IR light in a different way and therefore are able to establish the direction of the gesture.

Direction from DOWN to UP, or from RIGHT to LEFT and obviously also the opposite directions

Color detection

For color detection, the operating principle is very similar to the previous ones, depending on the reflected infrared values, the sensor is able to establish the quantity of Red, Green or Blue color that makes up the reflected light. The sensor returns a value between 0 and 255 for each component of R (red), G (green) and B (blue) of the light read.

At this point, including the operation in our sensor mounted on the Arduino Nano 33 BLE Sense, let’s see its practical applications with simple projects.

PAI-001: Color Detection

The sketch to use for this project is:

Once the sketch has been loaded, as described above, open the Serial Monitor and test by passing the sensor over colored surfaces, it will be observed that the majority color is identified and then the numerical values of the components R (red), G (gree) and B (blue).

Analysis of the sketch of the AI-001 Project - Color Detection

As you can see from the sketch, the use of the Arduino_APDS9960.h Library is very simple. Once the library is called with “include”, three “int” variables must be declared, then with the APDS.readColor (r, g, b) statement;

Once the values read by the sensor in the three variables have been loaded, by means of the “if”, I make the comparisons and establish the majority color, after which the results are printed on the serial monitor.

PAI-002: Gesture Detection

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, as described above, open the Serial Monitor and test by passing your hand over the sensor, first from bottom to top and then from left to right and so on:

Analysis of the sketch of the AI-002 Project - Gesture Detection

As you can see from the sketch, also in this case the use of the Arduino_APDS9960.h Library simplifies the sketch a lot. In fact, once the library has been called with “include”, just use the function int gesture = APDS.readGesture (); with its switch… case… which automatically returns the detected “gesture” to us.

It is also possible to change the gesture detection sensitivity, by default the value is 80, but with the instruction APDS.setGestureSensitivity (80); it is possible to change this value with a value between 1 and 100. The higher the value, the greater the detection sensitivity, but consequently the error of detecting false gestures is also greater. Personally, I was happy with the default value so I recommend not changing it.

PAI-003: Proximity Detection

By appropriately modifying the sketch made available by the library example, upload the following code on the board:

By opening the serial monitor it is possible to view the proximity value assigned by the sensor to the moving body detected by the same sensor.

I also tried to integrate the code by also attributing a qualitative evaluation, obviously the code is still optimizable, I leave this exercise to you.

The value 0 means, very close body, the value 255, far body.

Analysis of the sketch of the AI-003 Project - Proximity Detection

As you can see from the sketch, also in this case the use of the Arduino_APDS9960.h Library simplifies the sketch a lot. In fact, once the library is called, just use the function int proximity = APDS.readProximity (); to have proximity reading and then use it for your own projects.

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