├── ArduinoCoreLocations.md ├── ArduinoFAQ.md ├── BLEOverview.md ├── CppForPythonProgrammers.md ├── DebuggingMCU.md ├── LICENSE.md ├── MCUFlashing.md ├── OpenSpeechRecordingLocal.md ├── PoweringArduino.md ├── README.md ├── SerialProtocols.md └── img ├── BLEStack.png ├── batteryDone.png ├── batteryScrew.png ├── fileFolder.png ├── filePath.png ├── folder.png ├── library.png ├── lightBlueBLE.png └── reset.png /ArduinoCoreLocations.md: -------------------------------------------------------------------------------- 1 | ## Arduino Core Locations 2 | 3 | If you’re interested in digging deeper into a specific core, source files for AVR boards, which are installed by default and fairly well commented, can be found at: 4 | 5 | ``` 6 | // Windows 7 | \Arduino\hardware\arduino\avr\cores\arduino 8 | // macOS 9 | /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino 10 | ``` 11 | 12 | Whereas cores you’ve added via the Boards Manager are defined in: 13 | 14 | ``` 15 | // Windows 16 | \users\\AppData\Local\Arduino15\packages 17 | // macOS 18 | /home//.arduino15/packages 19 | ``` 20 | 21 | These file types are easily opened and edited by [Visual Studio Code](https://code.visualstudio.com/download), [Sublime Text](https://www.sublimetext.com/) or any other code text editor. 22 | -------------------------------------------------------------------------------- /ArduinoFAQ.md: -------------------------------------------------------------------------------- 1 | ## Common Arduino Errors FAQ 2 | 3 | ### I cannot upload code / device not found on listed ports 4 | 5 | 1. First ensure that the following are true: 6 | 7 | a. The microcontroller is plugged into your machine 8 | 9 | b. You are using the provided USB cable or a functional USB cable that isn’t intended solely for power delivery (that is, capable of data exchange) 10 | 11 | c. You haven’t introduced a defective USB hub or adaptor between the microcontroller board and your machine. 12 | 13 | d. You have selected the correct Board and Port. 14 | 15 | e. The protective foam is removed from the board. It is a common mistake to think that the protective foam that comes with the box is not conductive and therefore it can stay attached to the pins as the board is functioning. The foam is slightly conductive and can cause malfunctions and undesired behaviours (unwanted resets, interferences...) when kept attached to the pins. The foam needs to be slightly conductive to protect the board from ESD during shipping, but it needs to be removed before the board gets powered on. 16 | 17 | f. You have installed the correct version of the board files. Go back to the Setting up the Software reading and make sure you installed the correct version from the board manager. Remember, the reading will have the most up to date versions of everything but we may not be able to update the videos overtime. 18 | 19 | 2. If all of the above are satisfied then you may need to manually put your board into **Bootloader mode** in order to upload code. This happens from time to time and is nothing to worry about. To activate Bootloader mode simply double tap the small white RESET button. The orange built-in LED on the board will fade in and out. Do note that on some operating systems, the board may increment to a different serial port. 20 | 21 | Once the LED is fading on and off, try to upload the sketch again. Check if the sketch was uploaded correctly and if the LED is blinking as expected. Note the difference between fading (in bootloader mode listening for new code) and blinking (sketch successfully uploaded) 22 | 23 | ![An image of the Nano 33 BLE Sense Highlighting the Reset Button](img/reset.png) 24 | 25 | Finally, once you successfully upload code, you may need to press the reset button one more time to exit bootloader mode, if it doesn’t do that automatically, and you may need to reselect the Port after you do that. 26 | 27 | So in summary: **double tap reset → upload → single tap reset** and you should be ready to go! 28 | 29 | ### Board at \ not available, upload error 30 | 1. First ensure that the following are true: 31 | 32 | a. The microcontroller is plugged into your machine 33 | 34 | b. You are using the provided USB cable or a functional USB cable that isn’t intended solely for power delivery (that is, capable of data exchange) 35 | 36 | c. You haven’t introduced a defective USB hub or adaptor between the microcontroller board and your machine. 37 | 38 | d. You have selected the correct Board and Port. 39 | 40 | 2. If those are all satisfied then be sure that there aren’t other applications competing for access to your MCU over the same serial port — namely, that the Serial Monitor and Serial Plotter are closed for upload (We’ll explore both of those in more detail in the course). 41 | 42 | ### How do I know what version of \ is installed? 43 | 44 | Use the menu to navigate to: ```Tools → Manage Libraries```. Then type the name of the library in the top search bar and you will see the word ```INSTALLED``` in teal next to the version number of the library installed. For example you might find the below: 45 | 46 | ![A screenshot of the library manager showing version 2.4.0-ALPHA of the TensofrFlow Lite for Microcontrollers Arduion library being installed.](img/library.png) 47 | 48 | ### How do I know what version of the \ are installed? 49 | 50 | Use the menu to navigate to: ```Tools → Board: → Boards Manager```. Then type the name of the board files in the top search bar and you will see the word ```INSTALLED``` in teal next to the version number of the board files. (See the image of the Library Manager above for an example). 51 | 52 | 53 | ### Unable to open a sketch in the Arduino IDE 54 | 55 | The Arduino IDE requires every sketch (.ino file) to be stored in a folder with the same name as the file, e.g. “blink.ino” needs to be stored in a folder called “blink”. When you try to open a sketch that is not already in a folder with the same name, the IDE will attempt to create the appropriate folder and move the sketch before opening, indicated by the following pop-up: 56 | 57 | ![A popup stating: The file "FAQ.ino" needs to be inside a sketch folder named "FAQ". Create this folder, move the file, and continue?](img/fileFolder.png) 58 | 59 | If a folder with the name of your sketch already exists in the current directory, you will get the error messages below (one after the other): 60 | 61 | ![A popup stating: A folder named "FAQ" already exists. Can't open sketch.](img/folder.png) 62 | 63 | ![A popup stating: Failed to open sketch "PATH_TO_SKETCH".](img/filePath.png) 64 | 65 | To fix this, simply move or delete the conflicting directory (in this case, a directory called “FAQ”), then either try opening the sketch again, or manually create a folder with the sketch name and move the sketch into that folder then open the sketch. 66 | 67 | ### I'm running Linux and I can't seem to access the serial port to upload my code. 68 | 69 | We haven't tested all flavors of Linux but the following generally solves any issues faced when running Ubuntu Linux (Versions 16.04, 18.04, and 20.04): 70 | 71 | 1. Add yourself to the ```dialout``` user group to get access to the serial port. To do that run ```sudo usermod -aG dialout ``` and then logout and then log back in. Now your user should have the correct permissions. 72 | 73 | 2. ```chmod``` the serial port as follows: ```sudo chmod a+rw ```. 74 | 75 | 3. If you still cannot access the serial port, you may have the ```modemmanager``` package installed and set to auto-capture all serial devices. This package is used for cellular connections from your laptop. If you are not using your laptop for cellular you can remove the package with ```sudo apt-get purge modemmanager```. 76 | 77 | ### What Arduino software versions do I need to install? 78 | 79 | We have tested the TinyML kit on the following: 80 | + Arduino IDE version 1.8.13 81 | + Arduino mbed-enabled board files version 1.3.1 82 | + TensorFlow Lite for Microcontrollers Arudino library version 2.4.0-ALPHA 83 | + Arduino_LSM9DS1 Arudino library version 1.1.0 84 | + ArduinoBLE version Arduino library 1.1.3 85 | + Havrard_TinyMLx Arudino library version 0.1.0 86 | 87 | ### I'm getting the error ```fatal error: XXXX.h: No such file or directory``` 88 | 89 | This usually means that you do not have a needed library installed. Please go back to the software setup (and/or look at the list one question above) and make sure you have installed all of the libraries needed by the course! 90 | -------------------------------------------------------------------------------- /BLEOverview.md: -------------------------------------------------------------------------------- 1 | ## Bluetooth Low Energy (BLE) 2 | 3 | The [BLE Specification](https://learn.adafruit.com/introduction-to-bluetooth-low-energy/introduction) was created in 2011 to trasmit information as needed, rather than in a continuous stream, saving energy. In the next few paragraphs, we’ll cover some technical concepts and discuss the practical requirements to start using BLE. 4 | 5 | For your system to employ BLE, there are two roles for it to fill: one in which its BLE module handles forming connections with other devices and a second in which it handles communication itself, data transfer, for a connection made. These considerations live within the Generic Access Profile (GAP) and Generic Attribute Profile (GATT) layers of the BLE stack, pictured here, which are application adjacent. Conceptually, the BLE module can take on the role of either a central or peripheral GAP device. Peripherals periodically send out advertisements that state what they are and what services they can offer, where services is a loaded term conveying the type of data they can share, individually referred to as characteristics of a particular service. Meanwhile, central devices can choose to scan for peripherals and initiate a connection when they find a device or service they care to learn more about in forming a connection. 6 | 7 | [![An image of the BLE stack from Nordic Semiconductor.](img/BLEStack.png)](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsds_s132%2FSDS%2Fs1xx%2Fble_protocol_stack%2Fble_protocol_stack.html) 8 | 9 | There are three device states, then: idle (not advertising or scanning), discovery (advertising, scanning, or initiating a connection), and connected, at which point we shift our perspective to GATT roles in a traditional client, server relationship. It’s worth noting that while many GAP peripherals go on to be GATT servers and GAP centrals go on to be GATT clients, this is not necessarily true. Regardless, if you want your embedded device to be able to convey the results of some TFLM model, you can form a new service with a collection of related characteristics dedicated to organizing those variables, each with its own set of permissions (read and write, for example). 10 | 11 | Each new service and characteristic is tagged by a 128-bit universally unique identification number (UUID), which you can generate [here](https://www.guidgenerator.com/online-guid-generator.aspx). If you structure your embedded system as a GAP peripheral, which is common for embedded systems, you can then program whichever central device to scan specifically for your TFLM service UUID. With a connection formed, the client to your embedded server can then read from the characteristics you defined for your model return and form a very brief connection just long enough to retrieve said datum to minimize the energy requirement of RF transmission. Cleverly enough, if a characteristic is defined with a ‘notify’ permission, a client can subscribe to said characteristic and when its server updates the value associated with that characteristic, the client will be, you guessed it, notified. 12 | 13 | While some level of familiarity with the details of the previous paragraph is required to effectively call on the Nano’s BLE module, the [ArduinoBLE](https://www.arduino.cc/en/Reference/ArduinoBLE) library you installed fortunately abstracts away all but the most critical parameters, in offering up five classes which we will use in our Magic Wand example later in this course: 14 | + BLE - for low level module control 15 | + BLEDevice - used to get information about connected / discovered devices 16 | + BLEService - used to handle or inquiry services it provides or sees on other devices 17 | + BLECharacteristic - interact with characteristics, on one side or the other 18 | + BLEDescriptor - used to describe the characteristics that the board offers 19 | 20 | If you can’t wait to get your feet wet exploring BLE, we suggest you deploy a simple LED hello world BLE example. 21 | 1. You can find that example by navigating in the Arduino IDE to: ```Files → Examples → ArduinoBLE → Peripheral → LED```. 22 | 2. Make sure to set the Port and Board from the Tools menu. 23 | 3. Click upload to compile and flash your code to your Arduino. If you are having problems check out our [Arduino FAQ](https://github.com/tinyMLx/appendix/blob/main/ArduinoFAQ.md) appendix. 24 | 4. Once the code is uploaded open the serial monitor to start the BLE on your Arduino. 25 | 5. From there you can manipulate the state of the built-in LED using the LightBlue app from PunchThrough. LightBlue is available on both [iOS](https://apps.apple.com/app/lightblue/id557428110) and [Android](https://play.google.com/store/apps/details?id=com.punchthrough.lightblueexplorer&hl=en_US&gl=US). 26 | 6. Open up the app and give it access to Bluetooth then in the list of BLE devices look for either ```LED``` or ```Arduino``` and click on it. You should then see the serial monitor say ```Connected to central: XX:XX:XX:XX:XX:XX```. 27 | 7. Then click on the option that probably has a very long UUID and the option for ```Properties:Read Write```. Then click on ```Write new value```. You can now send a ```1``` to turn on the LED or a ```0``` to turn it off! 28 | 29 | ![Screenshots of using the LightBlue App as described in the reading above.](img/lightBlueBLE.png) 30 | 31 | You may find [this related tutorial](https://www.arduino.cc/en/Guide/MKRWiFi1010/enabling-ble) helpful, despite its use of another development board and discrete, off-board LED — all of the important considerations are common! 32 | -------------------------------------------------------------------------------- /CppForPythonProgrammers.md: -------------------------------------------------------------------------------- 1 | ## C++ For Python Programmers Extended Appendix 2 | 3 | ### Data Types 4 | 5 | C++ is a statically-typed language. To best allocate memory for variables and other such objects, you must explicitly note the type when declaring a variable. Some example types are int, double (the same as Python’s floating-point value), string, and other user-defined or library structures. 6 | 7 | **Example:** 8 | ``` 9 | int i = 24; // explicitly typed at declaration 10 | i = i + 1; // no need to use type again 11 | ``` 12 | 13 | You can review data types of the Arduino environment, [here](https://www.arduino.cc/reference/en/) (under “Variables” header). 14 | 15 | + Feel free to click on type descriptions for more granular information 16 | 17 | + Note that in C++ there is a special type void that is used when there is not a type needed by the program but C++ syntax would require a type (e.g., a function that does not return anything as shown below) 18 | 19 | ### Scope, Parentheses, and Semicolons 20 | 21 | To better manage memory and create efficient code, C++ relies on well-defined scope and programmer adherence to syntax-specific subtleties like semicolons to end lines. 22 | 23 | #### Scope via Braces 24 | 25 | Similar to indentation in Python, braces ```{}``` in C++ define scope. In C++, curly braces are used for *function definitions, conditional statements, loops, etc.* The boundaries established by ```{}``` then contain scope *blocks*, which can be nested. 26 | 27 | **Example:** 28 | ``` 29 | // function definition: 30 | void myFunction (int a, bool b) { 31 | // conditional statement: 32 | if (b) { 33 | printf(“Variable a holds the value %d.\n”, a); 34 | } else { 35 | int counter = 10; /* FYI: this local variable is no longer 36 | accessible when we leave the scope 37 | of the else statement */ 38 | while (counter != 0) { 39 | ++a; // an equivalent to a = a + 1 from Python 40 | --counter; // same as counter = counter - 1 41 | } 42 | 43 | } 44 | } 45 | ``` 46 | From the example above, you’ll notice the use of curly braces throughout the code to define the scope of the function as a whole, each conditional statement, and the while loop. **Local** variables, like counter, are declared within these braces and are only accessible within the associated scope or block, defined by its surrounding braces. Notably, **global** variables are declared outside of any function and are accessible within a global, or all-encompassing, scope for a particular program (file). Generally speaking, be careful with global variables as they open the door to mixed, inadvertent usage of common variable names. For completeness, we’ll note that the keyword extern is sometimes used to create a linkage between global variables of the same name within related .cpp files. **Finally, note that while C++ ignores most whitespace, for style and readability, we indent much like Python.** 47 | 48 | #### Parentheses 49 | 50 | You’ll notice, too, that the boolean expressions for each conditional statement (e.g., ```if (b)``` in the code above) and the while loop condition (e.g., ```while (counter != 0)``` in the code above) were enclosed in parentheses. This is required and especially important for complex boolean expressions. 51 | 52 | **Example:** 53 | ``` 54 | int a, b, c; 55 | 56 | ... /* other code altering values of a, b, and c */ ... 57 | 58 | if ((a > 0) && ((b == 2 && c != 2) || a == 24)) { 59 | ... 60 | // outer parentheses required 61 | // inner parentheses create order of operations: 62 | // a must be positive and either b is 2 and c is not 2 or 63 | // a is 24 in which case we can ignore the values of b, c 64 | } 65 | ``` 66 | 67 | Similar to Python, function signatures (especially for functions with arguments) use parentheses, too. 68 | 69 | #### Semicolons 70 | 71 | As seen in the code examples above, most lines need to be terminated with a semicolon. This is what makes C++ whitespace neutral. Since there are many kinds of statements and structures that do require termination, it is easier to define instances that do **not** require a semicolon. Namely, **no** semicolon is needed after: 72 | 73 | 74 | + Macros, library inclusion, and other preprocessor directives (#) 75 | 76 | + Code blocks, on either side of the bounding braces because the brace itself acts as punctuation, except for after data structures that forgo object declaration in the structure definition. This includes: function definitions, selection statements (if, switch, etc.), and iteration (while, for, etc.) statements 77 | 78 | **Example:** 79 | ``` 80 | #include // no semicolon here! 81 | 82 | struct thing { 83 | int value; 84 | double weight; 85 | }; // semicolon for struct definition 86 | 87 | thing item_one; 88 | 89 | int x = 15; 90 | bool is_x_initialized = true; 91 | 92 | void doTheThing(int a, bool print_enable) { // no semicolon here! 93 | if (print_enable) { // no semicolon here! 94 | printf(“The value is %d.\n”, x); 95 | } // no semicolon here! 96 | } // no semicolon here for function definition! 97 | 98 | doTheThing(x, is_x_initialized); 99 | ``` 100 | 101 | 102 | ### Functions 103 | 104 | Function declarations in Python and C++ are similar; however, because C++ is statically-typed, function arguments (parameters) and return values must include a type at the time of definition. If the function doesn’t return anything, it has a return type ```void```. 105 | 106 | The general form is a follows: 107 | 108 | ``` 109 | return_type function_name(type arg1, type arg2, ...) { 110 | // do something 111 | return object_of_return_type; 112 | } 113 | ``` 114 | 115 | **Example:** 116 | ``` 117 | // function definition: 118 | int doSomething(int a, bool print_enable) { 119 | if (print_enable) { // no semicolon here! 120 | printf(“The value is %d.\n”, x); 121 | } else { 122 | return a*a; // of type int 123 | } 124 | } 125 | 126 | int b = doSomething(2, true); // no types needed when calling function 127 | ``` 128 | 129 | ### Libraries, Header Files, #include 130 | Similar to Python’s ```import``` statement, C++ uses the ```#include``` preprocessor directive to notify the compiler (the preprocessor, actually) to put in place the variables, function declarations (prototypes, not the actual definitions), etc. where the directive was included in your source code for use throughout your given C++ file. 131 | 132 | Machine code of libraries will be linked in the *linking* phase of your build process. 133 | 134 | ``` 135 | #include // Include the contents of the standard header 136 | // (looking through system files for ‘vector.h') 137 | ``` 138 | 139 | ``` 140 | #include "user_defined.h" // Include the contents of the file 141 | // 'user_defined.h' 142 | // (looking through the current directory) 143 | ``` 144 | 145 | ### Syntax 146 | It is worth noting many small syntax changes from Python to C++. 147 | 148 | #### Boolean Expressions 149 | Logical AND is represented by two ampersands in C++: ```&&``` 150 | Logical OR by two “pipes”: ```||``` 151 | Not or negation by an exclamation point: ```!``` 152 | Predefined True and False are the same but all lowercase: ```true, false``` 153 | 154 | #### Comments 155 | Begin single-line comments with ```//``` 156 | Multi-line comments begin with ```/*``` and end with ```*/``` 157 | 158 | #### Loops 159 | Unlike Python’s “range,” in C++ a counter is initialized and incremented through each loop iteration, looping until a given condition is no longer met. The general form is as follows: 160 | 161 | ``` 162 | for(counter initialization; conditional expression; increment) { 163 | // do something 164 | } 165 | ``` 166 | 167 | **Example:** 168 | ``` 169 | for(int i = 0; i < 10; ++i) { 170 | printf(“loop iteration %d\n”, i); 171 | // prints 0 1 2 3 4 5 6 7 8 9 172 | } 173 | ``` 174 | 175 | **Example loop through collection:** 176 | ``` 177 | for(int i : vector_of_ints) { 178 | printf(“%d is also in the vector\n”, i); 179 | // prints each integer in vector_of_ints 180 | } 181 | ``` 182 | 183 | #### Exponentiation 184 | While Python uses two asterisks (```**```) for exponentiation, C++ is different in that exponentiation requires a library ```#include ``` and use of a specific function, ```pow()``` to accomplish the same task. Multiplication looks the same in Python and C++, though asterisks (```*```) can be used for pointer declaration and dereferencing, too (interpreted contextually at compilation time), in the lower level language of C++. 185 | 186 | #### Print Statements 187 | C++ has many input/output mechanisms, and print statements vary by library usage. ```std::cout``` from the standard library is used often. In the code above, we used C-style prints via ```printf``` but in Arduino, you’ll likely use ```Serial.print()``` or ```Serial.println()``` to print to the Serial monitor for debugging. We’ll cover this in more detail later! 188 | -------------------------------------------------------------------------------- /DebuggingMCU.md: -------------------------------------------------------------------------------- 1 | ## Debugging Microcontroller Code 2 | 3 | One of the challenges of developing embedded software is that it can be difficult to know how the code you’ve written behaves once it has been deployed. Because the corresponding computation is happening on the microcontroller, rather than on your laptop, say, you won’t necessarily have the same access to live variables or breakpoint-level debug that you may be accustomed to. In this reading, we outline a hierarchy of potential solutions and underline which of these we intend to use during this course. 4 | 5 | ### Isolate Variables 6 | 7 | As pedantic as the following suggestion may be, it is genuinely helpful to remember that when you’re developing a new system, including software, it can be extremely beneficial to monitor the change in output for a singular change in input as a way of tracking the effect a given input has on the output. In the context of developing microcontroller code, this manifests as adding (or removing) one line or block of code at a time to discern how this affects performance in isolation. In so doing, it should become clear whether or not the input under test has bearing over the aspect of behavior that you are evaluating. 8 | 9 | Note: This is a viable method for debug in this course 10 | 11 | ### Indicators by Actuation 12 | 13 | In the Blink example, we saw how easy it is to control simple actuators, like toggling an LED on and off, and even took this a step further in deploying the TFLM ‘hello_world.ino’ that maps an input (x) to an output y = sin(x) that then controls the intensity of light emitted by the same LED, illustrating that variable magnitude can be encoded in actuating behavior of various transducers. While we won’t call on these in this course, the same could be said for piezo buzzers or vibration motors, for example. We can take this concept further still by calling on the RGB LED featured on the Nano 33 BLE Sense to emit not only varied intensity of light, but also color to encode status and will use this as a way to indicate classifier performance. 14 | 15 | Note: This is a viable method for debug in this course 16 | 17 | ### Serial Monitor 18 | 19 | While indications of variable magnitude (binary or analog) can be encoded in actuating behavior, if precision is required, we can leverage the Serial Monitor we explored in the sensors test script to read and write to a data link between your computer and the MCU on the Nano 33 BLE Sense. Beware, however, that Serial.print() can affect program timing. 20 | 21 | Note: This is a viable method for debug in this course 22 | 23 | ### Full-featured Debug 24 | 25 | Finally, we want to mention that some microcontrollers boards, including the Nano 33 BLE Sense, have the capacity for what we’ll call full-featured debugging, although this almost always requires an external interface, many of which are costly. At best, you can gain access to line-by-line breakpoints and track variables and registers as your program slowly steps through the code you have written. 26 | 27 | For the Nano 33 BLE Sense, there are pads on the bottom of the board that give access to the SWD, or Serial Wire Debug, interface of the microcontroller for full-featured debugging. This requires soldering wires to these pads to break them out to an external SWD debug probe. 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International 2 | 3 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 4 | 5 | ### Using Creative Commons Public Licenses 6 | 7 | Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 8 | 9 | * __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). 10 | 11 | * __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). 12 | 13 | ## Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License 14 | 15 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 16 | 17 | ### Section 1 – Definitions. 18 | 19 | a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 20 | 21 | b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 22 | 23 | c. __BY-NC-SA Compatible License__ means a license listed at [creativecommons.org/compatiblelicenses](http://creativecommons.org/compatiblelicenses), approved by Creative Commons as essentially the equivalent of this Public License. 24 | 25 | d. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 26 | 27 | e. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 28 | 29 | f. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 30 | 31 | g. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. 32 | 33 | h. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 34 | 35 | i. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 36 | 37 | j. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. 38 | 39 | k. __NonCommercial__ means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. 40 | 41 | l. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 42 | 43 | m. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 44 | 45 | n. __You__ means the individual or entity exercising the Licensed Rights under this Public License. __Your__ has a corresponding meaning. 46 | 47 | ### Section 2 – Scope. 48 | 49 | a. ___License grant.___ 50 | 51 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 52 | 53 | A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and 54 | 55 | B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only. 56 | 57 | 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 58 | 59 | 3. __Term.__ The term of this Public License is specified in Section 6(a). 60 | 61 | 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 62 | 63 | 5. __Downstream recipients.__ 64 | 65 | A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 66 | 67 | B. __Additional offer from the Licensor – Adapted Material.__ Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. 68 | 69 | C. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 70 | 71 | 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 72 | 73 | b. ___Other rights.___ 74 | 75 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 76 | 77 | 2. Patent and trademark rights are not licensed under this Public License. 78 | 79 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. 80 | 81 | ### Section 3 – License Conditions. 82 | 83 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 84 | 85 | a. ___Attribution.___ 86 | 87 | 1. If You Share the Licensed Material (including in modified form), You must: 88 | 89 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 90 | 91 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 92 | 93 | ii. a copyright notice; 94 | 95 | iii. a notice that refers to this Public License; 96 | 97 | iv. a notice that refers to the disclaimer of warranties; 98 | 99 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 100 | 101 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 102 | 103 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 104 | 105 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 106 | 107 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 108 | 109 | b. ___ShareAlike.___ 110 | 111 | In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 112 | 113 | 1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. 114 | 115 | 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 116 | 117 | 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 118 | 119 | ### Section 4 – Sui Generis Database Rights. 120 | 121 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 122 | 123 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; 124 | 125 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 126 | 127 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 128 | 129 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 130 | 131 | ### Section 5 – Disclaimer of Warranties and Limitation of Liability. 132 | 133 | a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__ 134 | 135 | b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__ 136 | 137 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 138 | 139 | ### Section 6 – Term and Termination. 140 | 141 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 142 | 143 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 144 | 145 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 146 | 147 | 2. upon express reinstatement by the Licensor. 148 | 149 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 150 | 151 | c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 152 | 153 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 154 | 155 | ### Section 7 – Other Terms and Conditions. 156 | 157 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 158 | 159 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 160 | 161 | ### Section 8 – Interpretation. 162 | 163 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 164 | 165 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 166 | 167 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 168 | 169 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 170 | 171 | > Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 172 | > 173 | > Creative Commons may be contacted at creativecommons.org -------------------------------------------------------------------------------- /MCUFlashing.md: -------------------------------------------------------------------------------- 1 | ## "Flashing" Code to a Microcontroller 2 | 3 | You may be interested to learn a bit more about what’s happening in the process of deploying code to a microcontroller. The exact method will vary between MCU, but there are two main constructs that you’ll hear abou: in-system programming and bootloaders. In the case of the Nano 33 BLE Sense, when we upload code over USB, we are relying on a bootloader to accept the incoming program. 4 | 5 | ### In-System Programming (ISP) 6 | 7 | This approach does **not** require that there be anything pre-existing on the MCU to initiate transfer to program memory (which is not only desirable, but necessary for initial controller setup), but requires the use of an external programmer that can be costly and interfaces with the MCU via various standards: 8 | + A few popular standards include: [ICSP](https://en.wikipedia.org/wiki/In-system_programming), [SWD](https://en.wikipedia.org/wiki/JTAG#Similar_interface_standards), [PDI](https://en.wikipedia.org/wiki/AVR_microcontrollers#Programming_interfaces), [JTAG](https://en.wikipedia.org/wiki/JTAG). 9 | + The etymology for ISP relates to the notion of updating device software or firmware for an embedded MCU within its application environment 10 | 11 | ### Bootloaders 12 | 13 | In contrast, bootloaders specifically call on (really, are, rather) existing software that persists in memory and will, on reset, listen for signals that a new program is inbound. 14 | + If there is new code available, the incoming program overwrites the existing code but preserves the bootloader so that this process can be repeated 15 | + If there is not new code available, the existing code (as applicable) begins 16 | + Unlike various forms of ISP, the Arduino bootloader is generally accessible via USB, although technically some boards require USB-to-UART translation 17 | + Notably, a double tap of the small white reset button on top of the Nano 33 BLE Sense will draw the MCU away from any existing program into the bootloader, at times resolving issues where uploads are blocked or otherwise inhibited by the existing program. 18 | -------------------------------------------------------------------------------- /OpenSpeechRecordingLocal.md: -------------------------------------------------------------------------------- 1 | ## Using the Open-Speech-Recording Application Locally to Develop Your Own Dataset 2 | 3 | If you would like to run the open-speech-application locally please follow the instructions below. In order for this to work you need to have [```Python``` installed](https://www.python.org/downloads/) on your local machine as well as the [python package manager ```pip```](https://packaging.python.org/tutorials/installing-packages/). 4 | 5 | We have [forked a version](https://github.com/tinyMLx/open-speech-recording/) of Pete's Open-Speech-Recording application to use only local memory which you can use to record your own datafiles. If you'd like a more robust version that you want to share with others to aid in your data collection (and therefore use a google storage buckets which may cost some money) please see [Pete's original project](https://github.com/petewarden/open-speech-recording). You can setup and use our version of the app as follows. 6 | 7 | 1. Clone the repository and install the only requirement, flask: 8 | ``` 9 | git clone https://github.com/tinyMLx/open-speech-recording.git 10 | pip install flask 11 | ``` 12 | 13 | 2. You can then run the server locally (from within the open-speech-recording folder) by running: 14 | ``` 15 | cd open-speech-recording 16 | export FLASK_APP=main.py 17 | python -m flask run 18 | ``` 19 | 20 | 3. Then open the link provided in the terminal in a web browser to run the application. Make sure to **run the application in a private or incognito window** which avoids any cacheing issues. Also we've found that the app works best when **using Chrome** so if you are having issues with another browser please try it in Chrome. 21 | 22 | 4. The application can then be run as specified in the [edX course instructions](https://github.com/tinyMLx/courseware/raw/master/edX/readings/4-6-6.pdf). Once you are done recording, click to download the audio files. You will find that instead of downloading the files individually or via a zip, you now have a large collection of ```.ogg``` files in your open-speech-recording directory. 23 | 24 | 5. You can now safely close the flask app from the command line by running ```cntrl+c``` (or ```cmd+c```) and can now proceed to formatting your audio files and then training your model in Colab. 25 | -------------------------------------------------------------------------------- /PoweringArduino.md: -------------------------------------------------------------------------------- 1 | ## Powering Your TinyML System 2 | 3 | Now that you have your Arduino development board up and running, let's talk about how you could deploy it independent of your computer! While some embedded systems call on AC-DC converters (or “wall warts,” colloquially) to provide low voltage power to their electronics (the Google home speaker, for example), others are battery powered. Both of these paradigms are applicable to real-world deployment of tinyML and both are achievable using your TinyML kit. 4 | 5 | ### USB Power Delivery 6 | 7 | To this point, we have provided power over USB to our microcontroller via the microB port on the Nano 33 BLE Sense. The 5V that USB carries is then down regulated on the development board to 3.3V, the logical reference for the MCU. While there’s nothing wrong with this in development, a prototype of your application ought not depend on drawing power from your computer. Instead, you could call on an AC-DC converter with USB output. This has the added benefit of likely raising the current capacity of the 5V power rail, from at most 500 mA via a computer to whatever the specification happens to be for a given wall-bound converter. This could be meaningful for driving certain power hungry actuators, like speakers. 8 | 9 | ### Battery 10 | 11 | While the above solution removes the need for the computer, you’re still tethered to a wall. To go fully mobile you’ll want to call on a battery. So what are our options? The idea of using a voltage regulator (specifically, the [MPM3610](https://www.monolithicpower.com/en/documentview/productdocument/index/version/2/document_type/Datasheet/lang/en/sku/MPM3610GQV/document_id/2090)) to cut down an input voltage to a nice, stable 3.3V level applies here as well. If you were to take a closer look at the linked datasheet, you’d find that the MPM3610 accepts input voltages from 4.5V to 21V. The 5V delivered over USB is within this range, and any compatible battery will need to be as well. This unfortunately eliminates the possibility of calling on single cell 3.7V lithium batteries, but makes the selection of a [9V alkaline battery](https://commons.wikimedia.org/wiki/File:Duracell_9_Volt_0849.jpg) fairly obvious. 12 | 13 | You might be wondering how any battery might connect to the boards in front of you, but never fear, we’ve got you covered. At one corner of the Tiny Machine Learning Shield you’ll find a green terminal block with silkscreen labels that read, “VIN” and “GND,” where GND is our reference voltage and as such should be connected to the negative terminal of any compatible battery. This green terminal block is where you’d want to screw in wires carrying 4.5V to 21V, and we’ll add that 9V clip, [like this](https://www.digikey.com/en/products/detail/mpd-memory-protection-devices/BS6I/32055), that terminates in pre-stripped hook-up wire makes this quite easy! 14 | 15 | #### Assembly Steps 16 | 1. Screw down a wire leading from the negative battery terminal (black) to GND (Most < 3mm flat-head screwdrivers will suffice here). 17 | 2. Repeat this process for the positive battery terminal (red) to VIN. And that's it you're all set to power your Arduino from a battery! 18 | 19 | #### Important Notes 20 | 1. While there is clever circuitry on board to handle such an exception, it is generally good practice to avoid having competing power sources, so we’d recommend that you unplug the Nano 33 BLE Sense from USB power before connecting a battery 21 | 22 | 2. With about 550 mAh capacity, a 9V battery can source 15 mA for about 37 hours before you will need to get a new one. 23 | 24 | ![An image of screwing down the black negative terminal to attach a wire.](img/batteryScrew.png) 25 | 26 | ![An image of the attached battery powering the device.](img/batteryDone.png) 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repository holds the Appendix Documents for the [EdX TinyML Specialization](https://www.edx.org/professional-certificate/harvardx-tiny-machine-learning) 2 | 3 | ## Table of Contents: 4 | 5 | * [ArduinoCoreLocations.md](https://github.com/tinyMLx/appendix/blob/main/ArduinoCoreLocations.md) 6 | 7 | * File locations of the board files 8 | 9 | * [ArduinoFAQ.md](https://github.com/tinyMLx/appendix/blob/main/ArduinoFAQ.md) 10 | 11 | * A compiled list of common Arduino erros and solutions 12 | 13 | * [BLEOverview.md](https://github.com/tinyMLx/appendix/blob/main/BLEOverview.md) 14 | 15 | * A high level overview of the Bluetooth low energy specification 16 | 17 | * [CppForPythonProgrammers.md](https://github.com/tinyMLx/appendix/blob/main/CppForPythonProgrammers.md) 18 | 19 | * A basic introduction to the C++ language for programmers familiar with Python. It covers data types, scope, semicolons, functions, header files, and syntax. 20 | 21 | * [DebuggingMCU.md](https://github.com/tinyMLx/appendix/blob/main/DebuggingMCU.md) 22 | 23 | * A brief tutorial on how to debug microcontroller code. 24 | 25 | * [MCUFlashing.md](https://github.com/tinyMLx/appendix/blob/main/MCUFlashing.md) 26 | 27 | * A guide to deploying code to a microcontroller. It outlines the difference between in-system programming and bootloaders. 28 | 29 | * [OpenSpeechRecordingLocal.md](https://github.com/tinyMLx/appendix/blob/main/OpenSpeechRecordingLocal.md) 30 | 31 | * A guide for running the open-speech-recording application locally as compared to naviagting to [https://tinyMLx.org/open_speech_recording](https://tinyMLx.org/open_speech_recording) 32 | 33 | * [PoweringArduino.md](https://github.com/tinyMLx/appendix/blob/main/PoweringArduino.md) 34 | 35 | * A guide on how to power your TinyML Arduino development board, including sections on powering via USB and via Battery. 36 | 37 | * [SerialProtocols.md](https://github.com/tinyMLx/appendix/blob/main/SerialProtocols.md) 38 | 39 | * An introduction to serial communication protocols. It covers UART, I2C, SPI, and their application in embedded systems. 40 | 41 | * [Teachable Machine](https://github.com/googlecreativelab/teachablemachine-community/blob/master/snippets/markdown/tiny_image/GettingStarted.md) 42 | 43 | * We are excited to announce that Google's Teachable Machine now supports deployment to the Arduino Nano 33 BLE! If you'd like to learn more about it follow this link to their getting started guide! 44 | 45 | 46 | 47 | ## License 48 | 49 | Copyright (c) 2021 TinyMLx. All rights reserved. 50 | 51 | [![License: CC BY-NC-SA 4.0](https://licensebuttons.net/l/by-nc-sa/4.0/80x15.png)](https://creativecommons.org/licenses/by-nc-sa/4.0/) 52 | -------------------------------------------------------------------------------- /SerialProtocols.md: -------------------------------------------------------------------------------- 1 | ## Serial Communication Protocols 2 | 3 | Serial communication protocols designed for transmitting longer data messages with different applications in mind (e.g., one to one vs. one to many communication). In this short appendix document we will highlight 3 of them: [universal asynchronous receive transmit (UART)](https://learn.sparkfun.com/tutorials/serial-communication/all), [inter-integrated circuit (I2C)](https://learn.sparkfun.com/tutorials/i2c), and [serial peripheral interface (SPI)](https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi). 4 | 5 | ### UART 6 | While UART is remarkably simple to wire up and permits simultaneous bidirectional data transfer, there is no explicit understanding of transfer rates that is shared between each, hence the term “asynchronous” being a part of its name. Instead, both sides of a UART channel must have an agreed upon rate of data transfer in bits per second, referred to as the baud rate. Modules that communicate via UART will often have a pre-defined baud rate, that you as a designer must program your microcontroller to match in order to communicate. One of the most crucial drawbacks of UART is that it is a strictly point-to-point communication protocol, meaning it is designed for one device to communicate with only one other device. 7 | 8 | ### I2C 9 | For systems where you would like your MCU to communicate with multiple modules, without needing to wire up separate links for each module, the I2C and SPI protocols allow the creation of a serial bus. On a serial bus, many son, or peripheral, devices can communicate with a single mother, or controller, using the same data lines. I2C, like UART, only uses two wires: SDA, serial data, and SCL, serial clock. The SCL line allows the mother to explicitly set the data transfer rate, contrasted with UART, where both devices need to know the bit-rate beforehand. This simple wiring does come at the cost of data transfer being half duplex, meaning in one direction at a time. In addition, when initiating a data transfer on an I2C bus, the mother device must specify which device it is sending data to or requesting data from by first indicating the address of the intended son device. 10 | 11 | ### SPI 12 | The SPI protocol, on the other hand, simplifies the issue of addressing by breaking out a separate, son-select (SS) line for every son device (you may also see CS for chip-select). The mother then indicates which son device it is communicating with by pulling the son-select line for that son low. This advantage of simpler, faster addressing comes with the disadvantage of each additional son device requiring another wire, whereas an I2C bus is always only two wires. An SPI bus, on the other hand, requires a serial clock line, like I2C, in addition to two data lines for simultaneous bidirectional, or full duplex, data transfer, plus one son-select line for every son on the bus. Thus, SPI is significantly more complex to wire than both UART and I2C, but achieves the fastest data transfer of the three due to simple addressing and fast clock rates (typically in the range of a few MHz). 13 | 14 | ### Usage in Embedded Systems 15 | In a real embedded system, sensors and other peripherals that communicate via a serial protocol may be on the same board as the microcontroller, in which case the physical manifestation of the various data, clock, and select lines discussed above will be traces on a PCB. One example of this on the Nano 33 BLE Sense is the connection to the built-in IMU, the LSM9DS1, which the NRF52840 communicates with via an I2C bus. Some applications may require that sensors be off-board, in which case connection can be achieved via a cable assembly. The latter can also be useful in development as well, as there are several lines of sensor and actuator development boards that use standardized connectors to allow for plug-and-play, rapid prototyping. One such line that is particularly relevant for this course is the Grove system from SeeedStudio, as the Tiny Machine Learning Shield in your kit has 6 built-in Grove connectors. The 3 connectors on the right form an I2C bus that you can connect multiple sensors or actuators too. 16 | 17 | Note: the Grove connectors on the shield supply 3.3V to the modules that you connect to them, while some Grove modules may require 5V to work properly. Before purchasing a module for use with the shield, make sure that it is designed to accept either 3.3V or 5V. 18 | -------------------------------------------------------------------------------- /img/BLEStack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/BLEStack.png -------------------------------------------------------------------------------- /img/batteryDone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/batteryDone.png -------------------------------------------------------------------------------- /img/batteryScrew.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/batteryScrew.png -------------------------------------------------------------------------------- /img/fileFolder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/fileFolder.png -------------------------------------------------------------------------------- /img/filePath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/filePath.png -------------------------------------------------------------------------------- /img/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/folder.png -------------------------------------------------------------------------------- /img/library.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/library.png -------------------------------------------------------------------------------- /img/lightBlueBLE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/lightBlueBLE.png -------------------------------------------------------------------------------- /img/reset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyMLx/appendix/c0ef42f0ee45d30502f0c558781f722557d8cb9f/img/reset.png --------------------------------------------------------------------------------