This repo introduces how to install the official Arduino Tensorflow Lite library into your Wio Terminal, allowing you to test out some Machine Learning models using Wio Terminal.
For more information, please visit TensorFlow Lite For Microcontrollers.
Install the Arduino TensorFlow Lite Library¶
- Navigate to
Manager Libraries...and a Library Manager will appear.
- In the Library Manager, Search the keywords Arduino TensorFlow Lite and the library will appear. Under Select Version, select the one that is NOT precompiled and click Install.
Now, we need to make a small adjustment to the library files in order for it to compile with Wio Terminal.
Navigate to the library file location. It should be something like
Once inside the Arduino_TensorFlowLite file, navigate
kissfftand open the kiss_fft.h file.
- Use a code editor to open and find the line where it includes the
<sys/types.h>header file, which look like this:
1 2 3
#ifdef FIXED_POINT #include <sys/types.h> # if (FIXED_POINT == 32)
And change it to this:
1 2 3 4 5 6
#ifdef FIXED_POINT #include <sys/types.h> #if __GNUC__ == 4 #include <stdint.h> #endif # if (FIXED_POINT == 32)
Save the changes.
Running the Arduino TensorFlow Lite Hello World Example¶
The example is designed to demonstrate the absolute basics of using TensorFlow Lite for Microcontrollers. It includes the full end-to-end workflow of training a model, converting it for use with TensorFlow Lite, and running inference on a microcontroller.
The sample is built around a model trained to replicate a sine function. It contains implementations for several platforms. In each case, the model is used to generate a pattern of data that is used to either blink LEDs or control an animation.
hello_world. The example sketch should appear.
If compiles now, there will be an compile error because the
maxfunctions defined for the board are also defined in Arduino TensorFlow Library. So to solve this, use
#undef minright before the including library to avoid error, just like this:
1 2 3
#undef max #undef min #include <TensorFlowLite.h>
Now, click on Upload and upload your first TensorFlow Lite example to Wio Terminal!
Open the Serial Plotter, and you should see a Sine waveform. Further, check the built in LED on the back, it should be fading in and out according to the Sine wave you just generated from TensorFlow Lite!
Note: if you want to see the full Sine wave on Serial Plotter(i.e. LED flickering faster), you can click on the arduino_constants.cpp file on the top, and change the
kInferencesPerCycle to 100 as follow:
const int kInferencesPerCycle = 100;