#  TensorFlow Lite for EdgeBadge Quickstart

## Overview

https://www.youtube.com/watch?v=cn9PEDX_qLk

Machine learning has come to the 'edge' - small microcontrollers that can run a very miniature version of TensorFlow Lite to do ML computations.&nbsp;

But you don't need super complex hardware to start developing your own TensorFlow models! We've curated a simple kit to dip your toes into machine learning waters.

**Kit includes:**

- [Adafruit PyBadge with SAMD51 Cortex M4F processor @ 120MHz, with display, speaker and buttons](https://www.adafruit.com/product/4200)
- [Electret Microphone Amplifier - MAX4466 with Adjustable Gain](https://www.adafruit.com/product/1063)
- [JST PH 3-Pin to Female Socket Cable - 200mm](https://www.adafruit.com/product/3894)
- [Lithium Ion Polymer Battery with Short Cable - 3.7V 350mAh](https://www.adafruit.com/product/4237)

The kit uses our PyBadge as your edge processor. It's a compact board - it's credit card sized. It's powered by our favorite chip, the ATSAMD51, with 512KB of flash and 192KB of RAM. We add 2 MB of QSPI flash for file storage, handy for TensorFlow Lite files, images, fonts, sounds, or other assets.

You can plug in a microphone into the ports at the bottom, to add microphone input for micro speech recognition. Our Arduino library has some demos you can get started with to recognize various word pairs like "yes/no", "up/down" and "cat/dog". **TensorFlow Lite for microcontrollers is very cutting-edge so expect to see a lot of development happening in this area, with lots of code and process changes.**

# Parts required

You can get everything you need minus tools in this kit:

### TensorFlow Lite for Microcontrollers Kit

[TensorFlow Lite for Microcontrollers Kit](https://www.adafruit.com/product/4317)
Machine learning has come to the 'edge' - small microcontrollers that can run a very miniature version of TensorFlow Lite to do ML computations.&nbsp;

But you don't need super complex hardware to start developing your own TensorFlow models! We've curated a simple kit to...

In Stock
[Buy Now](https://www.adafruit.com/product/4317)
[Related Guides to the Product](https://learn.adafruit.com/products/4317/guides)
![Female holding an a assembled TensorFlow Lite for Microcontrollers Kit.](https://cdn-shop.adafruit.com/640x480/4317-02.jpg)

Or as individual parts:

### Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino

[Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino](https://www.adafruit.com/product/4200)
What's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino? That's right, its the **Adafruit PyBadge!** We wanted to see how much we could cram into a ​3 3⁄8 × ​2 1⁄8 inch rounded rectangle, to make an all-in-one dev board with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4200)
[Related Guides to the Product](https://learn.adafruit.com/products/4200/guides)
![Angled shot of a Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino. ](https://cdn-shop.adafruit.com/640x480/4200-01.jpg)

### STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm

[STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm](https://www.adafruit.com/product/3894)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with high-quality 0.1" female header sockets on the end. We're carrying these to match up with our Hallowing, for extending and connecting sensors or LEDs - and the wires are even color coded!

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3894)
[Related Guides to the Product](https://learn.adafruit.com/products/3894/guides)
![Angled shot of STEMMA JST PH 3-Pin to Female Header Cable - 200mm.](https://cdn-shop.adafruit.com/640x480/3894-03.jpg)

### Electret Microphone Amplifier - MAX4466 with Adjustable Gain

[Electret Microphone Amplifier - MAX4466 with Adjustable Gain](https://www.adafruit.com/product/1063)
Add an ear to your project with this well-designed electret microphone amplifier. This fully assembled and tested board comes with a 20-20KHz electret microphone soldered on. For the amplification, we use the Maxim MAX4466, an op-amp specifically designed for this delicate task! The amplifier...

In Stock
[Buy Now](https://www.adafruit.com/product/1063)
[Related Guides to the Product](https://learn.adafruit.com/products/1063/guides)
![Angled shot of electret microphone breakout board.](https://cdn-shop.adafruit.com/640x480/1063-06.jpg)

### Lithium Ion Polymer Battery with Short Cable - 3.7V 420mAh

[Lithium Ion Polymer Battery with Short Cable - 3.7V 420mAh](https://www.adafruit.com/product/4236)
Lithium-ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light, and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery has a capacity of 420mAh for a total of about 1.55 Wh. If you need a larger (or smaller!) battery, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4236)
[Related Guides to the Product](https://learn.adafruit.com/products/4236/guides)
![Lithium Ion Polymer Battery 3.7v 420mAh with JST 2-PH connector and short cable](https://cdn-shop.adafruit.com/640x480/4236-04.jpg)

#  TensorFlow Lite for EdgeBadge Quickstart

## Setup For Compiling Examples

We're going to be using the popular Arduino IDE to compile and load code. Start by following the PyBadge setup guide to

1. [Install the latest desktop Arduino IDE](https://learn.adafruit.com/adafruit-pybadge/setup)
2. [Install Adafruit SAMD board support package](https://learn.adafruit.com/adafruit-pybadge/using-with-arduino-ide) (If programming a SAMD board like the Edge/PyBadge)
3. [Install Adafruit nRF52 board support package](https://learn.adafruit.com/adafruit-circuit-playground-bluefruit/arduino-support-setup) (If programming an nRF52 board like the Circuit Playground Bluefruit)
4. [Install all the Arcada Libraries (yes there's a lot of them!)](https://learn.adafruit.com/adafruit-pybadge/arcada-libraries)

# TensorFlow Libraries

Now install the `Arduino TensorFlow library 1.15.0-ALPHA` with the library manager

Make sure you **don't pick the _pre-compiled_ release version**

**If you see 'precompiled' in the name, install the non-precompiled version from the dropdown**

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/084/237/medium800/adafruit_products_image.png?1573778823)

 **&nbsp;** Next, install **Adafruit TensorFlow Lite**

![](https://cdn-learn.adafruit.com/assets/assets/000/084/196/medium800/adafruit_products_image.png?1573771859)

And finally, for the speech demos, grab the Adafruit **Zero PDM** library

![](https://cdn-learn.adafruit.com/assets/assets/000/084/380/medium800/adafruit_products_image.png?1573943273)

# Select Board

Almost ready! Before we're ready to compile some examples!

Plug in the board into your computer with a known-good data/sync cable. Select the right board in the Tools download

## For PyBadge/EdgeBadge
![](https://cdn-learn.adafruit.com/assets/assets/000/084/197/medium800/adafruit_products_image.png?1573772178)

For some examples you will want to set&nbsp; **Optimize** to **Fastest** &nbsp; and set **CPU Speed** to 180MHz (overclocking). This will give 6-10x speedup. For the first few examples, it isn't necessary. Make sure to select **USB Stack: TinyUSB**

## For Circuit Playground Bluefruit

You can use the default settings:

![](https://cdn-learn.adafruit.com/assets/assets/000/085/625/medium800/adafruit_products_image.png?1575942568)

#  TensorFlow Lite for EdgeBadge Quickstart

## Sine Wave Demo

https://www.youtube.com/watch?v=59rfuaKEu1M

This is the "hello world" demo of TensorFlow Lite. It has a simple model that has been trained to generate a sine wave when a linear input is given. It's a good way to verify you have a working toolchain!

If you want to load demo this immediately to your PyBadge/EdgeBadge, here is the UF2 files which you can 'drag-n-drop' onto your **BOOT** diskdrive to load the example ([follow the instructions here on how to load UF2 files if you've never done it before](https://learn.adafruit.com/tensorflow-lite-for-microcontrollers-kit-quickstart/tron-demo#enter-bootloader-mode-6-2))

[pybadge/edgebadge Sinewave.UF2](https://cdn-learn.adafruit.com/assets/assets/000/083/188/original/pybadge_arcada_sinewave.UF2?1572324514)
# Serial plotter sine wave demo compile & upload

Let's start with the plain Arduino TensorFlow demo. **Don't forget you have to perform all the steps in the previous page for installing Arduino IDE, Adafruit SAMD support, libraries, and board/port selection!**

![](https://cdn-learn.adafruit.com/assets/assets/000/083/178/medium800/adafruit_products_image.png?1572322596)

Compile & upload this example!

![](https://cdn-learn.adafruit.com/assets/assets/000/083/179/medium800/adafruit_products_image.png?1572322632)

Upon success, you may see the LED on the board pulsing. The best way to see the output is to select the **Serial Plotter**

![](https://cdn-learn.adafruit.com/assets/assets/000/083/180/medium800/adafruit_products_image.png?1572322716)

You'll see a sine wave on the plotter!

![](https://cdn-learn.adafruit.com/assets/assets/000/083/181/medium800/adafruit_products_image.png?1572322751)

If you want to see a more sinusoidal output go to **arduino\_constants.cpp**

and change

`const int kInferencesPerCycle = 1000;`

to

`const int kInferencesPerCycle = 100;`

Then re-upload

![](https://cdn-learn.adafruit.com/assets/assets/000/083/182/medium800/adafruit_products_image.png?1572322825)

# Arcada display output sine demo compile & upload

Arcada is our library for handling displays and input - we have so many different boards and displays, we need a unifying library that would handle displays, filesystems, buttons, etc. For many boards, you don't need to do anything special to figure out the pinouts or part numbers!

Load up the **Adafruit\_TFLite-\>hello\_world\_arcada example**

![](https://cdn-learn.adafruit.com/assets/assets/000/083/183/medium800/adafruit_products_image.png?1572323049)

You can upload this sketch to your board and you'll get an animated ball on the screen.

![](https://cdn-learn.adafruit.com/assets/assets/000/083/185/medium800thumb/adafruit_products_final_5db7bfce87d36a001309f9cd_49225.jpg?1572323307)

The majority of the work is in this file that initializes the display on the first inference, then draws a ball (while erasing the last location) on every successful inference.

https://github.com/adafruit/Adafruit_TFLite/blob/master/examples/hello_world_arcada/arduino_output_handler.cpp

#  TensorFlow Lite for EdgeBadge Quickstart

## Customized Wave Demo

The sine wave demo is great to do initial experimentation with training new simple single input-\>output models.

Google TensorFlow has a great guide here

[TensorFlow Lite Microcontroller Build/Convert Guide](https://www.tensorflow.org/lite/microcontrollers/build_convert)
The detailed part of the tutorial is in this colab script. Colab is great because its fully hosted, runs in any web-browser without using your CPU to do the training!

# Re-creating the Default Sine Wave Model

Visit the colab script here:

[create_sine_model.ipynb](https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/hello_world/train/train_hello_world_model.ipynb)
And **run all** the script!

![adafruit_products_image.png](https://cdn-learn.adafruit.com/assets/assets/000/084/367/medium640/adafruit_products_image.png?1574137033)

It may take a few minutes. When its complete you'll get an array of data at the bottom:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/368/medium800/adafruit_products_image.png?1573854906)

Grab that text starting with

`unsigned char sine_model_quantized_tflite[] = {`

and ending with

`unsigned int sine_model_quantized_tflite_len = 2640;`

(the number may vary)

```python
unsigned char sine_model_quantized_tflite[] = {
  0x18, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x0e, 0x00,
  0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00,
  0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x00, 0x00,
  0xb8, 0x05, 0x00, 0x00, 0xa0, 0x05, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  ....more here....
  0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00,
  0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00
};
unsigned int sine_model_quantized_tflite_len = 2640;
```

Now visit the **hello\_world\_arcada** sketch and fine the **sine\_model\_data** tab:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/369/medium800/adafruit_products_image.png?1573856205)

And paste that output from the notebook, replacing the

`unsigned char sine_model_quantized_tflite[] = {`

down to

`const int g_sine_model_data_len = 2640;`

![](https://cdn-learn.adafruit.com/assets/assets/000/084/503/medium800/adafruit_products_image.png?1574055115)

![](https://cdn-learn.adafruit.com/assets/assets/000/084/504/medium800/adafruit_products_image.png?1574055187)

Danger: 

Recompile and upload to your badge or Circuit Playground Bluefruit, you should get the exact same sine wave demo!

![](https://cdn-learn.adafruit.com/assets/assets/000/084/599/medium800thumb/adafruit_products_Machine_Learning_Monday_-_Adding_TFLite_File_Loading_support.jpg?1574136122)

OK maybe not so exciting. Lets try changing the model.

# Creating a Cosine Wave Model

Let's get _wild and crazy_ now, by making a cosine wave model. Find the line in the script where we create the `y_values` from the `x_values`

![](https://cdn-learn.adafruit.com/assets/assets/000/084/505/medium800/adafruit_products_image.png?1574055375)

And change it to a **cos** function!

![](https://cdn-learn.adafruit.com/assets/assets/000/084/507/medium800/adafruit_products_image.png?1574055408)

Run the colab script from this point down (or the whole thing) to get a brand new `unsigned char sine_model_quantized_tflite` array&nbsp; and follow the steps you did before to replace the model array in the **hello\_world** sketch with your new model. Re-upload to now get cosine wave output, which looks like the plot above

![](https://cdn-learn.adafruit.com/assets/assets/000/084/600/medium800thumb/adafruit_products_Machine_Learning_Monday_-_Adding_TFLite_File_Loading_support.jpg?1574136248)

# Loading Models From Internal Storage

The PyBadge/EdgeBadge/Circuit Playground Bluefruit have 2MB of internal storage. We can use that to store TensorFlow models, so that we don't have to go through the recompilation step above. Instead, the model is loaded from that storage flash, we can read/write to the flash over USB by dragging-and-dropping, just like a USB key!

Upload the **hello\_world\_arcada** sketch. If you have a PyBadge/EdgeBadge, this time make sure to select **TinyUSB** as the USB stack since that will activate mass storage support. You don't have to specifically select TinyUSB for nRF52 (e.g. Circuit Playground Bluefruit)

![adafruit_products_image.png](https://cdn-learn.adafruit.com/assets/assets/000/084/597/medium640/adafruit_products_image.png?1574136611)

Now when you upload, on reset you'll get a new disk drive appearing on your computer, it'll probably be name CIRCUITPY but you can rename it if you like.

![adafruit_products_image.png](https://cdn-learn.adafruit.com/assets/assets/000/084/598/medium640/adafruit_products_image.png?1574136591)

Download this models zip file and drag the two .tflite files to CIRCUITPY

![adafruit_products_image.png](https://cdn-learn.adafruit.com/assets/assets/000/084/602/medium640/adafruit_products_image.png?1574136644)

[sin_and_cos_models.zip](https://cdn-learn.adafruit.com/assets/assets/000/084/601/original/sin_and_cos_models.zip?1574136361)
Rename one of the files to **model.tflite** - when this file is available to read, this will tell our sketch to load the model from disk instead of from memory!

Once you've renamed the file, click the **reset** button, you should get an alert like this:

Once you've renamed the file, click the **reset** button, you should get an alert like this. Press the **A** button on the badge or Circuit Playground Bluefruit (its the left button) to begin the model inference run.

![adafruit_products_image.png](https://cdn-learn.adafruit.com/assets/assets/000/084/603/medium640/adafruit_products_image.png?1574136535)

Once you've proved that you're running one of the files, try renaming the _other_ model file to **model.tflite** and reset. That way you can prove that its running from the disk.

https://www.youtube.com/watch?v=1zuT8Q6Zx3g

You can go back to the colab script you ran, and look in the **Files** tab to find the `sine_model_quantized.tflite` file that is converted in the last stage. You can download that file directly.

Try creating new **tflite** files that model different functions!

![adafruit_products_image.png](https://cdn-learn.adafruit.com/assets/assets/000/084/604/medium640/adafruit_products_image.png?1574136917)

#  TensorFlow Lite for EdgeBadge Quickstart

## Gesture Demo

https://www.youtube.com/watch?v=MG6rgUuA_o4

The PyBadge has a built-in accelerometer (LIS3DH) which you can use to detect tilt and motion. The accelerometer outputs 3 axes of acceleration data, and we can use that to train and infer gestures using TensorFlow!

If you want to load demo this immediately to your PyBadge, here is a UF2 file, which you can 'drag-n-drop' onto your BADGEBOOT diskdrive to load the example ([follow the instructions here on how to load UF2 files if you've never done it before](https://learn.adafruit.com/tensorflow-lite-for-microcontrollers-kit-quickstart/tron-demo#enter-bootloader-mode-6-2))

[Badge_Gestures.UF2](https://cdn-learn.adafruit.com/assets/assets/000/084/240/original/Badge_Gestures.UF2?1573782063)
# Serial out gesture demo compile & upload

Let's start with the plain Arduino TensorFlow demo. **Don't forget you have to perform all the steps in the previous page for installing Arduino IDE, Adafruit SAMD support, libraries, and board/port selection!**

We adapted the default gesture demo to use the LIS3DH, so you _cannot_ use the example in the Arduino TensorFlowLite library Instead, use the one in `Adafruit TensorFlow Lite` called `magic_wand`

![](https://cdn-learn.adafruit.com/assets/assets/000/084/202/medium800/adafruit_products_image.png?1573772891)

Compile & upload this example!

![](https://cdn-learn.adafruit.com/assets/assets/000/084/203/medium800/adafruit_products_image.png?1573772991)

Upon success, you may see the LED on the board pulsing. The best way to see the output is to select the **Serial Monitor**

![](https://cdn-learn.adafruit.com/assets/assets/000/084/206/medium800/adafruit_products_image.png?1573773154)

You'll see steaming data coming out on the Serial Monitor. This is the 3 axis accelerometer data. We output it so that you can have some more debugging data which can be really handy when training/debugging gestures. You can also plot it with the Serial Plotter if you like (close the Monitor first)

Move and twist the badge to see the red/green/blue lines change.

![](https://cdn-learn.adafruit.com/assets/assets/000/084/207/medium800/adafruit_products_image.png?1573773250)

Close the Plotter and re-open the monitor to see the streaming data again. This time, with the **screen facing you, and the USB port pointing to the ceiling** perform one of three gestures:

## Wing

This gesture is a **W** starting at your top left, going down, up, down up to your top right

When that gesture is detected you'lll see the front NeoPixels turn yellow, and the following print out on the Serial Monitor:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/208/medium800/adafruit_products_image.png?1573773544)

## Ring

This gesture is a **O** starting at top center, then moving clockwise in a circle to the right, then down, then left and back to when you started in the top center

When that gesture is detected you'll see the front NeoPixels turn purple, and the following print out on the Serial Monitor:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/209/medium800/adafruit_products_image.png?1573774447)

## Slope

This gesture is an **_L_** starting at your top right, moving diagonally to your bottom left, then straight across to bottom right.

When that gesture is detected you'll see the front NeoPixels turn light blue, and the following print out on the Serial Monitor:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/212/medium800/adafruit_products_image.png?1573774596)

# Arcada display output gesture demo compile & upload

Arcada is our library for handling displays and input - we have so many different boards and displays, we need a unifying library that would handle displays, filesystems, buttons, etc. For many boards, you don't need to do anything special to figure out the pinouts or part numbers!

Load up the **Adafruit\_TFLite-\>magic\_wand\_arcada example**

![](https://cdn-learn.adafruit.com/assets/assets/000/084/213/medium800/adafruit_products_image.png?1573774679)

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/084/216/medium800/adafruit_products_image.png?1573774842)

You can upload this sketch to your board. After upload it will show up on your computer as a disk drive called CIRCUITPY (unless you changed it)

![](https://cdn-learn.adafruit.com/assets/assets/000/084/218/medium800/adafruit_products_image.png?1573775268)

Click this button to download the gesture images and audio clips

[Badge Gesture Images](https://github.com/adafruit/Adafruit_TFLite/tree/master/examples/magic_wand_arcada/badge_files)
Navigate through the zip file to `examples\magic_wand_arcada\badge_files` then drag the files directly onto the **CIRCUITPY** drive like so:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/241/medium800/adafruit_products_image.png?1573782313)

Click **reset** on the Badge to restart, and you should get the graphics displaying so that you can run the demo untethered!

![](https://cdn-learn.adafruit.com/assets/assets/000/084/219/medium800thumb/adafruit_products_badge.jpg?1573775335)

Setup and configuration of the accelerometer and screen is done in the **accelerometer\_handler**

https://github.com/adafruit/Adafruit_TFLite/blob/master/examples/magic_wand_arcada/arduino_accelerometer_handler.cpp

While the LED/Display output is done in the **output\_handler.cpp**

https://github.com/adafruit/Adafruit_TFLite/blob/master/examples/magic_wand_arcada/arduino_output_handler.cpp

#  TensorFlow Lite for EdgeBadge Quickstart

## Micro Speech Demo

https://youtu.be/vzKFznrlPKM

The EdgeBadge has a built-in microphone which you can use to detect audio and speech. If you have&nbsp; PyBadge or some other microcontroller board, [you can assemble and attach an external microphone which will give you audio input](https://learn.adafruit.com/tensorflow-lite-for-edgebadge-kit-quickstart/assembly). The mic outputs monophonic digital sound waves, and we can use that to train and infer gestures using TensorFlow!

If you want to load demo this immediately to your EdgeBadge or PyBadge, here is a UF2 file, which you can 'drag-n-drop' onto your BADGEBOOT diskdrive to load the example ([follow the instructions here on how to load UF2 files if you've never done it before](https://learn.adafruit.com/tensorflow-lite-for-microcontrollers-kit-quickstart/tron-demo#enter-bootloader-mode-6-2))

[Edgebadge_InternalMic.UF2](https://cdn-learn.adafruit.com/assets/assets/000/084/359/original/Edgebadge_InternalMic.UF2?1573847640)
 **OR**

[Badge_ExternalMic.UF2](https://cdn-learn.adafruit.com/assets/assets/000/084/366/original/Badge_ExternalMic.UF2?1573853842)
# Micro speech demo compile & upload

**Don't forget you have to perform all the steps in the previous page for installing Arduino IDE, Adafruit SAMD support, libraries, and board/port selection!**

We adapted the default speech demo to use various kinds of audio input, so you _cannot_ use the example in the Arduino TensorFlowLite library Instead, use the one in `Adafruit TensorFlow Lite` called `micro_speech_arcada`

![](https://cdn-learn.adafruit.com/assets/assets/000/084/360/medium800/adafruit_products_image.png?1573850404)

 **Before you compile & upload this example...**

Visit the `arduino_audio_provider.cpp` tab and look at the top area for this section

```python
//#define USE_EXTERNAL_MIC A8  // D2 on pybadge
#define USE_EDGEBADGE_PDMMIC
//#define AUDIO_OUT A0         // uncomment to 'echo' audio to A0 for debugging
#define DEFAULT_BUFFER_SIZE 512
```

If you're using a PyBadge with external microphone, and its connected to D2, uncomment

`//#define USE_EXTERNAL_MIC A8 // D2 on pybadge`

and comment out

`#define USE_EDGEBADGE_PDMMIC`

before compiling!

OK _now_ you can compile and upload.

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/084/362/medium800/adafruit_products_image.png?1573851219)

![](https://cdn-learn.adafruit.com/assets/assets/000/084/361/medium800/adafruit_products_image.png?1573851004)

You can upload this sketch to your board. After upload it will show up on your computer as a disk drive called CIRCUITPY (unless you changed it)

![](https://cdn-learn.adafruit.com/assets/assets/000/084/363/medium800/adafruit_products_image.png?1573851247)

Click this button to download the detection/info images and audio clips

[Badge MicroSpeech files](https://github.com/adafruit/Adafruit_TFLite/tree/master/examples/micro_speech_arcada/badge_files)
Navigate through the zip file to `examples\micro_speech_arcada\badge_files` then drag the files directly onto the **CIRCUITPY** drive like so:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/364/medium800/adafruit_products_image.png?1573851473)

Click **reset** on the Badge to restart, and you should get the graphics displaying so that you can run the demo untethered!

![](https://cdn-learn.adafruit.com/assets/assets/000/084/365/medium800thumb/adafruit_products_final_5dcf123ac7c5c500138e6340_925809.jpg?1573851772)

Setup and configuration of the microphone and screen is done in the **audio\_provider**

https://github.com/adafruit/Adafruit_TFLite/blob/master/examples/micro_speech_arcada/arduino_audio_provider.cpp

While the LED/Display/audio output is done in the **command\_responder.cpp**

https://github.com/adafruit/Adafruit_TFLite/blob/master/examples/micro_speech_arcada/arduino_command_responder.cpp

#  TensorFlow Lite for EdgeBadge Quickstart

## Ext. Mic Assembly

Warning: 

# Step 1 - Solder Headers onto Microphone

You'll need to plug into your microphone, [so visit this guide for step by step instructions on soldering the headers on](https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/assembly-and-wiring)

![](https://cdn-learn.adafruit.com/assets/assets/000/078/480/medium800/adafruit_products_sensors_2013_01_12_IMG_1160-1024.jpg?1563852759)

# Step 2 - Connect JST PH Cable to Microphone

Connect **Red** to **VCC** , **Black** to **GND** and **White** to **OUT**

![](https://cdn-learn.adafruit.com/assets/assets/000/078/481/medium800/adafruit_products_IMG_2128.jpg?1563852990)

# Step 3 - Cut and solder the 3V selection jumper on the back of the PyBadge or PyGamer
On the back of your board, find the STEMMA cable voltage selection jumper. Cut the trace from **Vcc** to **5V**

![adafruit_products_IMG_2129.jpg](https://cdn-learn.adafruit.com/assets/assets/000/078/483/medium640/adafruit_products_IMG_2129.jpg?1563854550)

Then solder in the **Vcc** to **3V** pads

![adafruit_products_IMG_2130.jpg](https://cdn-learn.adafruit.com/assets/assets/000/078/484/medium640/adafruit_products_IMG_2130.jpg?1563854586)

# Step 4 - Plug in Microphone into D2
![](https://cdn-learn.adafruit.com/assets/assets/000/078/488/medium800/adafruit_products_IMG_2131.jpg?1563854641)

#  TensorFlow Lite for EdgeBadge Quickstart

## More PyBadge Projects

#  TensorFlow Lite for EdgeBadge Quickstart

## Troubleshooting

## error: macro "max" requires 2 arguments, but only 1 given = (\_M\_b.max() - \_M\_b.min() \< std::numeric\_limits\<\_Eresult\_type\>::max()

If you're getting complaints about **min()** and **max()** having wrong number of arguments, make sure you've updated to the latest **Adafruit SAMD Boards** package in the boards manager. Also make sure you have the latest libraries while you're at it

## "uses VFP register arguments and libtensorflowlite.a does not" error

If you get mysterious compilation errors about VFP registers or SerialUSB missing, check you have not installed the _pre-compiled_ version of the TensorFlow library

```python
ld.exe: error: C:\Users\ladyada\AppData\Local\Temp\arduino_build_570572/magic_wand_arcada.ino.elf uses VFP register arguments, C:\Users\ladyada\Dropbox\ArduinoSketches\libraries\Arduino_TensorFlowLite\src\cortex-m4\libtensorflowlite.a(error_reporter.cpp.o) does not
ld.exe: failed to merge target specific data of file C:\Users\ladyada\Dropbox\ArduinoSketches\libraries\Arduino_TensorFlowLite\src\cortex-m4\libtensorflowlite.a(error_reporter.cpp.o)
ld.exe: error: C:\Users\ladyada\AppData\Local\Temp\arduino_build_570572/magic_wand_arcada.ino.elf uses VFP register arguments, C:\Users\ladyada\Dropbox\ArduinoSketches\libraries\Arduino_TensorFlowLite\src\cortex-m4\libtensorflowlite.a(micro_error_reporter.cpp.o) does not       
ld.exe: failed to merge target specific data of file C:\Users\ladyada\Dropbox\ArduinoSketches\libraries\Arduino_TensorFlowLite\src\cortex-m4\libtensorflowlite.a(micro_error_reporter.cpp.o)
```

In the library manager, select the latest **not precompiled** version!

![](https://cdn-learn.adafruit.com/assets/assets/000/084/358/medium800/adafruit_products_image.png?1573847443)


## Primary Products

### TensorFlow Lite for Microcontrollers Kit

[TensorFlow Lite for Microcontrollers Kit](https://www.adafruit.com/product/4317)
Machine learning has come to the 'edge' - small microcontrollers that can run a very miniature version of TensorFlow Lite to do ML computations.&nbsp;

But you don't need super complex hardware to start developing your own TensorFlow models! We've curated a simple kit to...

In Stock
[Buy Now](https://www.adafruit.com/product/4317)
[Related Guides to the Product](https://learn.adafruit.com/products/4317/guides)

## Featured Products

### Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino

[Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino](https://www.adafruit.com/product/4200)
What's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino? That's right, its the **Adafruit PyBadge!** We wanted to see how much we could cram into a ​3 3⁄8 × ​2 1⁄8 inch rounded rectangle, to make an all-in-one dev board with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4200)
[Related Guides to the Product](https://learn.adafruit.com/products/4200/guides)
### STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm

[STEMMA JST PH 2mm 3-Pin to Female Socket Cable - 200mm](https://www.adafruit.com/product/3894)
This cable will let you turn a JST PH 3-pin cable port into 3 individual wires with high-quality 0.1" female header sockets on the end. We're carrying these to match up with our Hallowing, for extending and connecting sensors or LEDs - and the wires are even color coded!

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3894)
[Related Guides to the Product](https://learn.adafruit.com/products/3894/guides)
### Electret Microphone Amplifier - MAX4466 with Adjustable Gain

[Electret Microphone Amplifier - MAX4466 with Adjustable Gain](https://www.adafruit.com/product/1063)
Add an ear to your project with this well-designed electret microphone amplifier. This fully assembled and tested board comes with a 20-20KHz electret microphone soldered on. For the amplification, we use the Maxim MAX4466, an op-amp specifically designed for this delicate task! The amplifier...

In Stock
[Buy Now](https://www.adafruit.com/product/1063)
[Related Guides to the Product](https://learn.adafruit.com/products/1063/guides)

## Related Guides

- [Adafruit PyBadge and PyBadge LC](https://learn.adafruit.com/adafruit-pybadge.md)
- [Gemma-Powered NeoPixel LED Sound Reactive Drums](https://learn.adafruit.com/gemma-powered-neopixel-led-sound-reactive-drums.md)
- [Electronic Demon Costume](https://learn.adafruit.com/electronic-demon-costume.md)
- [Tiny Arduino Music Visualizer](https://learn.adafruit.com/piccolo.md)
- [Ursula's Seashell Necklace](https://learn.adafruit.com/ursulas-seashell-necklace.md)
- [3D Printed Wireless MIDI Controller Guitar](https://learn.adafruit.com/ez-key-wireless-midi-controller-guitar.md)
- [FFT: Fun with Fourier Transforms](https://learn.adafruit.com/fft-fun-with-fourier-transforms.md)
- [PyBadge Case with Flip Out Mic](https://learn.adafruit.com/pybadge-case-with-flip-out-mic.md)
- [LED Masquerade Masks](https://learn.adafruit.com/led-masquerade-masks.md)
- [Wave Shield Voice Changer](https://learn.adafruit.com/wave-shield-voice-changer.md)
- [Costume Triggers & Actuators](https://learn.adafruit.com/costume-triggers-and-switches.md)
- [3D Printed Animatronic Robot Head](https://learn.adafruit.com/3d-printed-animatronic-robot-head.md)
- [VU Meter Baseball Hat](https://learn.adafruit.com/vu-meter-baseball-hat.md)
- [3D Printed LED Microphone Flag](https://learn.adafruit.com/3d-printed-led-microphone-flag.md)
- [Trinket Sound-Reactive LED Color Organ](https://learn.adafruit.com/trinket-sound-reactive-led-color-organ.md)
- [Setting up an Open Speech Recording Website](https://learn.adafruit.com/setting-up-an-open-speech-recording-website.md)
