Updated date:

# ML Model and Arduino Programming for Machine Learning Typing Gloves

I am an Information Technology degree holder. I recently earned three certificates in Tiny Machine Learning.

## This Tutorial Will Teach You Programming for Machine Learning Typing Gloves

• The code that is required to get analog values from an Arduino and average them.
• The code for the ML model to get your artificial neural network trained on the data from the first tutorial.
• All so that your machine learning typing gloves will be ready to type on any hard surface.

## Sliding Into Arduino Code

1. The gloves themselves should be labeled for each hand to make them intuitive to use. I labeled mine as red and green.
2. Please keep in mind that the below code will send the analog values from the flex-sensors attached to the fingers through the Arduino's Bluetooth Silver Mate to the computer.
3. The receiving Python script built in the first tutorial will process the data coming into the computer.
4. Then store it into a comma-separated-value list. I believe there are six bytes total for each analog value.
5. The (A) signifying an analog character takes up 1 byte of memory sense chars are one byte. Then the sensor number indicator takes up four bytes, as it is an integer.
6. Then, we have lowByte to get the least significant byte from the analog value. As long as the analog values are between 1-255, this should be ok.
7. When working on the gloves, I also noticed that the analog values were spurious, so I used an averaging filter to smooth them into a more reliable value.

Math.h is needed to smooth the data in AverageFilter.

In the setup part of the Arduino program, we set the baud rate at 1,200

Average takes 16 analog values and averages them together sixteen times in total. After this, we divide by the number of analog values taken. Then, the function returns a fraction. By doing these things, it gives a more accurate representation of the final analog value.

The first printed character (A) gives some separation between the values, and the second printed number 5-9 after the initial printed value. It allows us to identify which sensor it is.

The third printed value is the actual analog value of the flex-sensor.

## Recommended for you

A0{integer value}A1{integer value}A2{integer value}A3{integer value}A4{integer value}A5{integer value}A6{integer value}A7{integer value}A8{integer value}A9{integer value}

## A Little Python

1. First, we import some required libraries into the project. Some of these were explained in the first tutorial so that we won't go over them.
2. Mainly I want to focus on the libraries TensorFlow, NumPy, and Keras. These will be used in the machine learning model.
3. Since we want to predict what key is pressed, based on the data from the gloves, some parts of the script will be similar to the pythonserialmlgloves1.1.py we made in the first tutorial. We have a dependent variable and an independent variable.
4. The X and y of the program play the role of the changing data and the results of that change, respectively.
5. The recorded keyboard key, in this case, will be the y or target value. The X will be all of the analog values that we record from our script when the key is pressed.
6. We cannot simply take the values as they are. They must undergo some normalization.
7. They may skew the final result for significant and minor values if not brought within a specific range. And as a computer cannot understand the alphabet letters, we must convert them using OneHotEncoder.

These are the layers of the neural network. We have only one input layer and one hidden layer. The number of neurons for this ANN was arbitrary and can be improved.

However, the output layer does need 28 neurons for the encoded letters of the alphabet.

Categorical_crossentropy was used because this is a classification problem.

Almost all of the following code is the same as the Python script made in the previous tutorial. But note the use of a graph at the bottom. This was used to save the state of the neural network.

## Would You Like to Know More About Making Machine Learning Typing Gloves?

If you're interested in this process, it's a great idea to check out my first in-depth tutorial on this subject, which contains further information:

How to Make Better Machine Learning Typing Gloves

This content is accurate and true to the best of the author’s knowledge and is not meant to substitute for formal and individualized advice from a qualified professional.