Deploying TinyML: Setting up your Software

385 阅读5分钟

In this reading, we will walk through setting up the software you’ll need for this course, the Arduino integrated development environment (IDE). We will be using the Arduino IDE to program your microcontroller.

Introduction

What is Arduino?

Arduino describes itself as “an open-source electronics platform based on easy-to-use hardware and software.” In large part, this description is fitting, as the company designs and sells a collection of microcontroller development boards that simplify deployment of embedded hardware alongside a software framework that abstracts away all, but the most relevant considerations for your application. Perhaps, what’s under-represented by this description is the role that the surrounding community plays in enabling many plug-and-play experiences given the number and quality of auxiliary hardware modules, support libraries, and tutorials that have and continue to be produced within Arduino’s ecosystem.

One thing we’d like to acknowledge here is that Arduino’s mission of creating easy-to-use hardware and software has the necessary tradeoff of limiting the feature set of its development environment to the essentials.

What is an Integrated Development Environment (IDE)?

As is true for all forms of programming, an integrated development environment, or IDE, is an application with a feature set that facilitates software development generally or within a particular niche. The Arduino Desktop IDE is highly specific in the sense that it is intended to facilitate software development for a specific set of microcontroller boards, in C++.

Within the niche of IDEs for embedded software, there is a noticeable dichotomy between light-weight applications, (like Arduino’s IDE) that minimize functionality and abstract away details in the name of simplicity and full-featured IDEs (like Keil µVision and Visual Studio Code) that exist to support industry professionals. 

If you’re interested in finding a happy medium to use in future embedded projects, our staff have had good experience using VS Code with the hardware specific extension PlatformIO, that together enable nice-to-have features like line completion, reference tracking, etcetera, without all of the complexity that more advanced IDEs introduce. Having said this, this particular combination of VS Code + PlatformIO will not be officially supported within this course.

What is the Arduino IDE?

As you might expect given the description above, the Arduino IDE is a light-weight development environment with features that permit you to very quickly manipulate microcontroller development boards. While there is a cloud-based offering (the Arduino Create Web Editor) as well as a so-called Arduino Pro IDE that is in development (specifically in the alpha stage at the time of writing), we are going to use the standard Arduino Desktop IDE in this course.

Downloading and Installing the Arduino IDE

Note: Our staff will only officially support the the Arduino Desktop IDE v1.8.15 or later (tested up to v1.8.19). If you have an older version of the Desktop IDE, we recommend that you update your software.

  1. Navigate to arduino.cc and at the top of the page select Software and click Downloads.
  2. Click on the download link appropriate for your machine.
  3. There is no obligation to contribute, you can click ‘Just Download’ to proceed.

Operating specific installation instructions vary, so if what follows isn’t self evident, you can find guidance, by OS, at the following links:

A Quick Tour of the IDE

A Screenshot of the Arduino IDE showing the menus and toolbar across the top highlighted in orange, the file tabs below that highlighted in yellow, the large code area in the middle of the screen highlighted in blue, and the console at the bottom highlighted in purple.

When you first open the IDE, you will see a screen that looks something like the above screenshot.

Up at the top of the IDE, you will find the menus and the toolbar, which we will explore as we work through the rest of this document and when we run the tests later in this section. 

Below that, you will find the file tabs. For now, there will only be one file open that is most likely named sketch_, however, later in the course when we work through more complicated examples, you will see all of the various files that make up the project across the file tab area. In “Arduino speak,” a sketch is a simple project/application.

In the middle of the screen, you will see the large code area. Each sketch can consist of many files and use many libraries, but at its core, each sketch is made of two main functions, “setup” and “loop”, which you can see pre-populated in the code area. We’ll explore what those functions are used for through the Blink example in a future video. For now, let's continue orienting ourselves with and setting up the IDE.

Finally, at the bottom of the screen, you’ll find the console. This is where you will see debug and error messages that result from compiling your C++ sketch and uploading it to your Arduino.

Installing the Board Files for the Nano 33 BLE Sense

One of the primary advantages that the Arduino ecosystem affords is the portability of code you write for one or another board within their line-up or even in porting code to affiliate boards. This is made possible by the support files organized in the Boards Manager, which coordinates a download and installation of files that detail the Arduino functions (sometimes ‘core’) that are defined for that particular board (which is how hardware differences between boards are abstracted) as well as compiler or linker details specific to the given board.

To install the board files that you will need for your Arduino Nano 33 BLE Sense, please do the following:

  1. Open the Boards Manager, which you can find via the Tools drop-down menu. Navigate, as follows: Tools → Board → Boards Manager. Note that the Board may be set to “Arduino UNO” by default.

A screenshot of the top left corner of the Arudino IDE showing the top menu of “File, Edit, Sketch, Tools, Help” with “Tools” highlighted. This opens up a large submenu and about 2/3rds of the way down we have highlighted “Board: Arduino Uno” which has opened up another sub menu to the right and we have highlighted “Boards Manager..” and selected that.

  1. In the Boards Manager dialog box, use the search bar at the top right to search for “mbed nano” which should bring up a few results. We’re interested in the first result (as shown), named “Arduino MBED OS Nano Boards,”. Make sure you select Version 2.3.1 or newer (tested up to Version 3.0.1) and then click “Install.” As the install process progresses, you will see a blue completion bar work its way across the bottom of the Board Manager window. Be patient, you may need to install USB drivers, which requires you to approve an administrator privileges popup which can take a couple of minutes to appear. 

A screenshot of the Boards manager showing an input bar across the top where we have typed in “mbed nano” which has next to it a dropdown for “type” that we have left to the default “All”. We see that two results have appeared. The first titled in board “Arduno MBed OS Nano Boards” and the second “[Deprecated - Please install standalone packages] Arduin Mbed OS Boards”. Inside each, there is a description of the package and its creator as well as links for help and more info. By selecting the first package (the non-deprecated one), on the right of that row appears a dropdown for a version (we have selected 2.3.1) as well as an Install button you'll want to click.

After you have successfully installed the board, if you exit and re-open the Board Manager and search again for “mbed nano” you will now see INSTALLED next to the library and the option to “Remove” the library or install a different version.

A screenshot of the Boards manager after installation. Everything is as described in the previous image except now there is additional text under the title which says version 2.3.1 INSTALLED. Where “INSTALLED” is highlighted in teal.

Google has changed the access to TFMicro. It is no longer an Arduino library as shown in the video. Don't worry -- we have bundled it into our library! So the same process works as shown in the video you will just need to search for our library instead. Instructions for that are shown below.

Installing the Libraries Needed for this Course

Another advantage of the Arduino ecosystem is the availability of a wide array of libraries for performing various tasks, such as interfacing with a sensor module or manipulating data using common algorithms. There are many libraries that can be accessed from within the Library Manager in the Arduino IDE as described below. Check here for a complete list.

For this course, we are going to need four libraries. To install the libraries, please do the following and make sure to install the version specified in the reading below or the tinyML applications will not work:

  1. Open the Library Manager, which you can find via the Tools drop-down menu. Navigate, as follows: Tools → Manage Libraries.
    Screenshot of opening the library manager using the menus on the Arduino IDE

  2. Then, much like for the Boards Manager, in the Library Manager dialog box, use the search bar at the top right to search for the following libraries, one at a time. Note that like with the Board manager, a blue completion bar will appear across the bottom of the Library Manager window.

  • The Tensorflow Lite Micro Library:  (This library has been deprecated by Google -- we have bundled a version into our custom library instead)  
    • Search Term: Tensorflow
    • Library Name: Arduino_TensorFlowLite
    • Version: 2.4.0-ALPHA

Screenshot of using the library manager to search for and install the  Arduino_TensorFlowLite library.

  • The Harvard_TinyMLx Library we put together for this course!
    • Search Term: TinyMLx
    • Library Name: Harvard_TinyMLx
    • Version: 1.2.2-Alpha (The new 1.2.x updates include TFMicro 2.4.0)

TinyMLx Library selection in the Library Manager

  • The library that supports the accelerometer, magnetometer, and gyroscope on the Nano 33 BLE sense:
    • Search Term: LSM9DS1
    • Library Name: Arduino_LSM9DS1
    • Version: 1.1.0

Screenshot of using the library manager to search for and install the Arduino_LSM9DS1 library.

  • ArduinoBLE:
    • Search Term: ArduinoBLE
    • Library Name: ArduinoBLE
    • Version: 1.2.1 or newer (tested up to 1.2.2)

ArduinoBLE Library selection in the Library Manager

Setting your Preferences

You can adjust the preferences set for the Arduino Desktop IDE via the File drop-down menu, File → Preferences. There are a few preferences that we recommend enabling to make the Arduino IDE a little easier to use, namely:

  1. Show verbose output during: compilation and upload.
  2. Enable code folding.
  3. Display line numbers.

On final note, if you don’t like the default theme for the Arduino Desktop IDE, there is a nice tutorial for a dark theme you can find here. Also, if you would like to learn more about the IDE, check out Arduino's documentation.

And that’s it! Your Arduino IDE should be all configured for this course. Now that you have all of the necessary board files and libraries installed, it’s time to explore more of the features of the IDE available under the “Tools” menu and start to test out your Arduino by deploying the Blink example!