Git Product home page Git Product logo

saddamos91 / tinyml-on-the-edge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from saddamos1/tinyml-on-the-edge

0.0 1.0 0.0 1.04 MB

IMU sensors on Arduino Nano 33 BLE Sense can be used in gesture recognition. Using machine learning, a model is trained using the data collected from the IMU sensors on Google Colaboratory. A tensorflow lite model is encoded in arduino header which a classifier sketch uses. They include; accelerometer , gyroscope and magnetometer.

License: GNU General Public License v3.0

C 81.32% C++ 0.22% Jupyter Notebook 18.46%

tinyml-on-the-edge's Introduction

Tinyml-on-the-edge

Arduino Nano 33 BLE Sense can be used to recognize gestures using machine learning. A tensorflow model is designed, built and trained using accelerometer and gyroscope sensors data on Google Colaboratory, which can handle jupyter notebooks online. The model is converted to tensorflow-lite model and later encoded on Arduino Nano 33 BLE Sense header file. A a gesture classifier uses the model to classify the data from both sensor types. IMU has numerous sensors including accelerometer, gyroscope and magnetometer. In this project, we are going to use accelerometer and gyroscope data to predict punch and flex gesture. This is based on arduino tutorials.

This project will follow the following procedure.

  1. Revisit setting up arduino IDE without going through the programming part of sensor data collection.
  2. Look into accelerometer and gyroscope operation
  3. Write a sketch to collect accelerometer and gyroscope data
  4. Upload the data to the google colaboratory platform
  5. Train a neural network
  6. Convert the trained model into tensorflow lite model
  7. Encode the model in arduino header file

Accelerometer and gyroscope operation.

IMU sensor on the Arduino Nano 33 BLE Sense has three sensors; accelerometer, gyroscope and magretometer. These sensors measure forces acting on the body. They give acceleration and rotation information on the x, y and Z.

Many accelerometers and gyroscopes are fabricated using micro-electromechanical systems (MEMS). The production process for the MEMS sensor combines silicon and mechanical functions on the same micrometer silicon substrate. The major components in these devices are the mechanical elements, the sensing mechanism and the application specific integrated circuit (ASIC) as explained in digi-key.

Application

  • Mobile Smart Phones
  • Drones
  • Aeroplanes
  • Mobile IoT Devices
  • Anti-theft/Asset Tracking/Security Devices

Operation

Accelerometer

In IMU 3d accelerometer sensor, the sensing mechanism for all three accelerometers is capacitive. The accelerometer measures linear acceleration along the x, y, and z axis. It has three sensors. The three sensors are mounted orthogonally.

photo 1

Gyroscope

The gyroscpe measures the rate of change of angular velocity over time (angular changes). Many of these sensors are also manufactured using MEMS. Gyroscope also relies on the varying capacitance between silicon and mechanical elements, but with this configuration, the sensor generates capacitive changes with angular velocity changes. A 3D gyroscope also has 3 gyroscopic sensors mounted orthogonally to each other.

photo 2

Accelerometer and gyrometer sensors face position and angular errors respectively, but fussion process in which they are made and manufactured, aims at perfecting on each other errors thus accuracy is reached.

Collect accelerometer and gyroscope sensor data

To capture the accelerometer and gyroscope data, A sketch is written on arduino IDE and uploaded to the board, or go to arduinoTensorFlowLite Tutorials for the skethes. The sketch in this repository is labelled nano-33-gesture. Set up Arduino IDE. It helps both in uploading inference models to Arduino Nano 33 BLE Sense as well as download training data from it in .csv format. Incase you haven't installed and configured your arduiono desktop IDE, please check the repository on installing Arduino desktop IDE or use the arduino web IDE.

Plug the Arduino Nano 33 BLE Sense board to the computer, select the board type and the port. Arduino boards run small applications (also called sketches) which are compiled from .ino format Arduino source code, and programmed onto the board using the Arduino IDE or Arduino Create. Its time to collect the training data.

Visualize collected data.

On Arduino desktop IDE open Files, click New and save the sketch as nan0-data-collect.ino. There is a filter that performs signal preprocessing and filtering on the device before the data is output to the log. The skech does the following;

  1. Detect motion using accelerometer and gyroscope
  2. Trigger a sample window on detecting significant linear acceleration of the board
  3. Sample the data every second at a frequency of 119Hz
  4. Format a CSV data output via serial port

When the scketch is ready, save. Go to Sketch, and click Upload. The sketch will indicate Done uploading. Turn to Tools. and click Serial Monitor to see the accelerometer and gyroscope data. You can as well plot on serial plot. However, our main objective is to have our data output in .csv formated document to be used in model training later on.

photo 3 photo 4

Make sure at the top of the serial monitor you have aX,aY,aZ,gX,gY,gZ. With the Arduino Nano 33 BLE Sense in your hand, make a fist to signify a punch. Stretch the hand with the punch pointing the computer or other direction you choose for consistency. Make 20 punches. On the Serial monitor, uncheck Autoscrol button and copy the data. Save the data on your pc as punch.csv. Flex your hand from the screen or the direction you chose towards your body 20 times too while checking Serial Monitor and copy the data again, but this time save as flex.csv on your PC.

Google colaboratory data upload

Open google Colaboratory platorm, Move to Files. Drag and drop your punch.csv and flex.csv files in the sample_data folder. The Google colaboratory provides a Jupyter notebook that allows us to run our TensorFlow training in a web browser.

photo 3

photo 4

Train neural network, build and train a model

While on the Google colaboratory platform, go trough the notebook till the end. Convertion of the trained model into tensorflow lite model is done near the end. When the model.h file is created under Files, click on the model.h file to download to your pc. If you open the model.h file, it will look like the one below.

photo 5

Encode the model in arduino header file

Open accelerometer and gyroscope clasifier sketch on this repository named as nano-classifier.ino. It was created by Don Coleman, Sandeep Mistry and modified by Dominic Pajak, Sandeep Mistry. On the far top right, click on the drop down button and click New Tab. Name the file as model.h when you save it. Open the downloaded model.h file on your favourite editor and copy the content. Paste in your new model.h file you created alongside the classifier sketch and save. Upload the sketch and turn to Serial Monitor on on Tools to view result. The confidence of each gesture will be printed to the Serial Monitor showing (0 = low confidence, 1 = high confidence)

photo 6 photo 7

Thank you.

tinyml-on-the-edge's People

Contributors

jaredmaks avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.