Introduction

Microcontrollers are pervasive in a myriad of applications and are typically work behind the scenes. However, with the emergence of the maker movement and a growing interest in microcontrollers, their usage is becoming more widespread.

On the one hand a microcontroller is a hardware device that interacts with other electronic devices such as temperature sensors, encoders, and motors. On the other hand it is also a tiny computer that can be programmed.

To begin programming microcontrollers, we first need to understand the basic tasks that are performed by a microcontroller. Typically a microcontroller gets inputs from sensors, computes something using these inputs, and outputs the results of these computations to the output devices.

The programming of the microcontroller by the Wolfram Language happens in two stages. First, the source code is generated. Then, it is cross-compiled and downloaded to the microcontroller.

If the compiler toolchain is set up correctly, it need not be explicitly specified. So apart from the compiler, there are broadly four things that need to be specified to get a program up and running on the microcontroller.

• The computations that the microcontroller needs to implement

• The microcontroller and the pins that need to be configured for the input and output signals

• Any additional specifications of the input or output devices that interact with the microcontroller

• The programming mechanism to upload and embed the program to the microcontroller

The superfunction that generates and embeds the code to the microcontroller is (PackageLink[MicrocontrollerEmbedCode, paclet:MicrocontrollerKit/ref/MicrocontrollerEmbedCode, MicrocontrollerKit Package Symbol]).

The computations that the microcontroller needs to carry out are specified as discrete-time input-output models. These include (RefLink[TransferFunctionModel, paclet:ref/TransferFunctionModel]), (RefLink[StateSpaceModel, paclet:ref/StateSpaceModel]), (RefLink[AffineStateSpaceModel, paclet:ref/AffineStateSpaceModel]), (RefLink[NonlinearStateSpaceModel, paclet:ref/NonlinearStateSpaceModel]), and (RefLink[SystemsConnectionsModel, paclet:ref/SystemsConnectionsModel]).

On startup the microcontroller starts at an initial state (Subscript[x, 0]). Based on the specified computation, at each sampling instant k microcontroller reads any inputs signals (Subscript[u, k]) and computes the outputs (Subscript[y, k]) and also updates its internal state from (Subscript[x, k]) to (Subscript[x, k+1]). The sampling instants are spaced at time intervals of τ, where τ is the sampling period of the discrete-time model sys.

The microcontroller specifications μc can be the following:

Microcontroller specifications.

The programming mechanism is typically specified as an (RefLink[Association, paclet:ref/Association]). If specified as a string "p" it is interpreted as \[LeftAssociation]"ConnectionPort"->"p"\[RightAssociation].

In subsequent tutorials we will elaborate upon the input and output channels, microcontroller options, programming mechanisms, and options to (PackageLink[MicrocontrollerEmbedCode, paclet:MicrocontrollerKit/ref/MicrocontrollerEmbedCode, MicrocontrollerKit Package Symbol]).

First, we will start with going over the installation of the toolchain that compiles and downloads the code.