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.

1.gif

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 MicrocontrollerEmbedCode.

2.gif

The computations that the microcontroller needs to carry out are specified as discrete-time input-output models. These include TransferFunctionModel, StateSpaceModel, AffineStateSpaceModel, NonlinearStateSpaceModel, and SystemsConnectionsModel.

On startup the microcontroller starts at an initial state x0. Based on the specified computation, at each sampling instant k microcontroller reads any inputs signals uk and computes the outputs yk and also updates its internal state from xk to xk+1. The sampling instants are spaced at time intervals of τ, where τ is the sampling period of the discrete-time model sys.

3.gif

The microcontroller specifications μc can be the following:

<|"Target"name,"Inputs"{},"Outputs"{}|> target name, input and output channel specifications
<|,specivali,|> other microcontroller specifications

Microcontroller specifications.

The programming mechanism is typically specified as an Association. If specified as a string "p" it is interpreted as "ConnectionPort"->"p".

In subsequent tutorials we will elaborate upon the input and output channels, microcontroller options, programming mechanisms, and options to MicrocontrollerEmbedCode.

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